blob: 90086b817e688fc745d56ee5add6dc248c0745e5 [file] [log] [blame]
Pranav Batra30744232020-09-08 21:17:471// Copyright 2020 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/printing_context_chromeos.h"
6
7#include <string.h>
8
9#include "printing/backend/cups_ipp_constants.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace printing {
13
14namespace {
15
16const char* GetOptionValue(const std::vector<ScopedCupsOption>& options,
17 const char* option_name) {
18 DCHECK(option_name);
19 const char* ret = nullptr;
20 for (const auto& option : options) {
21 EXPECT_TRUE(option->name);
22 EXPECT_TRUE(option->value);
23 if (option->name && !strcmp(option_name, option->name)) {
24 EXPECT_EQ(nullptr, ret)
25 << "Multiple options with name " << option_name << " found.";
26 ret = option->value;
27 }
28 }
29 return ret;
30}
31
32class TestPrintSettings : public PrintSettings {
33 public:
34 TestPrintSettings() { set_duplex_mode(mojom::DuplexMode::kSimplex); }
35};
36
37class PrintingContextTest : public testing::Test {
38 public:
39 const char* Get(const char* name) const {
40 return GetOptionValue(SettingsToCupsOptions(settings_), name);
41 }
42 TestPrintSettings settings_;
43};
44
45TEST_F(PrintingContextTest, SettingsToCupsOptions_Color) {
46 settings_.set_color(mojom::ColorModel::kGray);
47 EXPECT_STREQ("monochrome", Get(kIppColor));
48 settings_.set_color(mojom::ColorModel::kColor);
49 EXPECT_STREQ("color", Get(kIppColor));
50}
51
52TEST_F(PrintingContextTest, SettingsToCupsOptions_Duplex) {
53 settings_.set_duplex_mode(mojom::DuplexMode::kSimplex);
54 EXPECT_STREQ("one-sided", Get(kIppDuplex));
55 settings_.set_duplex_mode(mojom::DuplexMode::kLongEdge);
56 EXPECT_STREQ("two-sided-long-edge", Get(kIppDuplex));
57 settings_.set_duplex_mode(mojom::DuplexMode::kShortEdge);
58 EXPECT_STREQ("two-sided-short-edge", Get(kIppDuplex));
59}
60
61TEST_F(PrintingContextTest, SettingsToCupsOptions_Media) {
62 EXPECT_STREQ("", Get(kIppMedia));
63 settings_.set_requested_media(
64 {gfx::Size(297000, 420000), "iso_a3_297x420mm"});
65 EXPECT_STREQ("iso_a3_297x420mm", Get(kIppMedia));
66}
67
68TEST_F(PrintingContextTest, SettingsToCupsOptions_Copies) {
69 settings_.set_copies(3);
70 EXPECT_STREQ("3", Get(kIppCopies));
71}
72
73TEST_F(PrintingContextTest, SettingsToCupsOptions_Collate) {
74 EXPECT_STREQ("separate-documents-uncollated-copies", Get(kIppCollate));
75 settings_.set_collate(true);
76 EXPECT_STREQ("separate-documents-collated-copies", Get(kIppCollate));
77}
78
79TEST_F(PrintingContextTest, SettingsToCupsOptions_Pin) {
80 EXPECT_STREQ(nullptr, Get(kIppPin));
81 settings_.set_pin_value("1234");
82 EXPECT_STREQ("1234", Get(kIppPin));
83}
84
85TEST_F(PrintingContextTest, SettingsToCupsOptions_Resolution) {
86 EXPECT_STREQ(nullptr, Get(kIppResolution));
87 settings_.set_dpi_xy(0, 300);
88 EXPECT_STREQ(nullptr, Get(kIppResolution));
89 settings_.set_dpi_xy(300, 0);
90 EXPECT_STREQ(nullptr, Get(kIppResolution));
91 settings_.set_dpi(600);
92 EXPECT_STREQ("600dpi", Get(kIppResolution));
93 settings_.set_dpi_xy(600, 1200);
94 EXPECT_STREQ("600x1200dpi", Get(kIppResolution));
95}
96
97} // namespace
98
99} // namespace printing