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 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 " index: " << index << " type: " << itr->record()->iType; | 120 " index: " << index << " type: " << itr->record()->iType; |
121 } | 121 } |
122 context->PageDone(); | 122 context->PageDone(); |
123 context->DocumentDone(); | 123 context->DocumentDone(); |
124 } | 124 } |
125 | 125 |
126 // Disabled if no "UnitTest printer" exists. | 126 // Disabled if no "UnitTest printer" exists. |
127 TEST_F(EmfPrintingTest, PageBreak) { | 127 TEST_F(EmfPrintingTest, PageBreak) { |
128 base::win::ScopedCreateDC dc( | 128 base::win::ScopedCreateDC dc( |
129 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); | 129 CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL)); |
130 if (!dc.Get()) | 130 if (!dc.get()) |
131 return; | 131 return; |
132 uint32 size; | 132 uint32 size; |
133 std::vector<BYTE> data; | 133 std::vector<BYTE> data; |
134 { | 134 { |
135 Emf emf; | 135 Emf emf; |
136 EXPECT_TRUE(emf.Init()); | 136 EXPECT_TRUE(emf.Init()); |
137 EXPECT_TRUE(emf.context() != NULL); | 137 EXPECT_TRUE(emf.context() != NULL); |
138 int pages = 3; | 138 int pages = 3; |
139 while (pages) { | 139 while (pages) { |
140 EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1)); | 140 EXPECT_TRUE(emf.StartPage(gfx::Size(), gfx::Rect(), 1)); |
141 ::Rectangle(emf.context(), 10, 10, 190, 190); | 141 ::Rectangle(emf.context(), 10, 10, 190, 190); |
142 EXPECT_TRUE(emf.FinishPage()); | 142 EXPECT_TRUE(emf.FinishPage()); |
143 --pages; | 143 --pages; |
144 } | 144 } |
145 EXPECT_EQ(3U, emf.GetPageCount()); | 145 EXPECT_EQ(3U, emf.GetPageCount()); |
146 EXPECT_TRUE(emf.FinishDocument()); | 146 EXPECT_TRUE(emf.FinishDocument()); |
147 size = emf.GetDataSize(); | 147 size = emf.GetDataSize(); |
148 EXPECT_TRUE(emf.GetDataAsVector(&data)); | 148 EXPECT_TRUE(emf.GetDataAsVector(&data)); |
149 EXPECT_EQ(data.size(), size); | 149 EXPECT_EQ(data.size(), size); |
150 } | 150 } |
151 | 151 |
152 // Playback the data. | 152 // Playback the data. |
153 DOCINFO di = {0}; | 153 DOCINFO di = {0}; |
154 di.cbSize = sizeof(DOCINFO); | 154 di.cbSize = sizeof(DOCINFO); |
155 di.lpszDocName = L"Test Job"; | 155 di.lpszDocName = L"Test Job"; |
156 int job_id = ::StartDoc(dc.Get(), &di); | 156 int job_id = ::StartDoc(dc.get(), &di); |
157 Emf emf; | 157 Emf emf; |
158 EXPECT_TRUE(emf.InitFromData(&data.front(), size)); | 158 EXPECT_TRUE(emf.InitFromData(&data.front(), size)); |
159 EXPECT_TRUE(emf.SafePlayback(dc.Get())); | 159 EXPECT_TRUE(emf.SafePlayback(dc.get())); |
160 ::EndDoc(dc.Get()); | 160 ::EndDoc(dc.get()); |
161 // Since presumably the printer is not real, let us just delete the job from | 161 // Since presumably the printer is not real, let us just delete the job from |
162 // the queue. | 162 // the queue. |
163 HANDLE printer = NULL; | 163 HANDLE printer = NULL; |
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) { |
(...skipping 25 matching lines...) Expand all Loading... |
196 HDC hdc = CreateCompatibleDC(NULL); | 196 HDC hdc = CreateCompatibleDC(NULL); |
197 EXPECT_TRUE(hdc); | 197 EXPECT_TRUE(hdc); |
198 Emf emf; | 198 Emf emf; |
199 EXPECT_TRUE(emf.InitFromFile(metafile_path)); | 199 EXPECT_TRUE(emf.InitFromFile(metafile_path)); |
200 RECT output_rect = {0, 0, 10, 10}; | 200 RECT output_rect = {0, 0, 10, 10}; |
201 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); | 201 EXPECT_TRUE(emf.Playback(hdc, &output_rect)); |
202 EXPECT_TRUE(DeleteDC(hdc)); | 202 EXPECT_TRUE(DeleteDC(hdc)); |
203 } | 203 } |
204 | 204 |
205 } // namespace printing | 205 } // namespace printing |
OLD | NEW |