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

Side by Side Diff: printing/emf_win_unittest.cc

Issue 6611032: Unifying NativeMetafile class interface (as much as possible) for Linux, Mac, Win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Making virtual methods not virtual (for clang bots) 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/emf_win.cc ('k') | printing/image_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/emf_win.h" 5 #include "printing/emf_win.h"
6 6
7 // For quick access. 7 // For quick access.
8 #include <wingdi.h> 8 #include <wingdi.h>
9 #include <winspool.h> 9 #include <winspool.h>
10 10
(...skipping 30 matching lines...) Expand all
41 41
42 namespace printing { 42 namespace printing {
43 43
44 TEST(EmfTest, DC) { 44 TEST(EmfTest, DC) {
45 // Simplest use case. 45 // Simplest use case.
46 printing::Emf emf; 46 printing::Emf emf;
47 RECT rect = {100, 100, 200, 200}; 47 RECT rect = {100, 100, 200, 200};
48 HDC hdc = CreateCompatibleDC(NULL); 48 HDC hdc = CreateCompatibleDC(NULL);
49 EXPECT_TRUE(hdc != NULL); 49 EXPECT_TRUE(hdc != NULL);
50 EXPECT_TRUE(emf.CreateDc(hdc, &rect)); 50 EXPECT_TRUE(emf.CreateDc(hdc, &rect));
51 EXPECT_TRUE(emf.hdc() != NULL); 51 EXPECT_TRUE(emf.context() != NULL);
52 // In theory, you'd use the HDC with GDI functions here. 52 // In theory, you'd use the HDC with GDI functions here.
53 EXPECT_TRUE(emf.CloseDc()); 53 EXPECT_TRUE(emf.Close());
54 uint32 size = emf.GetDataSize(); 54 uint32 size = emf.GetDataSize();
55 EXPECT_EQ(size, EMF_HEADER_SIZE); 55 EXPECT_EQ(size, EMF_HEADER_SIZE);
56 std::vector<BYTE> data; 56 std::vector<BYTE> data;
57 EXPECT_TRUE(emf.GetData(&data)); 57 EXPECT_TRUE(emf.GetData(&data));
58 EXPECT_EQ(data.size(), size); 58 EXPECT_EQ(data.size(), size);
59 emf.CloseEmf(); 59 emf.CloseEmf();
60 EXPECT_TRUE(DeleteDC(hdc)); 60 EXPECT_TRUE(DeleteDC(hdc));
61 61
62 // Playback the data. 62 // Playback the data.
63 hdc = CreateCompatibleDC(NULL); 63 hdc = CreateCompatibleDC(NULL);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EXPECT_TRUE(emf.Init(&emf_data[0], emf_data.size())); 97 EXPECT_TRUE(emf.Init(&emf_data[0], emf_data.size()));
98 98
99 // This will print to file. The reason is that when running inside a 99 // This will print to file. The reason is that when running inside a
100 // unit_test, printing::PrintingContext automatically dumps its files to the 100 // unit_test, printing::PrintingContext automatically dumps its files to the
101 // current directory. 101 // current directory.
102 // TODO(maruel): Clean the .PRN file generated in current directory. 102 // TODO(maruel): Clean the .PRN file generated in current directory.
103 context->NewDocument(L"EmfTest.Enumerate"); 103 context->NewDocument(L"EmfTest.Enumerate");
104 context->NewPage(); 104 context->NewPage();
105 // Process one at a time. 105 // Process one at a time.
106 printing::Emf::Enumerator emf_enum(emf, context->context(), 106 printing::Emf::Enumerator emf_enum(emf, context->context(),
107 &emf.GetBounds().ToRECT()); 107 &emf.GetPageBounds(1).ToRECT());
108 for (printing::Emf::Enumerator::const_iterator itr = emf_enum.begin(); 108 for (printing::Emf::Enumerator::const_iterator itr = emf_enum.begin();
109 itr != emf_enum.end(); 109 itr != emf_enum.end();
110 ++itr) { 110 ++itr) {
111 // To help debugging. 111 // To help debugging.
112 ptrdiff_t index = itr - emf_enum.begin(); 112 ptrdiff_t index = itr - emf_enum.begin();
113 // If you get this assert, you need to lookup iType in wingdi.h. It starts 113 // If you get this assert, you need to lookup iType in wingdi.h. It starts
114 // with EMR_HEADER. 114 // with EMR_HEADER.
115 EMR_HEADER; 115 EMR_HEADER;
116 EXPECT_TRUE(itr->SafePlayback(NULL)) << 116 EXPECT_TRUE(itr->SafePlayback(NULL)) <<
117 " index: " << index << " type: " << itr->record()->iType; 117 " index: " << index << " type: " << itr->record()->iType;
118 } 118 }
119 context->PageDone(); 119 context->PageDone();
120 context->DocumentDone(); 120 context->DocumentDone();
121 } 121 }
122 122
123 // Disabled if no "UnitTest printer" exists. 123 // Disabled if no "UnitTest printer" exists.
124 TEST_F(EmfPrintingTest, PageBreak) { 124 TEST_F(EmfPrintingTest, PageBreak) {
125 base::win::ScopedHDC dc( 125 base::win::ScopedHDC dc(
126 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); 126 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL));
127 if (!dc.Get()) 127 if (!dc.Get())
128 return; 128 return;
129 printing::Emf emf; 129 printing::Emf emf;
130 EXPECT_TRUE(emf.CreateDc(dc.Get(), NULL)); 130 EXPECT_TRUE(emf.CreateDc(dc.Get(), NULL));
131 EXPECT_TRUE(emf.hdc() != NULL); 131 EXPECT_TRUE(emf.context() != NULL);
132 int pages = 3; 132 int pages = 3;
133 while (pages) { 133 while (pages) {
134 EXPECT_TRUE(emf.StartPage()); 134 EXPECT_TRUE(emf.StartPage());
135 ::Rectangle(emf.hdc(), 10, 10, 190, 190); 135 ::Rectangle(emf.context(), 10, 10, 190, 190);
136 EXPECT_TRUE(emf.EndPage()); 136 EXPECT_TRUE(emf.FinishPage());
137 --pages; 137 --pages;
138 } 138 }
139 EXPECT_TRUE(emf.CloseDc()); 139 EXPECT_TRUE(emf.Close());
140 uint32 size = emf.GetDataSize(); 140 uint32 size = emf.GetDataSize();
141 std::vector<BYTE> data; 141 std::vector<BYTE> data;
142 EXPECT_TRUE(emf.GetData(&data)); 142 EXPECT_TRUE(emf.GetData(&data));
143 EXPECT_EQ(data.size(), size); 143 EXPECT_EQ(data.size(), size);
144 emf.CloseEmf(); 144 emf.CloseEmf();
145 145
146 // Playback the data. 146 // Playback the data.
147 DOCINFO di = {0}; 147 DOCINFO di = {0};
148 di.cbSize = sizeof(DOCINFO); 148 di.cbSize = sizeof(DOCINFO);
149 di.lpszDocName = L"Test Job"; 149 di.lpszDocName = L"Test Job";
(...skipping 15 matching lines...) Expand all
165 printing::Emf emf; 165 printing::Emf emf;
166 RECT rect = {100, 100, 200, 200}; 166 RECT rect = {100, 100, 200, 200};
167 HDC hdc = CreateCompatibleDC(NULL); 167 HDC hdc = CreateCompatibleDC(NULL);
168 EXPECT_TRUE(hdc != NULL); 168 EXPECT_TRUE(hdc != NULL);
169 ScopedTempDir scratch_metafile_dir; 169 ScopedTempDir scratch_metafile_dir;
170 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); 170 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir());
171 FilePath metafile_path; 171 FilePath metafile_path;
172 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(), 172 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(),
173 &metafile_path)); 173 &metafile_path));
174 EXPECT_TRUE(emf.CreateFileBackedDc(hdc, &rect, metafile_path)); 174 EXPECT_TRUE(emf.CreateFileBackedDc(hdc, &rect, metafile_path));
175 EXPECT_TRUE(emf.hdc() != NULL); 175 EXPECT_TRUE(emf.context() != NULL);
176 // In theory, you'd use the HDC with GDI functions here. 176 // In theory, you'd use the HDC with GDI functions here.
177 EXPECT_TRUE(emf.CloseDc()); 177 EXPECT_TRUE(emf.Close());
178 178
179 uint32 size = emf.GetDataSize(); 179 uint32 size = emf.GetDataSize();
180 EXPECT_EQ(size, EMF_HEADER_SIZE); 180 EXPECT_EQ(size, EMF_HEADER_SIZE);
181 std::vector<BYTE> data; 181 std::vector<BYTE> data;
182 EXPECT_TRUE(emf.GetData(&data)); 182 EXPECT_TRUE(emf.GetData(&data));
183 EXPECT_EQ(data.size(), size); 183 EXPECT_EQ(data.size(), size);
184 emf.CloseEmf(); 184 emf.CloseEmf();
185 int64 file_size = 0; 185 int64 file_size = 0;
186 file_util::GetFileSize(metafile_path, &file_size); 186 file_util::GetFileSize(metafile_path, &file_size);
187 EXPECT_EQ(size, file_size); 187 EXPECT_EQ(size, file_size);
188 EXPECT_TRUE(DeleteDC(hdc)); 188 EXPECT_TRUE(DeleteDC(hdc));
189 189
190 // Playback the data. 190 // Playback the data.
191 hdc = CreateCompatibleDC(NULL); 191 hdc = CreateCompatibleDC(NULL);
192 EXPECT_TRUE(hdc); 192 EXPECT_TRUE(hdc);
193 EXPECT_TRUE(emf.CreateFromFile(metafile_path)); 193 EXPECT_TRUE(emf.CreateFromFile(metafile_path));
194 RECT output_rect = {0, 0, 10, 10}; 194 RECT output_rect = {0, 0, 10, 10};
195 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); 195 EXPECT_TRUE(emf.Playback(hdc, &output_rect));
196 EXPECT_TRUE(DeleteDC(hdc)); 196 EXPECT_TRUE(DeleteDC(hdc));
197 emf.CloseEmf(); 197 emf.CloseEmf();
198 } 198 }
199 199
200 } // namespace printing 200 } // namespace printing
OLDNEW
« no previous file with comments | « printing/emf_win.cc ('k') | printing/image_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698