OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "printing/pdf_ps_metafile_linux.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/file_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 typedef struct _cairo cairo_t; |
| 14 |
| 15 TEST(PdfTest, Basic) { |
| 16 // Tests in-renderer constructor. |
| 17 printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF); |
| 18 cairo_t* context = pdf.GetPageContext(); |
| 19 EXPECT_TRUE(context == NULL); |
| 20 |
| 21 // Renders page 1. |
| 22 EXPECT_TRUE(pdf.StartPage(72, 72)); |
| 23 context = pdf.GetPageContext(); |
| 24 EXPECT_TRUE(context != NULL); |
| 25 // In theory, we should use Cairo to draw something on |context|. |
| 26 pdf.FinishPage(1.5); |
| 27 context = pdf.GetPageContext(); |
| 28 EXPECT_TRUE(context == NULL); |
| 29 |
| 30 // Renders page 2. |
| 31 EXPECT_TRUE(pdf.StartPage(64, 64)); |
| 32 context = pdf.GetPageContext(); |
| 33 EXPECT_TRUE(context != NULL); |
| 34 // In theory, we should use Cairo to draw something on |context|. |
| 35 pdf.FinishPage(0.5); |
| 36 context = pdf.GetPageContext(); |
| 37 EXPECT_TRUE(context == NULL); |
| 38 |
| 39 // Closes the file. |
| 40 pdf.Close(); |
| 41 context = pdf.GetPageContext(); |
| 42 EXPECT_TRUE(context == NULL); |
| 43 |
| 44 // Checks data size. |
| 45 unsigned int size = pdf.GetDataSize(); |
| 46 EXPECT_GT(size, 0u); |
| 47 |
| 48 // Gets resulting data. |
| 49 std::vector<char> buffer(size, 0x00); |
| 50 pdf.GetData(&buffer.front(), size); |
| 51 |
| 52 // Tests another constructor. |
| 53 printing::PdfPsMetafile pdf2(printing::PdfPsMetafile::PDF, |
| 54 &buffer.front(), |
| 55 size); |
| 56 |
| 57 // Tries to get the first 4 characters from pdf2. |
| 58 std::vector<char> buffer2(4, 0x00); |
| 59 pdf2.GetData(&buffer2.front(), 4); |
| 60 |
| 61 // Tests if the header begins with "%PDF". |
| 62 std::string header(&buffer2.front(), 4); |
| 63 EXPECT_EQ(header.find("%PDF", 0), 0u); |
| 64 |
| 65 // Tests if we can save data. |
| 66 EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null"))); |
| 67 } |
| 68 |
| 69 TEST(PsTest, Basic) { |
| 70 // Tests in-renderer constructor. |
| 71 printing::PdfPsMetafile ps(printing::PdfPsMetafile::PS); |
| 72 cairo_t* context = ps.GetPageContext(); |
| 73 EXPECT_TRUE(context == NULL); |
| 74 |
| 75 // Renders page 1. |
| 76 EXPECT_TRUE(ps.StartPage(72, 72)); |
| 77 context = ps.GetPageContext(); |
| 78 EXPECT_TRUE(context != NULL); |
| 79 // In theory, we should use Cairo to draw something on |context|. |
| 80 ps.FinishPage(1.5); |
| 81 context = ps.GetPageContext(); |
| 82 EXPECT_TRUE(context == NULL); |
| 83 |
| 84 // Renders page 2. |
| 85 EXPECT_TRUE(ps.StartPage(64, 64)); |
| 86 context = ps.GetPageContext(); |
| 87 EXPECT_TRUE(context != NULL); |
| 88 // In theory, we should use Cairo to draw something on |context|. |
| 89 ps.FinishPage(0.5); |
| 90 context = ps.GetPageContext(); |
| 91 EXPECT_TRUE(context == NULL); |
| 92 |
| 93 // Closes the file. |
| 94 ps.Close(); |
| 95 context = ps.GetPageContext(); |
| 96 EXPECT_TRUE(context == NULL); |
| 97 |
| 98 // Checks data size. |
| 99 unsigned int size = ps.GetDataSize(); |
| 100 EXPECT_GT(size, 0u); |
| 101 |
| 102 // Gets resulting data. |
| 103 std::vector<char> buffer(size, 0x00); |
| 104 ps.GetData(&buffer.front(), size); |
| 105 |
| 106 // Tests another constructor. |
| 107 printing::PdfPsMetafile ps2(printing::PdfPsMetafile::PS, |
| 108 &buffer.front(), |
| 109 size); |
| 110 |
| 111 // Tries to get the first 4 characters from ps2. |
| 112 std::vector<char> buffer2(4, 0x00); |
| 113 ps2.GetData(&buffer2.front(), 4); |
| 114 |
| 115 // Tests if the header begins with "%!PS". |
| 116 std::string header(&buffer2.front(), 4); |
| 117 EXPECT_EQ(header.find("%!PS", 0), 0u); |
| 118 |
| 119 // Tests if we can save data. |
| 120 EXPECT_TRUE(ps.SaveTo(FilePath("/dev/null"))); |
| 121 } |
| 122 |
OLD | NEW |