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 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/win/scoped_hdc.h" | 19 #include "base/win/scoped_hdc.h" |
20 #include "printing/printing_context.h" | 20 #include "printing/printing_context.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
23 #include "ui/gfx/size.h" | 23 #include "ui/gfx/size.h" |
24 | 24 |
25 namespace printing { | |
26 | |
27 namespace { | 25 namespace { |
28 | 26 |
29 // This test is automatically disabled if no printer named "UnitTest Printer" is | 27 // This test is automatically disabled if no printer named "UnitTest Printer" is |
30 // available. | 28 // available. |
31 class EmfPrintingTest : public testing::Test, public PrintingContext::Delegate { | 29 class EmfPrintingTest : public testing::Test { |
32 public: | 30 public: |
33 typedef testing::Test Parent; | 31 typedef testing::Test Parent; |
34 static bool IsTestCaseDisabled() { | 32 static bool IsTestCaseDisabled() { |
35 // It is assumed this printer is a HP Color LaserJet 4550 PCL or 4700. | 33 // It is assumed this printer is a HP Color LaserJet 4550 PCL or 4700. |
36 HDC hdc = CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL); | 34 HDC hdc = CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL); |
37 if (!hdc) | 35 if (!hdc) |
38 return true; | 36 return true; |
39 DeleteDC(hdc); | 37 DeleteDC(hdc); |
40 return false; | 38 return false; |
41 } | 39 } |
42 | |
43 // PrintingContext::Delegate methods. | |
44 virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; } | |
45 virtual std::string GetAppLocale() OVERRIDE { return std::string(); } | |
46 }; | 40 }; |
47 | 41 |
48 const uint32 EMF_HEADER_SIZE = 128; | 42 const uint32 EMF_HEADER_SIZE = 128; |
49 | 43 |
50 } // namespace | 44 } // namespace |
51 | 45 |
| 46 namespace printing { |
| 47 |
52 TEST(EmfTest, DC) { | 48 TEST(EmfTest, DC) { |
53 // Simplest use case. | 49 // Simplest use case. |
54 uint32 size; | 50 uint32 size; |
55 std::vector<BYTE> data; | 51 std::vector<BYTE> data; |
56 { | 52 { |
57 Emf emf; | 53 Emf emf; |
58 EXPECT_TRUE(emf.Init()); | 54 EXPECT_TRUE(emf.Init()); |
59 EXPECT_TRUE(emf.context() != NULL); | 55 EXPECT_TRUE(emf.context() != NULL); |
60 // An empty EMF is invalid, so we put at least a rectangle in it. | 56 // An empty EMF is invalid, so we put at least a rectangle in it. |
61 ::Rectangle(emf.context(), 10, 10, 190, 190); | 57 ::Rectangle(emf.context(), 10, 10, 190, 190); |
(...skipping 18 matching lines...) Expand all Loading... |
80 TEST_F(EmfPrintingTest, Enumerate) { | 76 TEST_F(EmfPrintingTest, Enumerate) { |
81 if (IsTestCaseDisabled()) | 77 if (IsTestCaseDisabled()) |
82 return; | 78 return; |
83 | 79 |
84 PrintSettings settings; | 80 PrintSettings settings; |
85 | 81 |
86 // My test case is a HP Color LaserJet 4550 PCL. | 82 // My test case is a HP Color LaserJet 4550 PCL. |
87 settings.set_device_name(L"UnitTest Printer"); | 83 settings.set_device_name(L"UnitTest Printer"); |
88 | 84 |
89 // Initialize it. | 85 // Initialize it. |
90 scoped_ptr<PrintingContext> context(PrintingContext::Create(this)); | 86 scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); |
91 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); | 87 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); |
92 | 88 |
93 base::FilePath emf_file; | 89 base::FilePath emf_file; |
94 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); | 90 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); |
95 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) | 91 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) |
96 .Append(FILE_PATH_LITERAL("test")) | 92 .Append(FILE_PATH_LITERAL("test")) |
97 .Append(FILE_PATH_LITERAL("data")) | 93 .Append(FILE_PATH_LITERAL("data")) |
98 .Append(FILE_PATH_LITERAL("test4.emf")); | 94 .Append(FILE_PATH_LITERAL("test4.emf")); |
99 // Load any EMF with an image. | 95 // Load any EMF with an image. |
100 Emf emf; | 96 Emf emf; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 221 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
226 | 222 |
227 raster.reset(emf.RasterizeMetafile(16*1024*1024)); | 223 raster.reset(emf.RasterizeMetafile(16*1024*1024)); |
228 // Expected size about 64MB. | 224 // Expected size about 64MB. |
229 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); | 225 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); |
230 // Bounds should still be the same. | 226 // Bounds should still be the same. |
231 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); | 227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); |
232 } | 228 } |
233 | 229 |
234 } // namespace printing | 230 } // namespace printing |
OLD | NEW |