Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Unified Diff: printing/emf_win_unittest.cc

Issue 6695013: Cleanup NativeMetafile (win) interface and EMF class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « printing/emf_win.cc ('k') | printing/native_metafile.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/emf_win_unittest.cc
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index 9f2899b365871e57e357001172d011381be6bb98..249210460f21bf7cd6547311a2ee3713a57e4d2a 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
« no previous file with comments | « printing/emf_win.cc ('k') | printing/native_metafile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698