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

Side by Side Diff: printing/emf_win_unittest.cc

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed styling issues (naming, 80cols) Created 9 years, 10 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
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
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/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;
28 static bool IsTestCaseDisabled() { 29 static bool IsTestCaseDisabled() {
29 // It is assumed this printer is a HP Color LaserJet 4550 PCL or 4700. 30 // It is assumed this printer is a HP Color LaserJet 4550 PCL or 4700.
30 HDC hdc = CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL); 31 HDC hdc = CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL);
31 if (!hdc) 32 if (!hdc)
32 return true; 33 return true;
33 DeleteDC(hdc); 34 DeleteDC(hdc);
34 return false; 35 return false;
35 } 36 }
36 }; 37 };
37 38
38 const uint32 EMF_HEADER_SIZE = 128; 39 const uint32 EMF_HEADER_SIZE = 128;
39 40
40 } // namespace 41 } // namespace
41 42
42 TEST(EmfTest, DC) { 43 TEST(EmfTest, DC) {
43 // Simplest use case. 44 // Simplest use case.
44 printing::Emf emf; 45 printing::Emf emf;
vandebo (ex-Chrome) 2011/02/22 22:18:16 I know you haven't build windows yet, but it looks
45 RECT rect = {100, 100, 200, 200}; 46 RECT rect = {100, 100, 200, 200};
46 HDC hdc = CreateCompatibleDC(NULL); 47 HDC hdc = CreateCompatibleDC(NULL);
47 EXPECT_TRUE(hdc != NULL); 48 EXPECT_TRUE(hdc != NULL);
48 EXPECT_TRUE(emf.CreateDc(hdc, &rect)); 49 EXPECT_TRUE(emf.CreateDc(hdc, &rect));
49 EXPECT_TRUE(emf.hdc() != NULL); 50 EXPECT_TRUE(emf.hdc() != NULL);
50 // In theory, you'd use the HDC with GDI functions here. 51 // In theory, you'd use the HDC with GDI functions here.
51 EXPECT_TRUE(emf.CloseDc()); 52 EXPECT_TRUE(emf.CloseDc());
52 uint32 size = emf.GetDataSize(); 53 uint32 size = emf.GetDataSize();
53 EXPECT_EQ(size, EMF_HEADER_SIZE); 54 EXPECT_EQ(size, EMF_HEADER_SIZE);
54 std::vector<BYTE> data; 55 std::vector<BYTE> data;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // Playback the data. 189 // Playback the data.
189 hdc = CreateCompatibleDC(NULL); 190 hdc = CreateCompatibleDC(NULL);
190 EXPECT_TRUE(hdc); 191 EXPECT_TRUE(hdc);
191 EXPECT_TRUE(emf.CreateFromFile(metafile_path)); 192 EXPECT_TRUE(emf.CreateFromFile(metafile_path));
192 RECT output_rect = {0, 0, 10, 10}; 193 RECT output_rect = {0, 0, 10, 10};
193 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); 194 EXPECT_TRUE(emf.Playback(hdc, &output_rect));
194 EXPECT_TRUE(DeleteDC(hdc)); 195 EXPECT_TRUE(DeleteDC(hdc));
195 emf.CloseEmf(); 196 emf.CloseEmf();
196 } 197 }
197 198
199 TEST(EmfTest, DCFactory) {
vandebo (ex-Chrome) 2011/02/22 22:18:16 Maybe put this next to DC. You could pull out the
dpapad 2011/02/23 00:44:39 The unit test is basically identical, only the ini
200 // Simplest use case.
201 scoped_ptr<printing::NativeMetafile> emf(
202 printing::MetafileFactory::GetMetafile());
203 RECT rect = {100, 100, 200, 200};
204 HDC hdc = CreateCompatibleDC(NULL);
205 EXPECT_TRUE(hdc != NULL);
206 EXPECT_TRUE(emf->CreateDc(hdc, &rect));
207 EXPECT_TRUE(emf->hdc() != NULL);
208 // In theory, you'd use the HDC with GDI functions here.
209 EXPECT_TRUE(emf->CloseDc());
210 uint32 size = emf->GetDataSize();
211 EXPECT_EQ(size, EMF_HEADER_SIZE);
212 std::vector<BYTE> data;
213 EXPECT_TRUE(emf->GetData(&data));
214 EXPECT_EQ(data.size(), size);
215 emf->CloseEmf();
216 EXPECT_TRUE(DeleteDC(hdc));
217
218 // Playback the data.
219 hdc = CreateCompatibleDC(NULL);
220 EXPECT_TRUE(hdc);
221 EXPECT_TRUE(emf>Init(&data.front(), size));
222 RECT output_rect = {0, 0, 10, 10};
223 EXPECT_TRUE(emf->Playback(hdc, &output_rect));
224 EXPECT_TRUE(DeleteDC(hdc));
225 }
226
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698