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

Side by Side Diff: printing/printing_context_win_unittest.cc

Issue 3610013: Printing: Convert PrintingContext into an interface implemented by the separate (Closed)
Patch Set: Comment cleanup only. Created 10 years, 2 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
« no previous file with comments | « printing/printing_context_win.cc ('k') | printing/printing_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <ocidl.h>
6 #include <commdlg.h>
7
8 #include <string>
9
10 #include "base/scoped_ptr.h"
11 #include "printing/printing_test.h"
5 #include "printing/printing_context.h" 12 #include "printing/printing_context.h"
6 13 #include "printing/printing_context_win.h"
7 #include "printing/printing_test.h"
8 #include "printing/print_settings.h" 14 #include "printing/print_settings.h"
9 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
10 16
11 // This test is automatically disabled if no printer is available. 17 // This test is automatically disabled if no printer is available.
12 class PrintingContextTest : public PrintingTest<testing::Test> { 18 class PrintingContextTest : public PrintingTest<testing::Test> {
13 public: 19 public:
14 void PrintSettingsCallback(printing::PrintingContext::Result result) { 20 void PrintSettingsCallback(printing::PrintingContext::Result result) {
15 result_ = result; 21 result_ = result;
16 } 22 }
17 23
(...skipping 21 matching lines...) Expand all
39 // Painful paperwork. 45 // Painful paperwork.
40 std::wstring printer_name = PrintingContextTest::GetDefaultPrinter(); 46 std::wstring printer_name = PrintingContextTest::GetDefaultPrinter();
41 HANDLE printer; 47 HANDLE printer;
42 if (!OpenPrinter(const_cast<wchar_t*>(printer_name.c_str()), &printer, NULL)) 48 if (!OpenPrinter(const_cast<wchar_t*>(printer_name.c_str()), &printer, NULL))
43 return E_FAIL; 49 return E_FAIL;
44 50
45 scoped_array<uint8> buffer; 51 scoped_array<uint8> buffer;
46 DEVMODE* dev_mode = NULL; 52 DEVMODE* dev_mode = NULL;
47 PRINTER_INFO_2* info_2 = NULL; 53 PRINTER_INFO_2* info_2 = NULL;
48 54
49 printing::PrintingContext::GetPrinterHelper(printer, 2, &buffer); 55 printing::PrintingContextWin::GetPrinterHelper(printer, 2, &buffer);
50 if (buffer.get()) { 56 if (buffer.get()) {
51 info_2 = reinterpret_cast<PRINTER_INFO_2*>(buffer.get()); 57 info_2 = reinterpret_cast<PRINTER_INFO_2*>(buffer.get());
52 if (info_2->pDevMode != NULL) 58 if (info_2->pDevMode != NULL)
53 dev_mode = info_2->pDevMode; 59 dev_mode = info_2->pDevMode;
54 } 60 }
55 if (!dev_mode) 61 if (!dev_mode)
56 return E_FAIL; 62 return E_FAIL;
57 63
58 if (!printing::PrintingContext::AllocateContext(printer_name, dev_mode, 64 if (!printing::PrintingContextWin::AllocateContext(printer_name, dev_mode,
59 &lppd->hDC)) { 65 &lppd->hDC)) {
60 return E_FAIL; 66 return E_FAIL;
61 } 67 }
62 68
63 size_t dev_mode_size = dev_mode->dmSize + dev_mode->dmDriverExtra; 69 size_t dev_mode_size = dev_mode->dmSize + dev_mode->dmDriverExtra;
64 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, dev_mode_size); 70 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, dev_mode_size);
65 if (!lppd->hDevMode) 71 if (!lppd->hDevMode)
66 return E_FAIL; 72 return E_FAIL;
67 void* dev_mode_ptr = GlobalLock(lppd->hDevMode); 73 void* dev_mode_ptr = GlobalLock(lppd->hDevMode);
68 if (!dev_mode_ptr) 74 if (!dev_mode_ptr)
(...skipping 26 matching lines...) Expand all
95 GlobalUnlock(lppd->hDevNames); 101 GlobalUnlock(lppd->hDevNames);
96 102
97 return S_OK; 103 return S_OK;
98 } 104 }
99 105
100 TEST_F(PrintingContextTest, Base) { 106 TEST_F(PrintingContextTest, Base) {
101 printing::PrintSettings settings; 107 printing::PrintSettings settings;
102 108
103 settings.set_device_name(GetDefaultPrinter()); 109 settings.set_device_name(GetDefaultPrinter());
104 // Initialize it. 110 // Initialize it.
105 printing::PrintingContext context; 111 scoped_ptr<printing::PrintingContext> context(
106 EXPECT_EQ(printing::PrintingContext::OK, context.InitWithSettings(settings)); 112 printing::PrintingContext::Create());
113 EXPECT_EQ(printing::PrintingContext::OK, context->InitWithSettings(settings));
107 114
108 // The print may lie to use and may not support world transformation. 115 // The print may lie to use and may not support world transformation.
109 // Verify right now. 116 // Verify right now.
110 XFORM random_matrix = { 1, 0.1f, 0, 1.5f, 0, 1 }; 117 XFORM random_matrix = { 1, 0.1f, 0, 1.5f, 0, 1 };
111 EXPECT_TRUE(SetWorldTransform(context.context(), &random_matrix)); 118 EXPECT_TRUE(SetWorldTransform(context->context(), &random_matrix));
112 EXPECT_TRUE(ModifyWorldTransform(context.context(), NULL, MWT_IDENTITY)); 119 EXPECT_TRUE(ModifyWorldTransform(context->context(), NULL, MWT_IDENTITY));
113 } 120 }
114 121
115 TEST_F(PrintingContextTest, PrintAll) { 122 TEST_F(PrintingContextTest, PrintAll) {
116 printing::PrintingContext context; 123 printing::PrintingContextWin context;
117 context.SetPrintDialog(&PrintDlgExMock); 124 context.SetPrintDialog(&PrintDlgExMock);
118 context.AskUserForSettings( 125 context.AskUserForSettings(
119 NULL, 126 NULL,
120 123, 127 123,
121 false, 128 false,
122 NewCallback(static_cast<PrintingContextTest*>(this), 129 NewCallback(static_cast<PrintingContextTest*>(this),
123 &PrintingContextTest::PrintSettingsCallback)); 130 &PrintingContextTest::PrintSettingsCallback));
124 ASSERT_EQ(printing::PrintingContext::OK, result()); 131 ASSERT_EQ(printing::PrintingContext::OK, result());
125 printing::PrintSettings settings = context.settings(); 132 printing::PrintSettings settings = context.settings();
126 EXPECT_EQ(settings.ranges.size(), 0); 133 EXPECT_EQ(settings.ranges.size(), 0);
127 } 134 }
OLDNEW
« no previous file with comments | « printing/printing_context_win.cc ('k') | printing/printing_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698