blob: 3a38e682cbcdd4a0d04347050a3fe2bc780e6876 [file] [log] [blame]
[email protected]14b210792009-10-12 18:45:311// Copyright (c) 2009 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.
4
5#include "printing/pdf_metafile_mac.h"
6
7#import <ApplicationServices/ApplicationServices.h>
8
9#include <string>
10#include <vector>
11
[email protected]72f966b2009-10-14 20:02:2712#include "base/gfx/rect.h"
[email protected]14b210792009-10-12 18:45:3113#include "testing/gtest/include/gtest/gtest.h"
14
15TEST(PdfMetafileTest, Pdf) {
16 // Test in-renderer constructor.
17 printing::PdfMetafile pdf;
18 CGContextRef context = pdf.Init();
19 EXPECT_TRUE(context != NULL);
20
21 // Render page 1.
22 pdf.StartPage(540, 720, 1.25);
23 pdf.FinishPage();
24
25 // Render page 2.
26 pdf.StartPage(720, 540, 2.0);
27 pdf.FinishPage();
28
29 pdf.Close();
30
31 // Check data size.
32 unsigned int size = pdf.GetDataSize();
33 EXPECT_GT(size, 0U);
34
35 // Get resulting data.
36 std::vector<char> buffer(size, 0);
37 pdf.GetData(&buffer.front(), size);
38
39 // Test browser-side constructor.
40 printing::PdfMetafile pdf2;
41 EXPECT_TRUE(pdf2.Init(&buffer.front(), size));
42
43 // Get the first 4 characters from pdf2.
44 std::vector<char> buffer2(4, 0);
45 pdf2.GetData(&buffer2.front(), 4);
46
47 // Test that the header begins with "%PDF".
48 std::string header(&buffer2.front(), 4);
49 EXPECT_EQ(0U, header.find("%PDF", 0));
[email protected]72f966b2009-10-14 20:02:2750
51 // Test that the PDF is correctly reconstructed.
52 EXPECT_EQ(2U, pdf2.GetPageCount());
53 gfx::Size page_size = pdf2.GetPageBounds(1).size();
54 EXPECT_EQ(540, page_size.width());
55 EXPECT_EQ(720, page_size.height());
56 page_size = pdf2.GetPageBounds(2).size();
57 EXPECT_EQ(720, page_size.width());
58 EXPECT_EQ(540, page_size.height());
[email protected]14b210792009-10-12 18:45:3159}