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

Side by Side Diff: printing/backend/cups_helper_unittest.cc

Issue 1982883002: Use StringPiece in cups_helper.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/backend/cups_helper.cc ('k') | no next file » | 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) 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/backend/cups_helper.h" 5 #include "printing/backend/cups_helper.h"
6 #include "printing/backend/print_backend.h" 6 #include "printing/backend/print_backend.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexLongEdge) { 9 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexLongEdge) {
10 std::string test_ppd_data; 10 const char kTestPpdData[] =
11 test_ppd_data.append(
12 "*PPD-Adobe: \"4.3\"\n\n" 11 "*PPD-Adobe: \"4.3\"\n\n"
13 "*OpenGroup: General/General\n\n" 12 "*OpenGroup: General/General\n\n"
14 "*OpenUI *ColorModel/Color Model: PickOne\n" 13 "*OpenUI *ColorModel/Color Model: PickOne\n"
15 "*DefaultColorModel: Gray\n" 14 "*DefaultColorModel: Gray\n"
16 "*ColorModel Gray/Grayscale: \"" 15 "*ColorModel Gray/Grayscale: \""
17 "<</cupsColorSpace 0/cupsColorOrder 0>>" 16 "<</cupsColorSpace 0/cupsColorOrder 0>>"
18 "setpagedevice\"\n" 17 "setpagedevice\"\n"
19 "*ColorModel Black/Inverted Grayscale: \"" 18 "*ColorModel Black/Inverted Grayscale: \""
20 "<</cupsColorSpace 3/cupsColorOrder 0>>" 19 "<</cupsColorSpace 3/cupsColorOrder 0>>"
21 "setpagedevice\"\n" 20 "setpagedevice\"\n"
22 "*CloseUI: *ColorModel\n" 21 "*CloseUI: *ColorModel\n"
23 "*OpenUI *Duplex/2-Sided Printing: PickOne\n" 22 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
24 "*DefaultDuplex: DuplexTumble\n" 23 "*DefaultDuplex: DuplexTumble\n"
25 "*Duplex None/Off: \"<</Duplex false>>" 24 "*Duplex None/Off: \"<</Duplex false>>"
26 "setpagedevice\"\n" 25 "setpagedevice\"\n"
27 "*Duplex DuplexNoTumble/LongEdge: \"" 26 "*Duplex DuplexNoTumble/LongEdge: \""
28 "<</Duplex true/Tumble false>>setpagedevice\"\n" 27 "<</Duplex true/Tumble false>>setpagedevice\"\n"
29 "*Duplex DuplexTumble/ShortEdge: \"" 28 "*Duplex DuplexTumble/ShortEdge: \""
30 "<</Duplex true/Tumble true>>setpagedevice\"\n" 29 "<</Duplex true/Tumble true>>setpagedevice\"\n"
31 "*CloseUI: *Duplex\n\n" 30 "*CloseUI: *Duplex\n\n"
32 "*CloseGroup: General\n"); 31 "*CloseGroup: General\n";
33 32
34 printing::PrinterSemanticCapsAndDefaults caps; 33 printing::PrinterSemanticCapsAndDefaults caps;
35 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps)); 34 EXPECT_TRUE(printing::ParsePpdCapabilities("test", kTestPpdData, &caps));
36 EXPECT_TRUE(caps.collate_capable); 35 EXPECT_TRUE(caps.collate_capable);
37 EXPECT_TRUE(caps.collate_default); 36 EXPECT_TRUE(caps.collate_default);
38 EXPECT_TRUE(caps.copies_capable); 37 EXPECT_TRUE(caps.copies_capable);
39 EXPECT_TRUE(caps.duplex_capable); 38 EXPECT_TRUE(caps.duplex_capable);
40 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE); 39 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
41 EXPECT_FALSE(caps.color_changeable); 40 EXPECT_FALSE(caps.color_changeable);
42 EXPECT_FALSE(caps.color_default); 41 EXPECT_FALSE(caps.color_default);
43 } 42 }
44 43
45 // Test duplex detection code, which regressed in http://crbug.com/103999. 44 // Test duplex detection code, which regressed in http://crbug.com/103999.
46 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexSimples) { 45 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexSimples) {
47 std::string test_ppd_data; 46 const char kTestPpdData[] =
48 test_ppd_data.append(
49 "*PPD-Adobe: \"4.3\"\n\n" 47 "*PPD-Adobe: \"4.3\"\n\n"
50 "*OpenGroup: General/General\n\n" 48 "*OpenGroup: General/General\n\n"
51 "*OpenUI *Duplex/Double-Sided Printing: PickOne\n" 49 "*OpenUI *Duplex/Double-Sided Printing: PickOne\n"
52 "*DefaultDuplex: None\n" 50 "*DefaultDuplex: None\n"
53 "*Duplex None/Off: " 51 "*Duplex None/Off: "
54 "\"<</Duplex false>>setpagedevice\"\n" 52 "\"<</Duplex false>>setpagedevice\"\n"
55 "*Duplex DuplexNoTumble/Long Edge (Standard): " 53 "*Duplex DuplexNoTumble/Long Edge (Standard): "
56 "\"<</Duplex true/Tumble false>>setpagedevice\"\n" 54 "\"<</Duplex true/Tumble false>>setpagedevice\"\n"
57 "*Duplex DuplexTumble/Short Edge (Flip): " 55 "*Duplex DuplexTumble/Short Edge (Flip): "
58 "\"<</Duplex true/Tumble true>>setpagedevice\"\n" 56 "\"<</Duplex true/Tumble true>>setpagedevice\"\n"
59 "*CloseUI: *Duplex\n\n" 57 "*CloseUI: *Duplex\n\n"
60 "*CloseGroup: General\n"); 58 "*CloseGroup: General\n";
61 59
62 printing::PrinterSemanticCapsAndDefaults caps; 60 printing::PrinterSemanticCapsAndDefaults caps;
63 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps)); 61 EXPECT_TRUE(printing::ParsePpdCapabilities("test", kTestPpdData, &caps));
64 EXPECT_TRUE(caps.collate_capable); 62 EXPECT_TRUE(caps.collate_capable);
65 EXPECT_TRUE(caps.collate_default); 63 EXPECT_TRUE(caps.collate_default);
66 EXPECT_TRUE(caps.copies_capable); 64 EXPECT_TRUE(caps.copies_capable);
67 EXPECT_TRUE(caps.duplex_capable); 65 EXPECT_TRUE(caps.duplex_capable);
68 EXPECT_EQ(caps.duplex_default, printing::SIMPLEX); 66 EXPECT_EQ(caps.duplex_default, printing::SIMPLEX);
69 EXPECT_FALSE(caps.color_changeable); 67 EXPECT_FALSE(caps.color_changeable);
70 EXPECT_FALSE(caps.color_default); 68 EXPECT_FALSE(caps.color_default);
71 } 69 }
72 70
73 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorNoDuplex) { 71 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorNoDuplex) {
74 std::string test_ppd_data; 72 const char kTestPpdData[] =
75 test_ppd_data.append(
76 "*PPD-Adobe: \"4.3\"\n\n" 73 "*PPD-Adobe: \"4.3\"\n\n"
77 "*OpenGroup: General/General\n\n" 74 "*OpenGroup: General/General\n\n"
78 "*OpenUI *ColorModel/Color Model: PickOne\n" 75 "*OpenUI *ColorModel/Color Model: PickOne\n"
79 "*DefaultColorModel: Gray\n" 76 "*DefaultColorModel: Gray\n"
80 "*ColorModel Gray/Grayscale: \"" 77 "*ColorModel Gray/Grayscale: \""
81 "<</cupsColorSpace 0/cupsColorOrder 0>>" 78 "<</cupsColorSpace 0/cupsColorOrder 0>>"
82 "setpagedevice\"\n" 79 "setpagedevice\"\n"
83 "*ColorModel Black/Inverted Grayscale: \"" 80 "*ColorModel Black/Inverted Grayscale: \""
84 "<</cupsColorSpace 3/cupsColorOrder 0>>" 81 "<</cupsColorSpace 3/cupsColorOrder 0>>"
85 "setpagedevice\"\n" 82 "setpagedevice\"\n"
86 "*CloseUI: *ColorModel\n" 83 "*CloseUI: *ColorModel\n"
87 "*CloseGroup: General\n"); 84 "*CloseGroup: General\n";
88 85
89 printing::PrinterSemanticCapsAndDefaults caps; 86 printing::PrinterSemanticCapsAndDefaults caps;
90 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps)); 87 EXPECT_TRUE(printing::ParsePpdCapabilities("test", kTestPpdData, &caps));
91 EXPECT_TRUE(caps.collate_capable); 88 EXPECT_TRUE(caps.collate_capable);
92 EXPECT_TRUE(caps.collate_default); 89 EXPECT_TRUE(caps.collate_default);
93 EXPECT_TRUE(caps.copies_capable); 90 EXPECT_TRUE(caps.copies_capable);
94 EXPECT_FALSE(caps.duplex_capable); 91 EXPECT_FALSE(caps.duplex_capable);
95 EXPECT_EQ(caps.duplex_default, printing::UNKNOWN_DUPLEX_MODE); 92 EXPECT_EQ(caps.duplex_default, printing::UNKNOWN_DUPLEX_MODE);
96 EXPECT_FALSE(caps.color_changeable); 93 EXPECT_FALSE(caps.color_changeable);
97 EXPECT_FALSE(caps.color_default); 94 EXPECT_FALSE(caps.color_default);
98 } 95 }
99 96
100 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorTrueDuplexLongEdge) { 97 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorTrueDuplexLongEdge) {
101 std::string test_ppd_data; 98 const char kTestPpdData[] =
102 test_ppd_data.append(
103 "*PPD-Adobe: \"4.3\"\n\n" 99 "*PPD-Adobe: \"4.3\"\n\n"
104 "*ColorDevice: True\n" 100 "*ColorDevice: True\n"
105 "*DefaultColorSpace: CMYK\n\n" 101 "*DefaultColorSpace: CMYK\n\n"
106 "*OpenGroup: General/General\n\n" 102 "*OpenGroup: General/General\n\n"
107 "*OpenUI *ColorModel/Color Model: PickOne\n" 103 "*OpenUI *ColorModel/Color Model: PickOne\n"
108 "*DefaultColorModel: CMYK\n" 104 "*DefaultColorModel: CMYK\n"
109 "*ColorModel CMYK/Color: " 105 "*ColorModel CMYK/Color: "
110 "\"(cmyk) RCsetdevicecolor\"\n" 106 "\"(cmyk) RCsetdevicecolor\"\n"
111 "*ColorModel Gray/Black and White: " 107 "*ColorModel Gray/Black and White: "
112 "\"(gray) RCsetdevicecolor\"\n" 108 "\"(gray) RCsetdevicecolor\"\n"
113 "*CloseUI: *ColorModel\n" 109 "*CloseUI: *ColorModel\n"
114 "*OpenUI *Duplex/2-Sided Printing: PickOne\n" 110 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
115 "*DefaultDuplex: DuplexTumble\n" 111 "*DefaultDuplex: DuplexTumble\n"
116 "*Duplex None/Off: \"<</Duplex false>>" 112 "*Duplex None/Off: \"<</Duplex false>>"
117 "setpagedevice\"\n" 113 "setpagedevice\"\n"
118 "*Duplex DuplexNoTumble/LongEdge: \"" 114 "*Duplex DuplexNoTumble/LongEdge: \""
119 "<</Duplex true/Tumble false>>setpagedevice\"\n" 115 "<</Duplex true/Tumble false>>setpagedevice\"\n"
120 "*Duplex DuplexTumble/ShortEdge: \"" 116 "*Duplex DuplexTumble/ShortEdge: \""
121 "<</Duplex true/Tumble true>>setpagedevice\"\n" 117 "<</Duplex true/Tumble true>>setpagedevice\"\n"
122 "*CloseUI: *Duplex\n\n" 118 "*CloseUI: *Duplex\n\n"
123 "*CloseGroup: General\n"); 119 "*CloseGroup: General\n";
124 120
125 printing::PrinterSemanticCapsAndDefaults caps; 121 printing::PrinterSemanticCapsAndDefaults caps;
126 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps)); 122 EXPECT_TRUE(printing::ParsePpdCapabilities("test", kTestPpdData, &caps));
127 EXPECT_TRUE(caps.collate_capable); 123 EXPECT_TRUE(caps.collate_capable);
128 EXPECT_TRUE(caps.collate_default); 124 EXPECT_TRUE(caps.collate_default);
129 EXPECT_TRUE(caps.copies_capable); 125 EXPECT_TRUE(caps.copies_capable);
130 EXPECT_TRUE(caps.duplex_capable); 126 EXPECT_TRUE(caps.duplex_capable);
131 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE); 127 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
132 EXPECT_TRUE(caps.color_changeable); 128 EXPECT_TRUE(caps.color_changeable);
133 EXPECT_TRUE(caps.color_default); 129 EXPECT_TRUE(caps.color_default);
134 } 130 }
135 131
136 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorFalseDuplexLongEdge) { 132 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorFalseDuplexLongEdge) {
137 std::string test_ppd_data; 133 const char kTestPpdData[] =
138 test_ppd_data.append(
139 "*PPD-Adobe: \"4.3\"\n\n" 134 "*PPD-Adobe: \"4.3\"\n\n"
140 "*ColorDevice: True\n" 135 "*ColorDevice: True\n"
141 "*DefaultColorSpace: CMYK\n\n" 136 "*DefaultColorSpace: CMYK\n\n"
142 "*OpenGroup: General/General\n\n" 137 "*OpenGroup: General/General\n\n"
143 "*OpenUI *ColorModel/Color Model: PickOne\n" 138 "*OpenUI *ColorModel/Color Model: PickOne\n"
144 "*DefaultColorModel: Grayscale\n" 139 "*DefaultColorModel: Grayscale\n"
145 "*ColorModel Color/Color: " 140 "*ColorModel Color/Color: "
146 "\"%% FoomaticRIPOptionSetting: ColorModel=Color\"\n" 141 "\"%% FoomaticRIPOptionSetting: ColorModel=Color\"\n"
147 "*FoomaticRIPOptionSetting ColorModel=Color: " 142 "*FoomaticRIPOptionSetting ColorModel=Color: "
148 "\"JCLDatamode=Color GSCmdLine=Color\"\n" 143 "\"JCLDatamode=Color GSCmdLine=Color\"\n"
149 "*ColorModel Grayscale/Grayscale: " 144 "*ColorModel Grayscale/Grayscale: "
150 "\"%% FoomaticRIPOptionSetting: ColorModel=Grayscale\"\n" 145 "\"%% FoomaticRIPOptionSetting: ColorModel=Grayscale\"\n"
151 "*FoomaticRIPOptionSetting ColorModel=Grayscale: " 146 "*FoomaticRIPOptionSetting ColorModel=Grayscale: "
152 "\"JCLDatamode=Grayscale GSCmdLine=Grayscale\"\n" 147 "\"JCLDatamode=Grayscale GSCmdLine=Grayscale\"\n"
153 "*CloseUI: *ColorModel\n" 148 "*CloseUI: *ColorModel\n"
154 "*OpenUI *Duplex/2-Sided Printing: PickOne\n" 149 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
155 "*DefaultDuplex: DuplexTumble\n" 150 "*DefaultDuplex: DuplexTumble\n"
156 "*Duplex None/Off: \"<</Duplex false>>" 151 "*Duplex None/Off: \"<</Duplex false>>"
157 "setpagedevice\"\n" 152 "setpagedevice\"\n"
158 "*Duplex DuplexNoTumble/LongEdge: \"" 153 "*Duplex DuplexNoTumble/LongEdge: \""
159 "<</Duplex true/Tumble false>>setpagedevice\"\n" 154 "<</Duplex true/Tumble false>>setpagedevice\"\n"
160 "*Duplex DuplexTumble/ShortEdge: \"" 155 "*Duplex DuplexTumble/ShortEdge: \""
161 "<</Duplex true/Tumble true>>setpagedevice\"\n" 156 "<</Duplex true/Tumble true>>setpagedevice\"\n"
162 "*CloseUI: *Duplex\n\n" 157 "*CloseUI: *Duplex\n\n"
163 "*CloseGroup: General\n"); 158 "*CloseGroup: General\n";
164 159
165 printing::PrinterSemanticCapsAndDefaults caps; 160 printing::PrinterSemanticCapsAndDefaults caps;
166 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps)); 161 EXPECT_TRUE(printing::ParsePpdCapabilities("test", kTestPpdData, &caps));
167 EXPECT_TRUE(caps.collate_capable); 162 EXPECT_TRUE(caps.collate_capable);
168 EXPECT_TRUE(caps.collate_default); 163 EXPECT_TRUE(caps.collate_default);
169 EXPECT_TRUE(caps.copies_capable); 164 EXPECT_TRUE(caps.copies_capable);
170 EXPECT_TRUE(caps.duplex_capable); 165 EXPECT_TRUE(caps.duplex_capable);
171 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE); 166 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
172 EXPECT_TRUE(caps.color_changeable); 167 EXPECT_TRUE(caps.color_changeable);
173 EXPECT_FALSE(caps.color_default); 168 EXPECT_FALSE(caps.color_default);
174 } 169 }
175 170
176 TEST(PrintBackendCupsHelperTest, TestPpdParsingPageSize) { 171 TEST(PrintBackendCupsHelperTest, TestPpdParsingPageSize) {
177 std::string test_ppd_data; 172 const char kTestPpdData[] =
178 test_ppd_data.append(
179 "*PPD-Adobe: \"4.3\"\n\n" 173 "*PPD-Adobe: \"4.3\"\n\n"
180 "*OpenUI *PageSize: PickOne\n" 174 "*OpenUI *PageSize: PickOne\n"
181 "*OrderDependency: 30 AnySetup *PageSize\n" 175 "*OrderDependency: 30 AnySetup *PageSize\n"
182 "*DefaultPageSize: Letter\n" 176 "*DefaultPageSize: Letter\n"
183 "*PageSize Letter/US Letter: \"" 177 "*PageSize Letter/US Letter: \""
184 " <</DeferredMediaSelection true /PageSize [612 792] " 178 " <</DeferredMediaSelection true /PageSize [612 792] "
185 " /ImagingBBox null /MediaClass null >> setpagedevice\"\n" 179 " /ImagingBBox null /MediaClass null >> setpagedevice\"\n"
186 "*End\n" 180 "*End\n"
187 "*PageSize Legal/US Legal: \"" 181 "*PageSize Legal/US Legal: \""
188 " <</DeferredMediaSelection true /PageSize [612 1008] " 182 " <</DeferredMediaSelection true /PageSize [612 1008] "
189 " /ImagingBBox null /MediaClass null >> setpagedevice\"\n" 183 " /ImagingBBox null /MediaClass null >> setpagedevice\"\n"
190 "*End\n" 184 "*End\n"
191 "*DefaultPaperDimension: Letter\n" 185 "*DefaultPaperDimension: Letter\n"
192 "*PaperDimension Letter/US Letter: \"612 792\"\n" 186 "*PaperDimension Letter/US Letter: \"612 792\"\n"
193 "*PaperDimension Legal/US Legal: \"612 1008\"\n\n" 187 "*PaperDimension Legal/US Legal: \"612 1008\"\n\n"
194 "*CloseUI: *PageSize\n\n"); 188 "*CloseUI: *PageSize\n\n";
195 189
196 printing::PrinterSemanticCapsAndDefaults caps; 190 printing::PrinterSemanticCapsAndDefaults caps;
197 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps)); 191 EXPECT_TRUE(printing::ParsePpdCapabilities("test", kTestPpdData, &caps));
198 ASSERT_EQ(2UL, caps.papers.size()); 192 ASSERT_EQ(2UL, caps.papers.size());
199 EXPECT_EQ("Letter", caps.papers[0].vendor_id); 193 EXPECT_EQ("Letter", caps.papers[0].vendor_id);
200 EXPECT_EQ("US Letter", caps.papers[0].display_name); 194 EXPECT_EQ("US Letter", caps.papers[0].display_name);
201 EXPECT_EQ(215900, caps.papers[0].size_um.width()); 195 EXPECT_EQ(215900, caps.papers[0].size_um.width());
202 EXPECT_EQ(279400, caps.papers[0].size_um.height()); 196 EXPECT_EQ(279400, caps.papers[0].size_um.height());
203 EXPECT_EQ("Legal", caps.papers[1].vendor_id); 197 EXPECT_EQ("Legal", caps.papers[1].vendor_id);
204 EXPECT_EQ("US Legal", caps.papers[1].display_name); 198 EXPECT_EQ("US Legal", caps.papers[1].display_name);
205 EXPECT_EQ(215900, caps.papers[1].size_um.width()); 199 EXPECT_EQ(215900, caps.papers[1].size_um.width());
206 EXPECT_EQ(355600, caps.papers[1].size_um.height()); 200 EXPECT_EQ(355600, caps.papers[1].size_um.height());
207 } 201 }
OLDNEW
« no previous file with comments | « printing/backend/cups_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698