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