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>
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/geometry/rect.h"
17 TEST(PdfMetafileCgTest
, Pdf
) {
18 // Test in-renderer constructor.
20 EXPECT_TRUE(pdf
.Init());
21 EXPECT_TRUE(pdf
.context() != NULL
);
24 gfx::Rect
rect_1(10, 10, 520, 700);
25 gfx::Size
size_1(540, 720);
26 pdf
.StartPage(size_1
, rect_1
, 1.25);
30 gfx::Rect
rect_2(10, 10, 520, 700);
31 gfx::Size
size_2(720, 540);
32 pdf
.StartPage(size_2
, rect_2
, 2.0);
38 uint32 size
= pdf
.GetDataSize();
41 // Get resulting data.
42 std::vector
<char> buffer(size
, 0);
43 pdf
.GetData(&buffer
.front(), size
);
45 // Test browser-side constructor.
47 EXPECT_TRUE(pdf2
.InitFromData(&buffer
.front(), size
));
49 // Get the first 4 characters from pdf2.
50 std::vector
<char> buffer2(4, 0);
51 pdf2
.GetData(&buffer2
.front(), 4);
53 // Test that the header begins with "%PDF".
54 std::string
header(&buffer2
.front(), 4);
55 EXPECT_EQ(0U, header
.find("%PDF", 0));
57 // Test that the PDF is correctly reconstructed.
58 EXPECT_EQ(2U, pdf2
.GetPageCount());
59 gfx::Size page_size
= pdf2
.GetPageBounds(1).size();
60 EXPECT_EQ(540, page_size
.width());
61 EXPECT_EQ(720, page_size
.height());
62 page_size
= pdf2
.GetPageBounds(2).size();
63 EXPECT_EQ(720, page_size
.width());
64 EXPECT_EQ(540, page_size
.height());
67 } // namespace printing