summaryrefslogtreecommitdiffstats
path: root/printing/backend/cups_helper_unittest.cc
blob: d83b3b77dca183cdc23ccc122a70076b6d1c4358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "printing/backend/cups_helper.h"
#include "printing/backend/print_backend.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexLongEdge) {
  std::string test_ppd_data;
  test_ppd_data.append(
      "*PPD-Adobe: \"4.3\"\n\n"
      "*OpenGroup: General/General\n\n"
      "*OpenUI *ColorModel/Color Model: PickOne\n"
      "*DefaultColorModel: Gray\n"
      "*ColorModel Gray/Grayscale: \""
      "<</cupsColorSpace 0/cupsColorOrder 0>>"
      "setpagedevice\"\n"
      "*ColorModel Black/Inverted Grayscale: \""
      "<</cupsColorSpace 3/cupsColorOrder 0>>"
      "setpagedevice\"\n"
      "*CloseUI: *ColorModel\n"
      "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
      "*DefaultDuplex: DuplexTumble\n"
      "*Duplex None/Off: \"<</Duplex false>>"
      "setpagedevice\"\n"
      "*Duplex DuplexNoTumble/LongEdge: \""
      "<</Duplex true/Tumble false>>setpagedevice\"\n"
      "*Duplex DuplexTumble/ShortEdge: \""
      "<</Duplex true/Tumble true>>setpagedevice\"\n"
      "*CloseUI: *Duplex\n\n"
      "*CloseGroup: General\n");

  printing::PrinterSemanticCapsAndDefaults caps;
  EXPECT_TRUE(printing::parsePpdCapabilities("test", test_ppd_data, &caps));
  EXPECT_FALSE(caps.color_capable);
  EXPECT_FALSE(caps.color_default);
  EXPECT_TRUE(caps.duplex_capable);
  EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
}

// Test duplex detection code, which regressed in http://crbug.com/103999.
TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexSimples) {
  std::string test_ppd_data;
  test_ppd_data.append(
      "*PPD-Adobe: \"4.3\"\n\n"
      "*OpenGroup: General/General\n\n"
      "*OpenUI *Duplex/Double-Sided Printing: PickOne\n"
      "*DefaultDuplex: None\n"
      "*Duplex None/Off: "
      "\"<</Duplex false>>setpagedevice\"\n"
      "*Duplex DuplexNoTumble/Long Edge (Standard): "
      "\"<</Duplex true/Tumble false>>setpagedevice\"\n"
      "*Duplex DuplexTumble/Short Edge (Flip): "
      "\"<</Duplex true/Tumble true>>setpagedevice\"\n"
      "*CloseUI: *Duplex\n\n"
      "*CloseGroup: General\n");

  printing::PrinterSemanticCapsAndDefaults caps;
  EXPECT_TRUE(printing::parsePpdCapabilities("test", test_ppd_data, &caps));
  EXPECT_FALSE(caps.color_capable);
  EXPECT_FALSE(caps.color_default);
  EXPECT_TRUE(caps.duplex_capable);
  EXPECT_EQ(caps.duplex_default, printing::SIMPLEX);
}

TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorNoDuplex) {
  std::string test_ppd_data;
  test_ppd_data.append(
      "*PPD-Adobe: \"4.3\"\n\n"
      "*OpenGroup: General/General\n\n"
      "*OpenUI *ColorModel/Color Model: PickOne\n"
      "*DefaultColorModel: Gray\n"
      "*ColorModel Gray/Grayscale: \""
      "<</cupsColorSpace 0/cupsColorOrder 0>>"
      "setpagedevice\"\n"
      "*ColorModel Black/Inverted Grayscale: \""
      "<</cupsColorSpace 3/cupsColorOrder 0>>"
      "setpagedevice\"\n"
      "*CloseUI: *ColorModel\n"
      "*CloseGroup: General\n");

  printing::PrinterSemanticCapsAndDefaults caps;
  EXPECT_TRUE(printing::parsePpdCapabilities("test", test_ppd_data, &caps));
  EXPECT_FALSE(caps.color_capable);
  EXPECT_FALSE(caps.color_default);
  EXPECT_FALSE(caps.duplex_capable);
  EXPECT_EQ(caps.duplex_default, printing::UNKNOWN_DUPLEX_MODE);
}

TEST(PrintBackendCupsHelperTest, TestPpdParsingColorTrueDuplexLongEdge) {
  std::string test_ppd_data;
  test_ppd_data.append(
      "*PPD-Adobe: \"4.3\"\n\n"
      "*ColorDevice: True\n"
      "*DefaultColorSpace: CMYK\n\n"
      "*OpenGroup: General/General\n\n"
      "*OpenUI *ColorModel/Color Model: PickOne\n"
      "*DefaultColorModel: CMYK\n"
      "*ColorModel CMYK/Color: "
      "\"(cmyk) RCsetdevicecolor\"\n"
      "*ColorModel Gray/Black and White: "
      "\"(gray) RCsetdevicecolor\"\n"
      "*CloseUI: *ColorModel\n"
      "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
      "*DefaultDuplex: DuplexTumble\n"
      "*Duplex None/Off: \"<</Duplex false>>"
      "setpagedevice\"\n"
      "*Duplex DuplexNoTumble/LongEdge: \""
      "<</Duplex true/Tumble false>>setpagedevice\"\n"
      "*Duplex DuplexTumble/ShortEdge: \""
      "<</Duplex true/Tumble true>>setpagedevice\"\n"
      "*CloseUI: *Duplex\n\n"
      "*CloseGroup: General\n");

  printing::PrinterSemanticCapsAndDefaults caps;
  EXPECT_TRUE(printing::parsePpdCapabilities("test", test_ppd_data, &caps));
  EXPECT_TRUE(caps.color_capable);
  EXPECT_TRUE(caps.color_default);
  EXPECT_TRUE(caps.duplex_capable);
  EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
}

TEST(PrintBackendCupsHelperTest, TestPpdParsingColorFalseDuplexLongEdge) {
  std::string test_ppd_data;
  test_ppd_data.append(
      "*PPD-Adobe: \"4.3\"\n\n"
      "*ColorDevice: True\n"
      "*DefaultColorSpace: CMYK\n\n"
      "*OpenGroup: General/General\n\n"
      "*OpenUI *ColorModel/Color Model: PickOne\n"
      "*DefaultColorModel: Grayscale\n"
      "*ColorModel Color/Color: "
      "\"%% FoomaticRIPOptionSetting: ColorModel=Color\"\n"
      "*FoomaticRIPOptionSetting ColorModel=Color: "
      "\"JCLDatamode=Color GSCmdLine=Color\"\n"
      "*ColorModel Grayscale/Grayscale: "
      "\"%% FoomaticRIPOptionSetting: ColorModel=Grayscale\"\n"
      "*FoomaticRIPOptionSetting ColorModel=Grayscale: "
      "\"JCLDatamode=Grayscale GSCmdLine=Grayscale\"\n"
      "*CloseUI: *ColorModel\n"
      "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
      "*DefaultDuplex: DuplexTumble\n"
      "*Duplex None/Off: \"<</Duplex false>>"
      "setpagedevice\"\n"
      "*Duplex DuplexNoTumble/LongEdge: \""
      "<</Duplex true/Tumble false>>setpagedevice\"\n"
      "*Duplex DuplexTumble/ShortEdge: \""
      "<</Duplex true/Tumble true>>setpagedevice\"\n"
      "*CloseUI: *Duplex\n\n"
      "*CloseGroup: General\n");

  printing::PrinterSemanticCapsAndDefaults caps;
  EXPECT_TRUE(printing::parsePpdCapabilities("test", test_ppd_data, &caps));
  EXPECT_TRUE(caps.color_capable);
  EXPECT_FALSE(caps.color_default);
  EXPECT_TRUE(caps.duplex_capable);
  EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
}