1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/pdf_metafile_cg_mac.h"
7 #import <ApplicationServices/ApplicationServices.h>
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gfx/geometry/rect.h"
18 TEST(PdfMetafileCgTest, Pdf) {
19 // Test in-renderer constructor.
21 EXPECT_TRUE(pdf.Init());
22 EXPECT_TRUE(pdf.context() != NULL);
25 gfx::Rect rect_1(10, 10, 520, 700);
26 gfx::Size size_1(540, 720);
27 pdf.StartPage(size_1, rect_1, 1.25);
31 gfx::Rect rect_2(10, 10, 520, 700);
32 gfx::Size size_2(720, 540);
33 pdf.StartPage(size_2, rect_2, 2.0);
39 uint32_t size = pdf.GetDataSize();
42 // Get resulting data.
43 std::vector<char> buffer(size, 0);
44 pdf.GetData(&buffer.front(), size);
46 // Test browser-side constructor.
48 EXPECT_TRUE(pdf2.InitFromData(&buffer.front(), size));
50 // Get the first 4 characters from pdf2.
51 std::vector<char> buffer2(4, 0);
52 pdf2.GetData(&buffer2.front(), 4);
54 // Test that the header begins with "%PDF".
55 std::string header(&buffer2.front(), 4);
56 EXPECT_EQ(0U, header.find("%PDF", 0));
58 // Test that the PDF is correctly reconstructed.
59 EXPECT_EQ(2U, pdf2.GetPageCount());
60 gfx::Size page_size = pdf2.GetPageBounds(1).size();
61 EXPECT_EQ(540, page_size.width());
62 EXPECT_EQ(720, page_size.height());
63 page_size = pdf2.GetPageBounds(2).size();
64 EXPECT_EQ(720, page_size.width());
65 EXPECT_EQ(540, page_size.height());
68 } // namespace printing