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