Chromium Code Reviews| Index: printing/pdf_ps_metafile_cairo_unittest.cc |
| diff --git a/printing/pdf_ps_metafile_cairo_unittest.cc b/printing/pdf_ps_metafile_cairo_unittest.cc |
| index 927306617c18a974ebac898f7349083b8a1f53ab..0b05f1a4d338fbae1a588c8d875ade77e5e5502f 100644 |
| --- a/printing/pdf_ps_metafile_cairo_unittest.cc |
| +++ b/printing/pdf_ps_metafile_cairo_unittest.cc |
| @@ -10,7 +10,9 @@ |
| #include "base/file_descriptor_posix.h" |
| #include "base/file_util.h" |
| +#include "base/scoped_ptr.h" |
| #include "base/string_util.h" |
| +#include "printing/metafile_factory.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| typedef struct _cairo cairo_t; |
| @@ -24,61 +26,65 @@ class PdfPsTest : public testing::Test { |
| TEST_F(PdfPsTest, Pdf) { |
| // Tests in-renderer constructor. |
| - printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF); |
| - EXPECT_TRUE(pdf.Init()); |
| + scoped_ptr<printing::NativeMetafile> pdf_ptr( |
| + printing::MetafileFactory::GetMetafile()); |
| + EXPECT_TRUE(pdf_ptr->Init()); |
| // Renders page 1. |
| - cairo_t* context = pdf.StartPage(72, 72, 1, 2, 3, 4); |
| + cairo_t* context = pdf_ptr->StartPage(72, 72, 1, 2, 3, 4); |
| EXPECT_TRUE(context != NULL); |
| - EXPECT_EQ(printing::PdfPsMetafile::FromCairoContext(context), &pdf); |
| + //EXPECT_EQ(printing::PdfPsMetafile::FromCairoContext(context), pdf_ptr); |
|
Avi (use Gerrit)
2011/02/22 17:33:42
In general, don't commit commented-out code unless
dpapad
2011/02/22 18:09:30
Done.
|
| + EXPECT_EQ(printing::MetafileFactory::GetMetafileFrom(context), pdf_ptr); |
| // In theory, we should use Cairo to draw something on |context|. |
| - EXPECT_TRUE(pdf.FinishPage()); |
| + EXPECT_TRUE(pdf_ptr->FinishPage()); |
| // Renders page 2. |
| - context = pdf.StartPage(64, 64, 1, 2, 3, 4); |
| + context = pdf_ptr->StartPage(64, 64, 1, 2, 3, 4); |
| EXPECT_TRUE(context != NULL); |
| // In theory, we should use Cairo to draw something on |context|. |
| - EXPECT_TRUE(pdf.FinishPage()); |
| + EXPECT_TRUE(pdf_ptr->FinishPage()); |
| // Closes the file. |
| - pdf.Close(); |
| + pdf_ptr->Close(); |
| // Checks data size. |
| - uint32 size = pdf.GetDataSize(); |
| + uint32 size = pdf_ptr->GetDataSize(); |
| EXPECT_GT(size, 0u); |
| // Gets resulting data. |
| std::vector<char> buffer(size, 0x00); |
| - pdf.GetData(&buffer.front(), size); |
| + pdf_ptr->GetData(&buffer.front(), size); |
| // Tests another constructor. |
| - printing::PdfPsMetafile pdf2(printing::PdfPsMetafile::PDF); |
| - EXPECT_TRUE(pdf2.Init(&buffer.front(), size)); |
| + scoped_ptr<printing::NativeMetafile> pdf2_ptr( |
| + printing::MetafileFactory::GetMetafile()); |
| + EXPECT_TRUE(pdf2_ptr->Init(&buffer.front(), size)); |
| // Tries to get the first 4 characters from pdf2. |
| std::vector<char> buffer2(4, 0x00); |
| - pdf2.GetData(&buffer2.front(), 4); |
| + pdf2_ptr->GetData(&buffer2.front(), 4); |
| // Tests if the header begins with "%PDF". |
| std::string header(&buffer2.front(), 4); |
| EXPECT_EQ(header.find("%PDF", 0), 0u); |
| // Tests if we can save data. |
| - EXPECT_TRUE(pdf.SaveTo(DevNullFD())); |
| + EXPECT_TRUE(pdf_ptr->SaveTo(DevNullFD())); |
| // Test overriding the metafile with raw data. |
| - printing::PdfPsMetafile pdf3(printing::PdfPsMetafile::PDF); |
| - EXPECT_TRUE(pdf3.Init()); |
| - context = pdf3.StartPage(72, 72, 1, 2, 3, 4); |
| + scoped_ptr<printing::NativeMetafile> pdf3_ptr( |
| + printing::MetafileFactory::GetMetafile()); |
| + EXPECT_TRUE(pdf3_ptr->Init()); |
| + context = pdf3_ptr->StartPage(72, 72, 1, 2, 3, 4); |
| EXPECT_TRUE(context != NULL); |
| std::string test_raw_data = "Dummy PDF"; |
| - EXPECT_TRUE(pdf3.SetRawData(test_raw_data.c_str(), test_raw_data.size())); |
| - EXPECT_TRUE(pdf3.FinishPage()); |
| - pdf3.Close(); |
| - size = pdf3.GetDataSize(); |
| + EXPECT_TRUE(pdf3_ptr->SetRawData(test_raw_data.c_str(), test_raw_data.size())); |
| + EXPECT_TRUE(pdf3_ptr->FinishPage()); |
| + pdf3_ptr->Close(); |
| + size = pdf3_ptr->GetDataSize(); |
| EXPECT_EQ(test_raw_data.size(), size); |
| std::string output; |
| - pdf3.GetData(WriteInto(&output, size + 1), size); |
| + pdf3_ptr->GetData(WriteInto(&output, size + 1), size); |
| EXPECT_EQ(test_raw_data, output); |
| } |
| @@ -90,7 +96,8 @@ TEST_F(PdfPsTest, Ps) { |
| // Renders page 1. |
| cairo_t* context = ps.StartPage(72, 72, 1, 2, 3, 4); |
| EXPECT_TRUE(context != NULL); |
| - EXPECT_EQ(printing::PdfPsMetafile::FromCairoContext(context), &ps); |
| + //EXPECT_EQ(printing::PdfPsMetafile::FromCairoContext(context), &ps); |
| + EXPECT_EQ(printing::MetafileFactory::GetMetafileFrom(context), &ps); |
| // In theory, we should use Cairo to draw something on |context|. |
| EXPECT_TRUE(ps.FinishPage()); |