Home | History | Annotate | Download | only in backend
      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
      3 // found in the LICENSE file.
      4 
      5 #include "printing/backend/cups_helper.h"
      6 #include "printing/backend/print_backend.h"
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexLongEdge) {
     10   std::string test_ppd_data;
     11   test_ppd_data.append(
     12       "*PPD-Adobe: \"4.3\"\n\n"
     13       "*OpenGroup: General/General\n\n"
     14       "*OpenUI *ColorModel/Color Model: PickOne\n"
     15       "*DefaultColorModel: Gray\n"
     16       "*ColorModel Gray/Grayscale: \""
     17       "<</cupsColorSpace 0/cupsColorOrder 0>>"
     18       "setpagedevice\"\n"
     19       "*ColorModel Black/Inverted Grayscale: \""
     20       "<</cupsColorSpace 3/cupsColorOrder 0>>"
     21       "setpagedevice\"\n"
     22       "*CloseUI: *ColorModel\n"
     23       "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
     24       "*DefaultDuplex: DuplexTumble\n"
     25       "*Duplex None/Off: \"<</Duplex false>>"
     26       "setpagedevice\"\n"
     27       "*Duplex DuplexNoTumble/LongEdge: \""
     28       "<</Duplex true/Tumble false>>setpagedevice\"\n"
     29       "*Duplex DuplexTumble/ShortEdge: \""
     30       "<</Duplex true/Tumble true>>setpagedevice\"\n"
     31       "*CloseUI: *Duplex\n\n"
     32       "*CloseGroup: General\n");
     33 
     34   printing::PrinterSemanticCapsAndDefaults caps;
     35   EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
     36   EXPECT_FALSE(caps.color_changeable);
     37   EXPECT_FALSE(caps.color_default);
     38   EXPECT_TRUE(caps.duplex_capable);
     39   EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
     40 }
     41 
     42 // Test duplex detection code, which regressed in http://crbug.com/103999.
     43 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexSimples) {
     44   std::string test_ppd_data;
     45   test_ppd_data.append(
     46       "*PPD-Adobe: \"4.3\"\n\n"
     47       "*OpenGroup: General/General\n\n"
     48       "*OpenUI *Duplex/Double-Sided Printing: PickOne\n"
     49       "*DefaultDuplex: None\n"
     50       "*Duplex None/Off: "
     51       "\"<</Duplex false>>setpagedevice\"\n"
     52       "*Duplex DuplexNoTumble/Long Edge (Standard): "
     53       "\"<</Duplex true/Tumble false>>setpagedevice\"\n"
     54       "*Duplex DuplexTumble/Short Edge (Flip): "
     55       "\"<</Duplex true/Tumble true>>setpagedevice\"\n"
     56       "*CloseUI: *Duplex\n\n"
     57       "*CloseGroup: General\n");
     58 
     59   printing::PrinterSemanticCapsAndDefaults caps;
     60   EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
     61   EXPECT_FALSE(caps.color_changeable);
     62   EXPECT_FALSE(caps.color_default);
     63   EXPECT_TRUE(caps.duplex_capable);
     64   EXPECT_EQ(caps.duplex_default, printing::SIMPLEX);
     65 }
     66 
     67 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorNoDuplex) {
     68   std::string test_ppd_data;
     69   test_ppd_data.append(
     70       "*PPD-Adobe: \"4.3\"\n\n"
     71       "*OpenGroup: General/General\n\n"
     72       "*OpenUI *ColorModel/Color Model: PickOne\n"
     73       "*DefaultColorModel: Gray\n"
     74       "*ColorModel Gray/Grayscale: \""
     75       "<</cupsColorSpace 0/cupsColorOrder 0>>"
     76       "setpagedevice\"\n"
     77       "*ColorModel Black/Inverted Grayscale: \""
     78       "<</cupsColorSpace 3/cupsColorOrder 0>>"
     79       "setpagedevice\"\n"
     80       "*CloseUI: *ColorModel\n"
     81       "*CloseGroup: General\n");
     82 
     83   printing::PrinterSemanticCapsAndDefaults caps;
     84   EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
     85   EXPECT_FALSE(caps.color_changeable);
     86   EXPECT_FALSE(caps.color_default);
     87   EXPECT_FALSE(caps.duplex_capable);
     88   EXPECT_EQ(caps.duplex_default, printing::UNKNOWN_DUPLEX_MODE);
     89 }
     90 
     91 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorTrueDuplexLongEdge) {
     92   std::string test_ppd_data;
     93   test_ppd_data.append(
     94       "*PPD-Adobe: \"4.3\"\n\n"
     95       "*ColorDevice: True\n"
     96       "*DefaultColorSpace: CMYK\n\n"
     97       "*OpenGroup: General/General\n\n"
     98       "*OpenUI *ColorModel/Color Model: PickOne\n"
     99       "*DefaultColorModel: CMYK\n"
    100       "*ColorModel CMYK/Color: "
    101       "\"(cmyk) RCsetdevicecolor\"\n"
    102       "*ColorModel Gray/Black and White: "
    103       "\"(gray) RCsetdevicecolor\"\n"
    104       "*CloseUI: *ColorModel\n"
    105       "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
    106       "*DefaultDuplex: DuplexTumble\n"
    107       "*Duplex None/Off: \"<</Duplex false>>"
    108       "setpagedevice\"\n"
    109       "*Duplex DuplexNoTumble/LongEdge: \""
    110       "<</Duplex true/Tumble false>>setpagedevice\"\n"
    111       "*Duplex DuplexTumble/ShortEdge: \""
    112       "<</Duplex true/Tumble true>>setpagedevice\"\n"
    113       "*CloseUI: *Duplex\n\n"
    114       "*CloseGroup: General\n");
    115 
    116   printing::PrinterSemanticCapsAndDefaults caps;
    117   EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
    118   EXPECT_TRUE(caps.color_changeable);
    119   EXPECT_TRUE(caps.color_default);
    120   EXPECT_TRUE(caps.duplex_capable);
    121   EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
    122 }
    123 
    124 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorFalseDuplexLongEdge) {
    125   std::string test_ppd_data;
    126   test_ppd_data.append(
    127       "*PPD-Adobe: \"4.3\"\n\n"
    128       "*ColorDevice: True\n"
    129       "*DefaultColorSpace: CMYK\n\n"
    130       "*OpenGroup: General/General\n\n"
    131       "*OpenUI *ColorModel/Color Model: PickOne\n"
    132       "*DefaultColorModel: Grayscale\n"
    133       "*ColorModel Color/Color: "
    134       "\"%% FoomaticRIPOptionSetting: ColorModel=Color\"\n"
    135       "*FoomaticRIPOptionSetting ColorModel=Color: "
    136       "\"JCLDatamode=Color GSCmdLine=Color\"\n"
    137       "*ColorModel Grayscale/Grayscale: "
    138       "\"%% FoomaticRIPOptionSetting: ColorModel=Grayscale\"\n"
    139       "*FoomaticRIPOptionSetting ColorModel=Grayscale: "
    140       "\"JCLDatamode=Grayscale GSCmdLine=Grayscale\"\n"
    141       "*CloseUI: *ColorModel\n"
    142       "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
    143       "*DefaultDuplex: DuplexTumble\n"
    144       "*Duplex None/Off: \"<</Duplex false>>"
    145       "setpagedevice\"\n"
    146       "*Duplex DuplexNoTumble/LongEdge: \""
    147       "<</Duplex true/Tumble false>>setpagedevice\"\n"
    148       "*Duplex DuplexTumble/ShortEdge: \""
    149       "<</Duplex true/Tumble true>>setpagedevice\"\n"
    150       "*CloseUI: *Duplex\n\n"
    151       "*CloseGroup: General\n");
    152 
    153   printing::PrinterSemanticCapsAndDefaults caps;
    154   EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
    155   EXPECT_TRUE(caps.color_changeable);
    156   EXPECT_FALSE(caps.color_default);
    157   EXPECT_TRUE(caps.duplex_capable);
    158   EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
    159 }
    160