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

Side by Side Diff: resolution_selector_test.cc

Issue 6732013: Refactor monitor_reconfigure to stop using system("xrandr"). (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/monitor_reconfig.git@master
Patch Set: Fix comment Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « resolution_selector.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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <vector> 5 #include <vector>
6 6
7 #include <gflags/gflags.h> 7 #include <gflags/gflags.h>
8 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "monitor_reconfig/resolution_selector.h" 13 #include "monitor_reconfig/resolution_selector.h"
14 14
15 DEFINE_bool(logtostderr, false, 15 DEFINE_bool(logtostderr, false,
16 "Print debugging messages to stderr (suppressed otherwise)"); 16 "Print debugging messages to stderr (suppressed otherwise)");
17 17
18 namespace monitor_reconfig { 18 namespace monitor_reconfig {
19 19
20 using std::string; 20 using std::string;
21 using std::vector; 21 using std::vector;
22 22
23 class ResolutionSelectorTest : public ::testing::Test { 23 class ResolutionSelectorTest : public ::testing::Test {
24 protected: 24 protected:
25 virtual void SetUp() {} 25 virtual void SetUp() {
26 lcd_resolution_ = new ResolutionSelector::Mode;
27 external_resolution_ = new ResolutionSelector::Mode;
28 screen_resolution_ = new ResolutionSelector::Mode;
29 }
26 30
27 // Add a mode to |lcd_modes_|. 31 // Add a mode to |lcd_modes_|.
28 void AddLcdMode(int width, int height) { 32 void AddLcdMode(int width, int height, int id) {
29 lcd_modes_.push_back( 33 lcd_modes_.push_back(
30 ResolutionSelector::Mode( 34 ResolutionSelector::Mode(
31 width, height, StringPrintf("%dx%d", width, height))); 35 width, height, StringPrintf("%dx%d", width, height), id));
32 } 36 }
33 37
34 // Add a mode to |external_modes_|. 38 // Add a mode to |external_modes_|.
35 void AddExternalMode(int width, int height) { 39 void AddExternalMode(int width, int height, int id) {
36 external_modes_.push_back( 40 external_modes_.push_back(
37 ResolutionSelector::Mode( 41 ResolutionSelector::Mode(
38 width, height, StringPrintf("%dx%d", width, height))); 42 width, height, StringPrintf("%dx%d", width, height), id));
39 } 43 }
40 44
41 // Ask |selector_| for the best resolutions and store them in 45 // Ask |selector_| for the best resolutions and store them in
42 // |lcd_resolution_|, |external_resolution_|, and |screen_resolution_|. 46 // |lcd_resolution_|, |external_resolution_|, and |screen_resolution_|.
43 // The return value from |FindBestResolutions()| is returned. 47 // The return value from |FindBestResolutions()| is returned.
44 bool GetResolutions() { 48 bool GetResolutions() {
45 return selector_.FindBestResolutions(lcd_modes_, 49 return selector_.FindBestResolutions(lcd_modes_,
46 external_modes_, 50 external_modes_,
47 &lcd_resolution_, 51 lcd_resolution_,
48 &external_resolution_, 52 external_resolution_,
49 &screen_resolution_); 53 screen_resolution_);
50 } 54 }
51 55
52 ResolutionSelector selector_; 56 ResolutionSelector selector_;
53 57
54 vector<ResolutionSelector::Mode> lcd_modes_; 58 vector<ResolutionSelector::Mode> lcd_modes_;
55 vector<ResolutionSelector::Mode> external_modes_; 59 vector<ResolutionSelector::Mode> external_modes_;
56 60
57 string lcd_resolution_; 61 ResolutionSelector::Mode* lcd_resolution_;
58 string external_resolution_; 62 ResolutionSelector::Mode* external_resolution_;
59 string screen_resolution_; 63 ResolutionSelector::Mode* screen_resolution_;
60 }; 64 };
61 65
62 // We should use the LCD's max resolution when there's no external output 66 // We should use the LCD's max resolution when there's no external output
63 // connected. 67 // connected.
64 TEST_F(ResolutionSelectorTest, NoExternalOutput) { 68 TEST_F(ResolutionSelectorTest, NoExternalOutput) {
65 AddLcdMode(1024, 768); 69 AddLcdMode(1024, 768, 50);
66 AddLcdMode(800, 600); 70 AddLcdMode(800, 600, 51);
67 ASSERT_TRUE(GetResolutions()); 71 ASSERT_TRUE(GetResolutions());
68 EXPECT_EQ("1024x768", lcd_resolution_); 72 EXPECT_EQ("1024x768", lcd_resolution_->name);
69 EXPECT_EQ("", external_resolution_); 73 EXPECT_EQ("", external_resolution_->name);
70 EXPECT_EQ("1024x768", screen_resolution_); 74 EXPECT_EQ("1024x768", screen_resolution_->name);
71 } 75 }
72 76
73 // When both outputs have the same max resolution, we should use it. 77 // When both outputs have the same max resolution, we should use it.
74 TEST_F(ResolutionSelectorTest, MatchingTopResolutions) { 78 TEST_F(ResolutionSelectorTest, MatchingTopResolutions) {
75 AddLcdMode(1024, 768); 79 AddLcdMode(1024, 768, 50);
76 AddLcdMode(800, 600); 80 AddLcdMode(800, 600, 51);
77 AddExternalMode(1024, 768); 81 AddExternalMode(1024, 768, 60);
78 AddExternalMode(800, 600); 82 AddExternalMode(800, 600, 61);
79 ASSERT_TRUE(GetResolutions()); 83 ASSERT_TRUE(GetResolutions());
80 EXPECT_EQ("1024x768", lcd_resolution_); 84 EXPECT_EQ("1024x768", lcd_resolution_->name);
81 EXPECT_EQ("1024x768", external_resolution_); 85 EXPECT_EQ("1024x768", external_resolution_->name);
82 EXPECT_EQ("1024x768", screen_resolution_); 86 EXPECT_EQ("1024x768", screen_resolution_->name);
83 } 87 }
84 88
85 // We should use the highest shared resolution when the LCD has the higher 89 // We should use the highest shared resolution when the LCD has the higher
86 // max resolution. 90 // max resolution.
87 TEST_F(ResolutionSelectorTest, LcdHasHigherResolution) { 91 TEST_F(ResolutionSelectorTest, LcdHasHigherResolution) {
88 AddLcdMode(1024, 768); 92 AddLcdMode(1024, 768, 50);
89 AddLcdMode(800, 600); 93 AddLcdMode(800, 600, 51);
90 AddLcdMode(640, 480); 94 AddLcdMode(640, 480, 52);
91 AddExternalMode(800, 600); 95 AddExternalMode(800, 600, 60);
92 AddExternalMode(640, 480); 96 AddExternalMode(640, 480, 61);
93 ASSERT_TRUE(GetResolutions()); 97 ASSERT_TRUE(GetResolutions());
94 EXPECT_EQ("800x600", lcd_resolution_); 98 EXPECT_EQ("800x600", lcd_resolution_->name);
95 EXPECT_EQ("800x600", external_resolution_); 99 EXPECT_EQ("800x600", external_resolution_->name);
96 EXPECT_EQ("800x600", screen_resolution_); 100 EXPECT_EQ("800x600", screen_resolution_->name);
97 } 101 }
98 102
99 // We should use the highest shared resolution when the external output has 103 // We should use the highest shared resolution when the external output has
100 // the higher max resolution. 104 // the higher max resolution.
101 TEST_F(ResolutionSelectorTest, ExternalHasHigherResolution) { 105 TEST_F(ResolutionSelectorTest, ExternalHasHigherResolution) {
102 AddLcdMode(800, 600); 106 AddLcdMode(800, 600, 50);
103 AddLcdMode(640, 480); 107 AddLcdMode(640, 480, 51);
104 AddExternalMode(1024, 768); 108 AddExternalMode(1024, 768, 60);
105 AddExternalMode(800, 600); 109 AddExternalMode(800, 600, 61);
106 AddExternalMode(640, 480); 110 AddExternalMode(640, 480, 62);
107 ASSERT_TRUE(GetResolutions()); 111 ASSERT_TRUE(GetResolutions());
108 EXPECT_EQ("800x600", lcd_resolution_); 112 EXPECT_EQ("800x600", lcd_resolution_->name);
109 EXPECT_EQ("800x600", external_resolution_); 113 EXPECT_EQ("800x600", external_resolution_->name);
110 EXPECT_EQ("800x600", screen_resolution_); 114 EXPECT_EQ("800x600", screen_resolution_->name);
111 } 115 }
112 116
113 // When the maximum resolution offered by the two outputs is different, we 117 // When the maximum resolution offered by the two outputs is different, we
114 // should use the max resolution from the lower-res output. 118 // should use the max resolution from the lower-res output.
115 TEST_F(ResolutionSelectorTest, MismatchedMaxResolution) { 119 TEST_F(ResolutionSelectorTest, MismatchedMaxResolution) {
116 AddLcdMode(1024, 600); 120 AddLcdMode(1024, 600, 50);
117 AddLcdMode(800, 600); 121 AddLcdMode(800, 600, 51);
118 AddExternalMode(1280, 720); 122 AddExternalMode(1280, 720, 60);
119 AddExternalMode(1024, 768); 123 AddExternalMode(1024, 768, 61);
120 AddExternalMode(800, 600); 124 AddExternalMode(800, 600, 62);
121 ASSERT_TRUE(GetResolutions()); 125 ASSERT_TRUE(GetResolutions());
122 EXPECT_EQ("1024x600", lcd_resolution_); 126 EXPECT_EQ("1024x600", lcd_resolution_->name);
123 EXPECT_EQ("1024x768", external_resolution_); 127 EXPECT_EQ("1024x768", external_resolution_->name);
124 EXPECT_EQ("1024x600", screen_resolution_); 128 EXPECT_EQ("1024x600", screen_resolution_->name);
125 } 129 }
126 130
127 // When the external output is large enough that we think it's a monitor, 131 // When the external output is large enough that we think it's a monitor,
128 // we should just use its maximum resolution instead of trying to find a 132 // we should just use its maximum resolution instead of trying to find a
129 // size that'll also work for the LCD output. 133 // size that'll also work for the LCD output.
130 TEST_F(ResolutionSelectorTest, ExternalOutputIsMonitor) { 134 TEST_F(ResolutionSelectorTest, ExternalOutputIsMonitor) {
131 AddLcdMode(1024, 768); 135 AddLcdMode(1024, 768, 50);
132 AddLcdMode(800, 600); 136 AddLcdMode(800, 600, 51);
133 AddExternalMode(1600, 1200); 137 AddExternalMode(1600, 1200, 60);
134 AddExternalMode(1280, 960); 138 AddExternalMode(1280, 960, 61);
135 AddExternalMode(1024, 768); 139 AddExternalMode(1024, 768, 62);
136 ASSERT_GE(external_modes_[0].width * external_modes_[0].height, 140 ASSERT_GE(external_modes_[0].width * external_modes_[0].height,
137 ResolutionSelector::kMaxProjectorPixels); 141 ResolutionSelector::kMaxProjectorPixels);
138 ASSERT_TRUE(GetResolutions()); 142 ASSERT_TRUE(GetResolutions());
139 EXPECT_EQ("", lcd_resolution_); 143 EXPECT_EQ("", lcd_resolution_->name);
140 EXPECT_EQ("1600x1200", external_resolution_); 144 EXPECT_EQ("1600x1200", external_resolution_->name);
141 EXPECT_EQ("1600x1200", screen_resolution_); 145 EXPECT_EQ("1600x1200", screen_resolution_->name);
142 } 146 }
143 147
144 // We should just fail if there's no common resolution between the two 148 // We should just fail if there's no common resolution between the two
145 // outputs. 149 // outputs.
146 TEST_F(ResolutionSelectorTest, FailIfNoCommonResolution) { 150 TEST_F(ResolutionSelectorTest, FailIfNoCommonResolution) {
147 AddLcdMode(1024, 768); 151 AddLcdMode(1024, 768, 50);
148 AddExternalMode(1280, 600); 152 AddExternalMode(1280, 600, 60);
149 EXPECT_FALSE(GetResolutions()); 153 EXPECT_FALSE(GetResolutions());
150 } 154 }
151 155
152 } // namespace monitor_reconfig 156 } // namespace monitor_reconfig
153 157
154 int main(int argc, char** argv) { 158 int main(int argc, char** argv) {
155 google::ParseCommandLineFlags(&argc, &argv, true); 159 google::ParseCommandLineFlags(&argc, &argv, true);
156 CommandLine::Init(argc, argv); 160 CommandLine::Init(argc, argv);
157 logging::InitLogging(NULL, 161 logging::InitLogging(NULL,
158 FLAGS_logtostderr ? 162 FLAGS_logtostderr ?
159 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : 163 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG :
160 logging::LOG_NONE, 164 logging::LOG_NONE,
161 logging::DONT_LOCK_LOG_FILE, 165 logging::DONT_LOCK_LOG_FILE,
162 logging::APPEND_TO_OLD_LOG_FILE); 166 logging::APPEND_TO_OLD_LOG_FILE);
163 ::testing::InitGoogleTest(&argc, argv); 167 ::testing::InitGoogleTest(&argc, argv);
164 return RUN_ALL_TESTS(); 168 return RUN_ALL_TESTS();
165 } 169 }
OLDNEW
« no previous file with comments | « resolution_selector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698