diff options
author | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-07 21:31:39 +0000 |
---|---|---|
committer | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-07 21:31:39 +0000 |
commit | 8ff1d42631e79e842669dc3051d91ed7db80f1dc (patch) | |
tree | 55c1987549e982bfbf60a33fad3b60b5113d7864 /printing/page_setup_unittest.cc | |
parent | 395f9295b3e370746846dbe6073a0d43ab7e4af5 (diff) | |
download | chromium_src-8ff1d42631e79e842669dc3051d91ed7db80f1dc.zip chromium_src-8ff1d42631e79e842669dc3051d91ed7db80f1dc.tar.gz chromium_src-8ff1d42631e79e842669dc3051d91ed7db80f1dc.tar.bz2 |
Move printing related stuff to the root printing project from the browser project. This simplifies further refactoring and eases understanding of the printing part of Chrome.
Also renamed win_printing_context to printing_context_win (correct naming convention) and added stub implementations for _linux and mac.
Now all but one file is compiling on all platforms.
TEST=none (no functional change).
BUG=none
Review URL: http://codereview.chromium.org/149212
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/page_setup_unittest.cc')
-rw-r--r-- | printing/page_setup_unittest.cc | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/printing/page_setup_unittest.cc b/printing/page_setup_unittest.cc new file mode 100644 index 0000000..e2c68b9 --- /dev/null +++ b/printing/page_setup_unittest.cc @@ -0,0 +1,146 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "printing/page_setup.h" + +#include <stdlib.h> +#include <time.h> + +#include "testing/gtest/include/gtest/gtest.h" + +TEST(PageSetupTest, Random) { + time_t seed = time(NULL); + int kMax = 10; + srand(static_cast<unsigned>(seed)); + + // Margins. + printing::PageMargins margins; + margins.header = rand() % kMax; + margins.footer = rand() % kMax; + margins.left = rand() % kMax; + margins.top = rand() % kMax; + margins.right = rand() % kMax; + margins.bottom = rand() % kMax; + int kTextHeight = rand() % kMax; + + // Page description. + gfx::Size page_size(100 + rand() % kMax, 200 + rand() % kMax); + gfx::Rect printable_area(rand() % kMax, rand() % kMax, 0, 0); + printable_area.set_width(page_size.width() - (rand() % kMax) - + printable_area.x()); + printable_area.set_height(page_size.height() - (rand() % kMax) - + printable_area.y()); + + // Make the calculations. + printing::PageSetup setup; + setup.SetRequestedMargins(margins); + setup.Init(page_size, printable_area, kTextHeight); + + // Calculate the effective margins. + printing::PageMargins effective_margins; + effective_margins.header = std::max(margins.header, printable_area.y()); + effective_margins.left = std::max(margins.left, printable_area.x()); + effective_margins.top = std::max(margins.top, + effective_margins.header + kTextHeight); + effective_margins.footer = std::max(margins.footer, + page_size.height() - + printable_area.bottom()); + effective_margins.right = std::max(margins.right, + page_size.width() - + printable_area.right()); + effective_margins.bottom = std::max(margins.bottom, + effective_margins.footer + kTextHeight); + + // Calculate the overlay area. + gfx::Rect overlay_area(effective_margins.left, effective_margins.header, + page_size.width() - effective_margins.right - + effective_margins.left, + page_size.height() - effective_margins.footer - + effective_margins.header); + + // Calculate the content area. + gfx::Rect content_area(overlay_area.x(), + effective_margins.top, + overlay_area.width(), + page_size.height() - effective_margins.bottom - + effective_margins.top); + + // Test values. + EXPECT_EQ(page_size, setup.physical_size()) << seed << " " << page_size << + " " << printable_area << " " << kTextHeight; + EXPECT_EQ(overlay_area, setup.overlay_area()) << seed << " " << page_size << + " " << printable_area << " " << kTextHeight; + EXPECT_EQ(content_area, setup.content_area()) << seed << " " << page_size << + " " << printable_area << " " << kTextHeight; + + EXPECT_EQ(effective_margins.header, setup.effective_margins().header) << + seed << " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.footer, setup.effective_margins().footer) << + seed << " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.left, setup.effective_margins().left) << seed << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.top, setup.effective_margins().top) << seed << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.right, setup.effective_margins().right) << seed << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.bottom, setup.effective_margins().bottom) << + seed << " " << page_size << " " << printable_area << " " << kTextHeight; +} + +TEST(PageSetupTest, HardCoded) { + // Margins. + printing::PageMargins margins; + margins.header = 2; + margins.footer = 2; + margins.left = 4; + margins.top = 4; + margins.right = 4; + margins.bottom = 4; + int kTextHeight = 3; + + // Page description. + gfx::Size page_size(100, 100); + gfx::Rect printable_area(3, 3, 94, 94); + + // Make the calculations. + printing::PageSetup setup; + setup.SetRequestedMargins(margins); + setup.Init(page_size, printable_area, kTextHeight); + + // Calculate the effective margins. + printing::PageMargins effective_margins; + effective_margins.header = 3; + effective_margins.left = 4; + effective_margins.top = 6; + effective_margins.footer = 3; + effective_margins.right = 4; + effective_margins.bottom = 6; + + // Calculate the overlay area. + gfx::Rect overlay_area(4, 3, 92, 94); + + // Calculate the content area. + gfx::Rect content_area(4, 6, 92, 88); + + // Test values. + EXPECT_EQ(page_size, setup.physical_size()) << " " << page_size << + " " << printable_area << " " << kTextHeight; + EXPECT_EQ(overlay_area, setup.overlay_area()) << " " << page_size << + " " << printable_area << " " << kTextHeight; + EXPECT_EQ(content_area, setup.content_area()) << " " << page_size << + " " << printable_area << " " << kTextHeight; + + EXPECT_EQ(effective_margins.header, setup.effective_margins().header) << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.footer, setup.effective_margins().footer) << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.left, setup.effective_margins().left) << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.top, setup.effective_margins().top) << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.right, setup.effective_margins().right) << + " " << page_size << " " << printable_area << " " << kTextHeight; + EXPECT_EQ(effective_margins.bottom, setup.effective_margins().bottom) << + " " << page_size << " " << printable_area << " " << kTextHeight; +} |