diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-22 06:36:58 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-22 06:36:58 +0000 |
commit | 481edc5493d2a5bd85ee882b3cf1a21f487a2a94 (patch) | |
tree | b35c073123e217e8306d0d96467a7297bc7e6991 /printing/emf_win_unittest.cc | |
parent | 12b251a3514d18fc598766a1277bb3ca36bc9448 (diff) | |
download | chromium_src-481edc5493d2a5bd85ee882b3cf1a21f487a2a94.zip chromium_src-481edc5493d2a5bd85ee882b3cf1a21f487a2a94.tar.gz chromium_src-481edc5493d2a5bd85ee882b3cf1a21f487a2a94.tar.bz2 |
Cleanup NativeMetafile (win) interface and EMF class.
- Rename CreateDc to Init() and remove unused argument (all non-test calls were CreateDc(NULL, NULL). [This matches cross platform interface.]
- Remove CreateFileBackedDc from the NativeMetafile interface and make InitToFile() in the EMF class.
- Remove CreateFromFile from the NativeMetafile interface and make it InitFromFile() in the EMF class.
- Move the CloseEmf method into the destructor, making the Emf class a use once class (matches actual use).
BUG=NONE
TEST=NONE
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78666
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=78669
Review URL: http://codereview.chromium.org/6695013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/emf_win_unittest.cc')
-rw-r--r-- | printing/emf_win_unittest.cc | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc index 9f2899b..2492104 100644 --- a/printing/emf_win_unittest.cc +++ b/printing/emf_win_unittest.cc @@ -45,26 +45,26 @@ namespace printing { TEST(EmfTest, DC) { // Simplest use case. - printing::Emf emf; - RECT rect = {100, 100, 200, 200}; - HDC hdc = CreateCompatibleDC(NULL); - EXPECT_TRUE(hdc != NULL); - EXPECT_TRUE(emf.CreateDc(hdc, &rect)); - EXPECT_TRUE(emf.context() != NULL); - // In theory, you'd use the HDC with GDI functions here. - EXPECT_TRUE(emf.FinishDocument()); - uint32 size = emf.GetDataSize(); - EXPECT_EQ(size, EMF_HEADER_SIZE); + uint32 size; std::vector<BYTE> data; - EXPECT_TRUE(emf.GetData(&data)); - EXPECT_EQ(data.size(), size); - emf.CloseEmf(); - EXPECT_TRUE(DeleteDC(hdc)); + { + printing::Emf emf; + EXPECT_TRUE(emf.Init()); + EXPECT_TRUE(emf.context() != NULL); + // An empty EMF is invalid, so we put at least a rectangle in it. + ::Rectangle(emf.context(), 10, 10, 190, 190); + EXPECT_TRUE(emf.FinishDocument()); + size = emf.GetDataSize(); + EXPECT_GT(size, EMF_HEADER_SIZE); + EXPECT_TRUE(emf.GetData(&data)); + EXPECT_EQ(data.size(), size); + } // Playback the data. - hdc = CreateCompatibleDC(NULL); - EXPECT_TRUE(hdc); + printing::Emf emf; EXPECT_TRUE(emf.InitFromData(&data.front(), size)); + HDC hdc = CreateCompatibleDC(NULL); + EXPECT_TRUE(hdc); RECT output_rect = {0, 0, 10, 10}; EXPECT_TRUE(emf.Playback(hdc, &output_rect)); EXPECT_TRUE(DeleteDC(hdc)); @@ -128,28 +128,31 @@ TEST_F(EmfPrintingTest, PageBreak) { CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); if (!dc.Get()) return; - printing::Emf emf; - EXPECT_TRUE(emf.CreateDc(dc.Get(), NULL)); - EXPECT_TRUE(emf.context() != NULL); - int pages = 3; - while (pages) { - EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Point(), 1)); - ::Rectangle(emf.context(), 10, 10, 190, 190); - EXPECT_TRUE(emf.FinishPage()); - --pages; - } - EXPECT_TRUE(emf.FinishDocument()); - uint32 size = emf.GetDataSize(); + uint32 size; std::vector<BYTE> data; - EXPECT_TRUE(emf.GetData(&data)); - EXPECT_EQ(data.size(), size); - emf.CloseEmf(); + { + printing::Emf emf; + EXPECT_TRUE(emf.Init()); + EXPECT_TRUE(emf.context() != NULL); + int pages = 3; + while (pages) { + EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Point(), 1)); + ::Rectangle(emf.context(), 10, 10, 190, 190); + EXPECT_TRUE(emf.FinishPage()); + --pages; + } + EXPECT_TRUE(emf.FinishDocument()); + size = emf.GetDataSize(); + EXPECT_TRUE(emf.GetData(&data)); + EXPECT_EQ(data.size(), size); + } // Playback the data. DOCINFO di = {0}; di.cbSize = sizeof(DOCINFO); di.lpszDocName = L"Test Job"; int job_id = ::StartDoc(dc.Get(), &di); + printing::Emf emf; EXPECT_TRUE(emf.InitFromData(&data.front(), size)); EXPECT_TRUE(emf.SafePlayback(dc.Get())); ::EndDoc(dc.Get()); @@ -162,41 +165,39 @@ TEST_F(EmfPrintingTest, PageBreak) { } } -TEST(EmfTest, FileBackedDC) { +TEST(EmfTest, FileBackedEmf) { // Simplest use case. - printing::Emf emf; - RECT rect = {100, 100, 200, 200}; - HDC hdc = CreateCompatibleDC(NULL); - EXPECT_TRUE(hdc != NULL); ScopedTempDir scratch_metafile_dir; ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); FilePath metafile_path; EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(), &metafile_path)); - EXPECT_TRUE(emf.CreateFileBackedDc(hdc, &rect, metafile_path)); - EXPECT_TRUE(emf.context() != NULL); - // In theory, you'd use the HDC with GDI functions here. - EXPECT_TRUE(emf.FinishDocument()); - - uint32 size = emf.GetDataSize(); - EXPECT_EQ(size, EMF_HEADER_SIZE); + uint32 size; std::vector<BYTE> data; - EXPECT_TRUE(emf.GetData(&data)); - EXPECT_EQ(data.size(), size); - emf.CloseEmf(); + { + printing::Emf emf; + EXPECT_TRUE(emf.InitToFile(metafile_path)); + EXPECT_TRUE(emf.context() != NULL); + // An empty EMF is invalid, so we put at least a rectangle in it. + ::Rectangle(emf.context(), 10, 10, 190, 190); + EXPECT_TRUE(emf.FinishDocument()); + size = emf.GetDataSize(); + EXPECT_GT(size, EMF_HEADER_SIZE); + EXPECT_TRUE(emf.GetData(&data)); + EXPECT_EQ(data.size(), size); + } int64 file_size = 0; file_util::GetFileSize(metafile_path, &file_size); EXPECT_EQ(size, file_size); - EXPECT_TRUE(DeleteDC(hdc)); // Playback the data. - hdc = CreateCompatibleDC(NULL); + HDC hdc = CreateCompatibleDC(NULL); EXPECT_TRUE(hdc); - EXPECT_TRUE(emf.CreateFromFile(metafile_path)); + printing::Emf emf; + EXPECT_TRUE(emf.InitFromFile(metafile_path)); RECT output_rect = {0, 0, 10, 10}; EXPECT_TRUE(emf.Playback(hdc, &output_rect)); EXPECT_TRUE(DeleteDC(hdc)); - emf.CloseEmf(); } } // namespace printing |