OLD | NEW |
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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
17 #include "base/win/scoped_hdc.h" | 17 #include "base/win/scoped_hdc.h" |
| 18 #include "printing/native_metafile_factory.h" |
18 #include "printing/printing_context.h" | 19 #include "printing/printing_context.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // This test is automatically disabled if no printer named "UnitTest Printer" is | 24 // This test is automatically disabled if no printer named "UnitTest Printer" is |
24 // available. | 25 // available. |
25 class EmfPrintingTest : public testing::Test { | 26 class EmfPrintingTest : public testing::Test { |
26 public: | 27 public: |
27 typedef testing::Test Parent; | 28 typedef testing::Test Parent; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // the queue. | 154 // the queue. |
154 HANDLE printer = NULL; | 155 HANDLE printer = NULL; |
155 if (::OpenPrinter(L"UnitTest Printer", &printer, NULL)) { | 156 if (::OpenPrinter(L"UnitTest Printer", &printer, NULL)) { |
156 ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE); | 157 ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE); |
157 ClosePrinter(printer); | 158 ClosePrinter(printer); |
158 } | 159 } |
159 } | 160 } |
160 | 161 |
161 TEST(EmfTest, FileBackedDC) { | 162 TEST(EmfTest, FileBackedDC) { |
162 // Simplest use case. | 163 // Simplest use case. |
163 printing::Emf emf; | 164 scoped_ptr<printing::NativeMetafile> emf( |
| 165 printing::NativeMetafileFactory::CreateMetafile()); |
164 RECT rect = {100, 100, 200, 200}; | 166 RECT rect = {100, 100, 200, 200}; |
165 HDC hdc = CreateCompatibleDC(NULL); | 167 HDC hdc = CreateCompatibleDC(NULL); |
166 EXPECT_TRUE(hdc != NULL); | 168 EXPECT_TRUE(hdc != NULL); |
167 ScopedTempDir scratch_metafile_dir; | 169 ScopedTempDir scratch_metafile_dir; |
168 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); | 170 ASSERT_TRUE(scratch_metafile_dir.CreateUniqueTempDir()); |
169 FilePath metafile_path; | 171 FilePath metafile_path; |
170 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(), | 172 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(scratch_metafile_dir.path(), |
171 &metafile_path)); | 173 &metafile_path)); |
172 EXPECT_TRUE(emf.CreateFileBackedDc(hdc, &rect, metafile_path)); | 174 EXPECT_TRUE(emf->CreateFileBackedDc(hdc, &rect, metafile_path)); |
173 EXPECT_TRUE(emf.hdc() != NULL); | 175 EXPECT_TRUE(emf->hdc() != NULL); |
174 // In theory, you'd use the HDC with GDI functions here. | 176 // In theory, you'd use the HDC with GDI functions here. |
175 EXPECT_TRUE(emf.CloseDc()); | 177 EXPECT_TRUE(emf->CloseDc()); |
176 | 178 |
177 uint32 size = emf.GetDataSize(); | 179 uint32 size = emf->GetDataSize(); |
178 EXPECT_EQ(size, EMF_HEADER_SIZE); | 180 EXPECT_EQ(size, EMF_HEADER_SIZE); |
179 std::vector<BYTE> data; | 181 std::vector<BYTE> data; |
180 EXPECT_TRUE(emf.GetData(&data)); | 182 EXPECT_TRUE(emf->GetData(&data)); |
181 EXPECT_EQ(data.size(), size); | 183 EXPECT_EQ(data.size(), size); |
182 emf.CloseEmf(); | 184 emf->CloseEmf(); |
183 int64 file_size = 0; | 185 int64 file_size = 0; |
184 file_util::GetFileSize(metafile_path, &file_size); | 186 file_util::GetFileSize(metafile_path, &file_size); |
185 EXPECT_EQ(size, file_size); | 187 EXPECT_EQ(size, file_size); |
186 EXPECT_TRUE(DeleteDC(hdc)); | 188 EXPECT_TRUE(DeleteDC(hdc)); |
187 | 189 |
188 // Playback the data. | 190 // Playback the data. |
189 hdc = CreateCompatibleDC(NULL); | 191 hdc = CreateCompatibleDC(NULL); |
190 EXPECT_TRUE(hdc); | 192 EXPECT_TRUE(hdc); |
191 EXPECT_TRUE(emf.CreateFromFile(metafile_path)); | 193 EXPECT_TRUE(emf->CreateFromFile(metafile_path)); |
192 RECT output_rect = {0, 0, 10, 10}; | 194 RECT output_rect = {0, 0, 10, 10}; |
193 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); | 195 EXPECT_TRUE(emf->Playback(hdc, &output_rect)); |
194 EXPECT_TRUE(DeleteDC(hdc)); | 196 EXPECT_TRUE(DeleteDC(hdc)); |
195 emf.CloseEmf(); | 197 emf->CloseEmf(); |
196 } | 198 } |
197 | |
OLD | NEW |