diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 23:15:06 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 23:15:06 +0000 |
commit | 9b61753963f16cc6cf48f388a2c24e064add4cbb (patch) | |
tree | 6fbae6593eb9465c320a5f35ebdaa24612818bb0 /printing/pdf_metafile_cg_mac_unittest.cc | |
parent | 22796b1a1791a0d1e84bf2d0eeba82d08d0687c1 (diff) | |
download | chromium_src-9b61753963f16cc6cf48f388a2c24e064add4cbb.zip chromium_src-9b61753963f16cc6cf48f388a2c24e064add4cbb.tar.gz chromium_src-9b61753963f16cc6cf48f388a2c24e064add4cbb.tar.bz2 |
Rename some printing classes and minor cleanups.
Rename:
PdfPsMetafile -> PdfMetafileCairo
PdfMetafile -> PdfMetafileCg (Mac)
VectorPlatformDevice -> VectorPlatformDeviceEmf/Cairo (Windows/Linux varients)
This is in preparation for VectorPlatformDeviceSkia.
BUG=NONE
TEST=NONE
Review URL: http://codereview.chromium.org/6783036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/pdf_metafile_cg_mac_unittest.cc')
-rw-r--r-- | printing/pdf_metafile_cg_mac_unittest.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/printing/pdf_metafile_cg_mac_unittest.cc b/printing/pdf_metafile_cg_mac_unittest.cc new file mode 100644 index 0000000..5324514 --- /dev/null +++ b/printing/pdf_metafile_cg_mac_unittest.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2011 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/pdf_metafile_cg_mac.h" + +#import <ApplicationServices/ApplicationServices.h> + +#include <string> +#include <vector> + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/rect.h" + +namespace printing { + +TEST(PdfMetafileCgTest, Pdf) { + // Test in-renderer constructor. + printing::PdfMetafileCg pdf; + EXPECT_TRUE(pdf.Init()); + EXPECT_TRUE(pdf.context() != NULL); + + // Render page 1 at origin (10.0, 10.0). + gfx::Point origin_1(10.0f, 10.0f); + gfx::Size size_1(540, 720); + pdf.StartPage(size_1, origin_1, 1.25); + pdf.FinishPage(); + + // Render page 2 at origin (10.0, 10.0). + gfx::Point origin_2(10.0f, 10.0f); + gfx::Size size_2(720, 540); + pdf.StartPage(size_2, origin_2, 2.0); + pdf.FinishPage(); + + pdf.FinishDocument(); + + // Check data size. + uint32 size = pdf.GetDataSize(); + EXPECT_GT(size, 0U); + + // Get resulting data. + std::vector<char> buffer(size, 0); + pdf.GetData(&buffer.front(), size); + + // Test browser-side constructor. + printing::PdfMetafileCg pdf2; + EXPECT_TRUE(pdf2.InitFromData(&buffer.front(), size)); + + // Get the first 4 characters from pdf2. + std::vector<char> buffer2(4, 0); + pdf2.GetData(&buffer2.front(), 4); + + // Test that the header begins with "%PDF". + std::string header(&buffer2.front(), 4); + EXPECT_EQ(0U, header.find("%PDF", 0)); + + // Test that the PDF is correctly reconstructed. + EXPECT_EQ(2U, pdf2.GetPageCount()); + gfx::Size page_size = pdf2.GetPageBounds(1).size(); + EXPECT_EQ(540, page_size.width()); + EXPECT_EQ(720, page_size.height()); + page_size = pdf2.GetPageBounds(2).size(); + EXPECT_EQ(720, page_size.width()); + EXPECT_EQ(540, page_size.height()); +} + +} // namespace printing |