OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 27 matching lines...) Expand all Loading... |
38 return true; | 38 return true; |
39 DeleteDC(hdc); | 39 DeleteDC(hdc); |
40 return false; | 40 return false; |
41 } | 41 } |
42 | 42 |
43 // PrintingContext::Delegate methods. | 43 // PrintingContext::Delegate methods. |
44 gfx::NativeView GetParentView() override { return NULL; } | 44 gfx::NativeView GetParentView() override { return NULL; } |
45 std::string GetAppLocale() override { return std::string(); } | 45 std::string GetAppLocale() override { return std::string(); } |
46 }; | 46 }; |
47 | 47 |
48 const uint32 EMF_HEADER_SIZE = 128; | 48 const uint32_t EMF_HEADER_SIZE = 128; |
| 49 const int ONE_MB = 1024 * 1024; |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 TEST(EmfTest, DC) { | 53 TEST(EmfTest, DC) { |
53 // Simplest use case. | 54 // Simplest use case. |
54 uint32 size; | 55 uint32_t size; |
55 std::vector<char> data; | 56 std::vector<char> data; |
56 { | 57 { |
57 Emf emf; | 58 Emf emf; |
58 EXPECT_TRUE(emf.Init()); | 59 EXPECT_TRUE(emf.Init()); |
59 EXPECT_TRUE(emf.context() != NULL); | 60 EXPECT_TRUE(emf.context() != NULL); |
60 // An empty EMF is invalid, so we put at least a rectangle in it. | 61 // An empty EMF is invalid, so we put at least a rectangle in it. |
61 ::Rectangle(emf.context(), 10, 10, 190, 190); | 62 ::Rectangle(emf.context(), 10, 10, 190, 190); |
62 EXPECT_TRUE(emf.FinishDocument()); | 63 EXPECT_TRUE(emf.FinishDocument()); |
63 size = emf.GetDataSize(); | 64 size = emf.GetDataSize(); |
64 EXPECT_GT(size, EMF_HEADER_SIZE); | 65 EXPECT_GT(size, EMF_HEADER_SIZE); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 context->PageDone(); | 127 context->PageDone(); |
127 context->DocumentDone(); | 128 context->DocumentDone(); |
128 } | 129 } |
129 | 130 |
130 // Disabled if no "UnitTest printer" exists. | 131 // Disabled if no "UnitTest printer" exists. |
131 TEST_F(EmfPrintingTest, PageBreak) { | 132 TEST_F(EmfPrintingTest, PageBreak) { |
132 base::win::ScopedCreateDC dc( | 133 base::win::ScopedCreateDC dc( |
133 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); | 134 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); |
134 if (!dc.Get()) | 135 if (!dc.Get()) |
135 return; | 136 return; |
136 uint32 size; | 137 uint32_t size; |
137 std::vector<char> data; | 138 std::vector<char> data; |
138 { | 139 { |
139 Emf emf; | 140 Emf emf; |
140 EXPECT_TRUE(emf.Init()); | 141 EXPECT_TRUE(emf.Init()); |
141 EXPECT_TRUE(emf.context() != NULL); | 142 EXPECT_TRUE(emf.context() != NULL); |
142 int pages = 3; | 143 int pages = 3; |
143 while (pages) { | 144 while (pages) { |
144 EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1)); | 145 EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1)); |
145 ::Rectangle(emf.context(), 10, 10, 190, 190); | 146 ::Rectangle(emf.context(), 10, 10, 190, 190); |
146 EXPECT_TRUE(emf.FinishPage()); | 147 EXPECT_TRUE(emf.FinishPage()); |
(...skipping 24 matching lines...) Expand all Loading... |
171 } | 172 } |
172 } | 173 } |
173 | 174 |
174 TEST(EmfTest, FileBackedEmf) { | 175 TEST(EmfTest, FileBackedEmf) { |
175 // Simplest use case. | 176 // Simplest use case. |
176 base::ScopedTempDir scratch_metafile_dir; | 177 base::ScopedTempDir scratch_metafile_dir; |
177 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); | 178 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); |
178 base::FilePath metafile_path; | 179 base::FilePath metafile_path; |
179 EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(), | 180 EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(), |
180 &metafile_path)); | 181 &metafile_path)); |
181 uint32 size; | 182 uint32_t size; |
182 std::vector<char> data; | 183 std::vector<char> data; |
183 { | 184 { |
184 Emf emf; | 185 Emf emf; |
185 EXPECT_TRUE(emf.InitToFile(metafile_path)); | 186 EXPECT_TRUE(emf.InitToFile(metafile_path)); |
186 EXPECT_TRUE(emf.context() != NULL); | 187 EXPECT_TRUE(emf.context() != NULL); |
187 // An empty EMF is invalid, so we put at least a rectangle in it. | 188 // An empty EMF is invalid, so we put at least a rectangle in it. |
188 ::Rectangle(emf.context(), 10, 10, 190, 190); | 189 ::Rectangle(emf.context(), 10, 10, 190, 190); |
189 EXPECT_TRUE(emf.FinishDocument()); | 190 EXPECT_TRUE(emf.FinishDocument()); |
190 size = emf.GetDataSize(); | 191 size = emf.GetDataSize(); |
191 EXPECT_GT(size, EMF_HEADER_SIZE); | 192 EXPECT_GT(size, EMF_HEADER_SIZE); |
192 EXPECT_TRUE(emf.GetDataAsVector(&data)); | 193 EXPECT_TRUE(emf.GetDataAsVector(&data)); |
193 EXPECT_EQ(data.size(), size); | 194 EXPECT_EQ(data.size(), size); |
194 } | 195 } |
195 int64 file_size = 0; | 196 int64_t file_size = 0; |
196 base::GetFileSize(metafile_path, &file_size); | 197 base::GetFileSize(metafile_path, &file_size); |
197 EXPECT_EQ(size, file_size); | 198 EXPECT_EQ(size, file_size); |
198 | 199 |
199 // Playback the data. | 200 // Playback the data. |
200 HDC hdc = CreateCompatibleDC(NULL); | 201 HDC hdc = CreateCompatibleDC(NULL); |
201 EXPECT_TRUE(hdc); | 202 EXPECT_TRUE(hdc); |
202 Emf emf; | 203 Emf emf; |
203 EXPECT_TRUE(emf.InitFromFile(metafile_path)); | 204 EXPECT_TRUE(emf.InitFromFile(metafile_path)); |
204 RECT output_rect = {0, 0, 10, 10}; | 205 RECT output_rect = {0, 0, 10, 10}; |
205 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); | 206 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); |
(...skipping 11 matching lines...) Expand all Loading... |
217 } | 218 } |
218 EXPECT_TRUE(emf.FinishDocument()); | 219 EXPECT_TRUE(emf.FinishDocument()); |
219 | 220 |
220 scoped_ptr<Emf> raster(emf.RasterizeMetafile(1)); | 221 scoped_ptr<Emf> raster(emf.RasterizeMetafile(1)); |
221 // Just 1px bitmap but should be stretched to the same bounds. | 222 // Just 1px bitmap but should be stretched to the same bounds. |
222 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 223 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
223 | 224 |
224 raster = emf.RasterizeMetafile(20); | 225 raster = emf.RasterizeMetafile(20); |
225 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 226 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
226 | 227 |
227 raster = emf.RasterizeMetafile(16 * 1024 * 1024); | 228 raster = emf.RasterizeMetafile(16 * ONE_MB); |
228 // Expected size about 64MB. | 229 // Expected size about 64MB. |
229 EXPECT_LE(abs(int(raster->GetDataSize()) - 64 * 1024 * 1024), 1024 * 1024); | 230 EXPECT_LE(abs(static_cast<int>(raster->GetDataSize()) - 64 * ONE_MB), ONE_MB); |
230 // Bounds should still be the same. | 231 // Bounds should still be the same. |
231 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 232 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
232 } | 233 } |
233 | 234 |
234 } // namespace printing | 235 } // namespace printing |
OLD | NEW |