OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/pdf_ps_metafile_linux.h" | 5 #include "printing/pdf_ps_metafile_linux.h" |
6 | 6 |
| 7 #include <fcntl.h> |
7 #include <string> | 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
| 11 #include "base/file_descriptor_posix.h" |
10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 typedef struct _cairo cairo_t; | 15 typedef struct _cairo cairo_t; |
14 | 16 |
15 TEST(PdfTest, ThreePages) { | 17 class PdfPsTest : public testing::Test { |
| 18 protected: |
| 19 base::FileDescriptor DevNullFD() { |
| 20 return base::FileDescriptor(open("/dev/null", O_WRONLY), true); |
| 21 } |
| 22 }; |
| 23 |
| 24 TEST_F(PdfPsTest, Pdf) { |
16 // Tests in-renderer constructor. | 25 // Tests in-renderer constructor. |
17 printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF); | 26 printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF); |
18 EXPECT_TRUE(pdf.Init()); | 27 EXPECT_TRUE(pdf.Init()); |
19 | 28 |
20 // Renders page 1. | 29 // Renders page 1. |
21 cairo_t* context = pdf.StartPage(72, 72); | 30 cairo_t* context = pdf.StartPage(72, 72); |
22 EXPECT_TRUE(context != NULL); | 31 EXPECT_TRUE(context != NULL); |
23 // In theory, we should use Cairo to draw something on |context|. | 32 // In theory, we should use Cairo to draw something on |context|. |
24 EXPECT_TRUE(pdf.FinishPage(1.5)); | 33 EXPECT_TRUE(pdf.FinishPage(1.5)); |
25 | 34 |
(...skipping 20 matching lines...) Expand all Loading... |
46 | 55 |
47 // Tries to get the first 4 characters from pdf2. | 56 // Tries to get the first 4 characters from pdf2. |
48 std::vector<char> buffer2(4, 0x00); | 57 std::vector<char> buffer2(4, 0x00); |
49 pdf2.GetData(&buffer2.front(), 4); | 58 pdf2.GetData(&buffer2.front(), 4); |
50 | 59 |
51 // Tests if the header begins with "%PDF". | 60 // Tests if the header begins with "%PDF". |
52 std::string header(&buffer2.front(), 4); | 61 std::string header(&buffer2.front(), 4); |
53 EXPECT_EQ(header.find("%PDF", 0), 0u); | 62 EXPECT_EQ(header.find("%PDF", 0), 0u); |
54 | 63 |
55 // Tests if we can save data. | 64 // Tests if we can save data. |
56 EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null"))); | 65 EXPECT_TRUE(pdf.SaveTo(DevNullFD())); |
57 } | 66 } |
58 | 67 |
59 TEST(PsTest, TwoPages) { | 68 TEST_F(PdfPsTest, Ps) { |
60 // Tests in-renderer constructor. | 69 // Tests in-renderer constructor. |
61 printing::PdfPsMetafile ps(printing::PdfPsMetafile::PS); | 70 printing::PdfPsMetafile ps(printing::PdfPsMetafile::PS); |
62 EXPECT_TRUE(ps.Init()); | 71 EXPECT_TRUE(ps.Init()); |
63 | 72 |
64 // Renders page 1. | 73 // Renders page 1. |
65 cairo_t* context = ps.StartPage(72, 72); | 74 cairo_t* context = ps.StartPage(72, 72); |
66 EXPECT_TRUE(context != NULL); | 75 EXPECT_TRUE(context != NULL); |
67 // In theory, we should use Cairo to draw something on |context|. | 76 // In theory, we should use Cairo to draw something on |context|. |
68 EXPECT_TRUE(ps.FinishPage(1.5)); | 77 EXPECT_TRUE(ps.FinishPage(1.5)); |
69 | 78 |
(...skipping 20 matching lines...) Expand all Loading... |
90 | 99 |
91 // Tries to get the first 4 characters from ps2. | 100 // Tries to get the first 4 characters from ps2. |
92 std::vector<char> buffer2(4, 0x00); | 101 std::vector<char> buffer2(4, 0x00); |
93 ps2.GetData(&buffer2.front(), 4); | 102 ps2.GetData(&buffer2.front(), 4); |
94 | 103 |
95 // Tests if the header begins with "%!PS". | 104 // Tests if the header begins with "%!PS". |
96 std::string header(&buffer2.front(), 4); | 105 std::string header(&buffer2.front(), 4); |
97 EXPECT_EQ(header.find("%!PS", 0), 0u); | 106 EXPECT_EQ(header.find("%!PS", 0), 0u); |
98 | 107 |
99 // Tests if we can save data. | 108 // Tests if we can save data. |
100 EXPECT_TRUE(ps.SaveTo(FilePath("/dev/null"))); | 109 EXPECT_TRUE(ps.SaveTo(DevNullFD())); |
101 } | 110 } |
OLD | NEW |