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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 PrintSettings settings; | 80 PrintSettings settings; |
81 | 81 |
82 // My test case is a HP Color LaserJet 4550 PCL. | 82 // My test case is a HP Color LaserJet 4550 PCL. |
83 settings.set_device_name(L"UnitTest Printer"); | 83 settings.set_device_name(L"UnitTest Printer"); |
84 | 84 |
85 // Initialize it. | 85 // Initialize it. |
86 scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); | 86 scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); |
87 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); | 87 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); |
88 | 88 |
89 FilePath emf_file; | 89 base::FilePath emf_file; |
90 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); | 90 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); |
91 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) | 91 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) |
92 .Append(FILE_PATH_LITERAL("test")) | 92 .Append(FILE_PATH_LITERAL("test")) |
93 .Append(FILE_PATH_LITERAL("data")) | 93 .Append(FILE_PATH_LITERAL("data")) |
94 .Append(FILE_PATH_LITERAL("test4.emf")); | 94 .Append(FILE_PATH_LITERAL("test4.emf")); |
95 // Load any EMF with an image. | 95 // Load any EMF with an image. |
96 Emf emf; | 96 Emf emf; |
97 std::string emf_data; | 97 std::string emf_data; |
98 file_util::ReadFileToString(emf_file, &emf_data); | 98 file_util::ReadFileToString(emf_file, &emf_data); |
99 ASSERT_TRUE(emf_data.size()); | 99 ASSERT_TRUE(emf_data.size()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (::OpenPrinter(L"UnitTest Printer", &printer, NULL)) { | 164 if (::OpenPrinter(L"UnitTest Printer", &printer, NULL)) { |
165 ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE); | 165 ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE); |
166 ClosePrinter(printer); | 166 ClosePrinter(printer); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 TEST(EmfTest, FileBackedEmf) { | 170 TEST(EmfTest, FileBackedEmf) { |
171 // Simplest use case. | 171 // Simplest use case. |
172 base::ScopedTempDir scratch_metafile_dir; | 172 base::ScopedTempDir scratch_metafile_dir; |
173 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); | 173 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); |
174 FilePath metafile_path; | 174 base::FilePath metafile_path; |
175 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(), | 175 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(), |
176 &metafile_path)); | 176 &metafile_path)); |
177 uint32 size; | 177 uint32 size; |
178 std::vector<BYTE> data; | 178 std::vector<BYTE> data; |
179 { | 179 { |
180 Emf emf; | 180 Emf emf; |
181 EXPECT_TRUE(emf.InitToFile(metafile_path)); | 181 EXPECT_TRUE(emf.InitToFile(metafile_path)); |
182 EXPECT_TRUE(emf.context() != NULL); | 182 EXPECT_TRUE(emf.context() != NULL); |
183 // An empty EMF is invalid, so we put at least a rectangle in it. | 183 // An empty EMF is invalid, so we put at least a rectangle in it. |
184 ::Rectangle(emf.context(), 10, 10, 190, 190); | 184 ::Rectangle(emf.context(), 10, 10, 190, 190); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 221 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
222 | 222 |
223 raster.reset(emf.RasterizeMetafile(16*1024*1024)); | 223 raster.reset(emf.RasterizeMetafile(16*1024*1024)); |
224 // Expected size about 64MB. | 224 // Expected size about 64MB. |
225 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); | 225 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); |
226 // Bounds should still be the same. | 226 // Bounds should still be the same. |
227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
228 } | 228 } |
229 | 229 |
230 } // namespace printing | 230 } // namespace printing |
OLD | NEW |