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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 virtual std::string GetAppLocale() OVERRIDE { return std::string(); } | 45 virtual std::string GetAppLocale() OVERRIDE { return std::string(); } |
46 }; | 46 }; |
47 | 47 |
48 const uint32 EMF_HEADER_SIZE = 128; | 48 const uint32 EMF_HEADER_SIZE = 128; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 TEST(EmfTest, DC) { | 52 TEST(EmfTest, DC) { |
53 // Simplest use case. | 53 // Simplest use case. |
54 uint32 size; | 54 uint32 size; |
55 std::vector<BYTE> data; | 55 std::vector<char> data; |
56 { | 56 { |
57 Emf emf; | 57 Emf emf; |
58 EXPECT_TRUE(emf.Init()); | 58 EXPECT_TRUE(emf.Init()); |
59 EXPECT_TRUE(emf.context() != NULL); | 59 EXPECT_TRUE(emf.context() != NULL); |
60 // An empty EMF is invalid, so we put at least a rectangle in it. | 60 // An empty EMF is invalid, so we put at least a rectangle in it. |
61 ::Rectangle(emf.context(), 10, 10, 190, 190); | 61 ::Rectangle(emf.context(), 10, 10, 190, 190); |
62 EXPECT_TRUE(emf.FinishDocument()); | 62 EXPECT_TRUE(emf.FinishDocument()); |
63 size = emf.GetDataSize(); | 63 size = emf.GetDataSize(); |
64 EXPECT_GT(size, EMF_HEADER_SIZE); | 64 EXPECT_GT(size, EMF_HEADER_SIZE); |
65 EXPECT_TRUE(emf.GetDataAsVector(&data)); | 65 EXPECT_TRUE(emf.GetDataAsVector(&data)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 context->DocumentDone(); | 127 context->DocumentDone(); |
128 } | 128 } |
129 | 129 |
130 // Disabled if no "UnitTest printer" exists. | 130 // Disabled if no "UnitTest printer" exists. |
131 TEST_F(EmfPrintingTest, PageBreak) { | 131 TEST_F(EmfPrintingTest, PageBreak) { |
132 base::win::ScopedCreateDC dc( | 132 base::win::ScopedCreateDC dc( |
133 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); | 133 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); |
134 if (!dc.Get()) | 134 if (!dc.Get()) |
135 return; | 135 return; |
136 uint32 size; | 136 uint32 size; |
137 std::vector<BYTE> data; | 137 std::vector<char> data; |
138 { | 138 { |
139 Emf emf; | 139 Emf emf; |
140 EXPECT_TRUE(emf.Init()); | 140 EXPECT_TRUE(emf.Init()); |
141 EXPECT_TRUE(emf.context() != NULL); | 141 EXPECT_TRUE(emf.context() != NULL); |
142 int pages = 3; | 142 int pages = 3; |
143 while (pages) { | 143 while (pages) { |
144 EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1)); | 144 EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1)); |
145 ::Rectangle(emf.context(), 10, 10, 190, 190); | 145 ::Rectangle(emf.context(), 10, 10, 190, 190); |
146 EXPECT_TRUE(emf.FinishPage()); | 146 EXPECT_TRUE(emf.FinishPage()); |
147 --pages; | 147 --pages; |
(...skipping 24 matching lines...) Expand all Loading... |
172 } | 172 } |
173 | 173 |
174 TEST(EmfTest, FileBackedEmf) { | 174 TEST(EmfTest, FileBackedEmf) { |
175 // Simplest use case. | 175 // Simplest use case. |
176 base::ScopedTempDir scratch_metafile_dir; | 176 base::ScopedTempDir scratch_metafile_dir; |
177 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); | 177 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); |
178 base::FilePath metafile_path; | 178 base::FilePath metafile_path; |
179 EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(), | 179 EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(), |
180 &metafile_path)); | 180 &metafile_path)); |
181 uint32 size; | 181 uint32 size; |
182 std::vector<BYTE> data; | 182 std::vector<char> data; |
183 { | 183 { |
184 Emf emf; | 184 Emf emf; |
185 EXPECT_TRUE(emf.InitToFile(metafile_path)); | 185 EXPECT_TRUE(emf.InitToFile(metafile_path)); |
186 EXPECT_TRUE(emf.context() != NULL); | 186 EXPECT_TRUE(emf.context() != NULL); |
187 // An empty EMF is invalid, so we put at least a rectangle in it. | 187 // An empty EMF is invalid, so we put at least a rectangle in it. |
188 ::Rectangle(emf.context(), 10, 10, 190, 190); | 188 ::Rectangle(emf.context(), 10, 10, 190, 190); |
189 EXPECT_TRUE(emf.FinishDocument()); | 189 EXPECT_TRUE(emf.FinishDocument()); |
190 size = emf.GetDataSize(); | 190 size = emf.GetDataSize(); |
191 EXPECT_GT(size, EMF_HEADER_SIZE); | 191 EXPECT_GT(size, EMF_HEADER_SIZE); |
192 EXPECT_TRUE(emf.GetDataAsVector(&data)); | 192 EXPECT_TRUE(emf.GetDataAsVector(&data)); |
(...skipping 21 matching lines...) Expand all Loading... |
214 for (int i = 0; i < 4; ++i) { | 214 for (int i = 0; i < 4; ++i) { |
215 RECT rect = { 5 + i, 5 + i, 5 + i + 1, 5 + i + 2}; | 215 RECT rect = { 5 + i, 5 + i, 5 + i + 1, 5 + i + 2}; |
216 FillRect(emf.context(), &rect, brush); | 216 FillRect(emf.context(), &rect, brush); |
217 } | 217 } |
218 EXPECT_TRUE(emf.FinishDocument()); | 218 EXPECT_TRUE(emf.FinishDocument()); |
219 | 219 |
220 scoped_ptr<Emf> raster(emf.RasterizeMetafile(1)); | 220 scoped_ptr<Emf> raster(emf.RasterizeMetafile(1)); |
221 // Just 1px bitmap but should be stretched to the same bounds. | 221 // Just 1px bitmap but should be stretched to the same bounds. |
222 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 222 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
223 | 223 |
224 raster.reset(emf.RasterizeMetafile(20)); | 224 raster = emf.RasterizeMetafile(20); |
225 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 225 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
226 | 226 |
227 raster.reset(emf.RasterizeMetafile(16*1024*1024)); | 227 raster = emf.RasterizeMetafile(16 * 1024 * 1024); |
228 // Expected size about 64MB. | 228 // Expected size about 64MB. |
229 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); | 229 EXPECT_LE(abs(int(raster->GetDataSize()) - 64 * 1024 * 1024), 1024 * 1024); |
230 // Bounds should still be the same. | 230 // Bounds should still be the same. |
231 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 231 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
232 } | 232 } |
233 | 233 |
234 } // namespace printing | 234 } // namespace printing |
OLD | NEW |