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