| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_cairo.h" | 5 #include "printing/pdf_ps_metafile_cairo.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // Checks data size. | 49 // Checks data size. |
| 50 uint32 size = pdf.GetDataSize(); | 50 uint32 size = pdf.GetDataSize(); |
| 51 EXPECT_GT(size, 0u); | 51 EXPECT_GT(size, 0u); |
| 52 | 52 |
| 53 // Gets resulting data. | 53 // Gets resulting data. |
| 54 std::vector<char> buffer(size, 0x00); | 54 std::vector<char> buffer(size, 0x00); |
| 55 pdf.GetData(&buffer.front(), size); | 55 pdf.GetData(&buffer.front(), size); |
| 56 | 56 |
| 57 // Tests another constructor. | 57 // Tests another constructor. |
| 58 printing::PdfPsMetafile pdf2; | 58 printing::PdfPsMetafile pdf2; |
| 59 EXPECT_TRUE(pdf2.Init(&buffer.front(), size)); | 59 EXPECT_TRUE(pdf2.InitFromData(&buffer.front(), size)); |
| 60 | 60 |
| 61 // Tries to get the first 4 characters from pdf2. | 61 // Tries to get the first 4 characters from pdf2. |
| 62 std::vector<char> buffer2(4, 0x00); | 62 std::vector<char> buffer2(4, 0x00); |
| 63 pdf2.GetData(&buffer2.front(), 4); | 63 pdf2.GetData(&buffer2.front(), 4); |
| 64 | 64 |
| 65 // Tests if the header begins with "%PDF". | 65 // Tests if the header begins with "%PDF". |
| 66 std::string header(&buffer2.front(), 4); | 66 std::string header(&buffer2.front(), 4); |
| 67 EXPECT_EQ(header.find("%PDF", 0), 0u); | 67 EXPECT_EQ(header.find("%PDF", 0), 0u); |
| 68 | 68 |
| 69 // Tests if we can save data. | 69 // Tests if we can save data. |
| 70 EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null"))); | 70 EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null"))); |
| 71 | 71 |
| 72 // Test overriding the metafile with raw data. | 72 // Test overriding the metafile with raw data. |
| 73 printing::PdfPsMetafile pdf3; | 73 printing::PdfPsMetafile pdf3; |
| 74 EXPECT_TRUE(pdf3.Init()); | 74 EXPECT_TRUE(pdf3.Init()); |
| 75 context = pdf3.StartPage(gfx::Size(72 + 2 + 4, 72 + 1 + 3), 1, 4); | 75 context = pdf3.StartPage(gfx::Size(72 + 2 + 4, 72 + 1 + 3), 1, 4); |
| 76 EXPECT_TRUE(context != NULL); | 76 EXPECT_TRUE(context != NULL); |
| 77 std::string test_raw_data = "Dummy PDF"; | 77 std::string test_raw_data = "Dummy PDF"; |
| 78 EXPECT_TRUE(pdf3.SetRawData(test_raw_data.c_str(), test_raw_data.size())); | 78 EXPECT_TRUE(pdf3.SetRawData(test_raw_data.c_str(), test_raw_data.size())); |
| 79 EXPECT_TRUE(pdf3.FinishPage()); | 79 EXPECT_TRUE(pdf3.FinishPage()); |
| 80 pdf3.Close(); | 80 pdf3.Close(); |
| 81 size = pdf3.GetDataSize(); | 81 size = pdf3.GetDataSize(); |
| 82 EXPECT_EQ(test_raw_data.size(), size); | 82 EXPECT_EQ(test_raw_data.size(), size); |
| 83 std::string output; | 83 std::string output; |
| 84 pdf3.GetData(WriteInto(&output, size + 1), size); | 84 pdf3.GetData(WriteInto(&output, size + 1), size); |
| 85 EXPECT_EQ(test_raw_data, output); | 85 EXPECT_EQ(test_raw_data, output); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace printing | 88 } // namespace printing |
| OLD | NEW |