1 // Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include <algorithm>
6
7 #include "include/cef_print_settings.h"
8 #include "tests/gtest/include/gtest/gtest.h"
9
10 // Verify Set/Get methods for CefPrintSettings.
TEST(PrintTest,SettingsSetGet)11 TEST(PrintTest, SettingsSetGet) {
12 // CefRequest CreateRequest
13 CefRefPtr<CefPrintSettings> settings(CefPrintSettings::Create());
14 EXPECT_TRUE(settings.get() != nullptr);
15 EXPECT_TRUE(settings->IsValid());
16 EXPECT_FALSE(settings->IsReadOnly());
17
18 bool landscape = true;
19 settings->SetOrientation(landscape);
20 EXPECT_EQ(landscape, settings->IsLandscape());
21 landscape = false;
22 settings->SetOrientation(landscape);
23 EXPECT_EQ(landscape, settings->IsLandscape());
24
25 const char device_name[] = "my_device_name";
26 settings->SetDeviceName(device_name);
27 EXPECT_STREQ(device_name, settings->GetDeviceName().ToString().c_str());
28
29 int dpi = 25;
30 settings->SetDPI(dpi);
31 EXPECT_EQ(dpi, settings->GetDPI());
32
33 CefPrintSettings::PageRangeList page_ranges;
34 page_ranges.push_back(CefRange(1, 3));
35 page_ranges.push_back(CefRange(5, 6));
36 settings->SetPageRanges(page_ranges);
37 EXPECT_EQ(page_ranges.size(), settings->GetPageRangesCount());
38 CefPrintSettings::PageRangeList page_ranges2;
39 settings->GetPageRanges(page_ranges2);
40 EXPECT_EQ(page_ranges.size(), page_ranges2.size());
41 for (size_t i = 0; i < page_ranges.size(); ++i)
42 EXPECT_EQ(page_ranges[i], page_ranges2[i]);
43
44 bool selection_only = true;
45 settings->SetSelectionOnly(selection_only);
46 EXPECT_EQ(selection_only, settings->IsSelectionOnly());
47 selection_only = false;
48 settings->SetSelectionOnly(selection_only);
49 EXPECT_EQ(selection_only, settings->IsSelectionOnly());
50
51 bool collate = true;
52 settings->SetCollate(collate);
53 EXPECT_EQ(collate, settings->WillCollate());
54 collate = false;
55 settings->SetCollate(collate);
56 EXPECT_EQ(collate, settings->WillCollate());
57
58 CefPrintSettings::ColorModel color_model = COLOR_MODEL_CMYK;
59 settings->SetColorModel(color_model);
60 EXPECT_EQ(color_model, settings->GetColorModel());
61
62 int copies = 3;
63 settings->SetCopies(copies);
64 EXPECT_EQ(copies, settings->GetCopies());
65
66 CefPrintSettings::DuplexMode duplex_mode = DUPLEX_MODE_SIMPLEX;
67 settings->SetDuplexMode(duplex_mode);
68 EXPECT_EQ(duplex_mode, settings->GetDuplexMode());
69 }
70