zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/modules/desktop_capture/screen_drawer.h" |
| 12 | |
| 13 | #include <stdint.h> |
| 14 | |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 15 | #include "webrtc/base/random.h" |
| 16 | #include "webrtc/base/timeutils.h" |
zijiehe | 0f49dac | 2016-09-07 11:52:25 -0700 | [diff] [blame] | 17 | #include "webrtc/system_wrappers/include/logging.h" |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 18 | #include "webrtc/system_wrappers/include/sleep.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 19 | #include "webrtc/test/gtest.h" |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // These are a set of manual test cases, as we do not have an automatical way to |
| 24 | // detect whether a ScreenDrawer on a certain platform works well without |
| 25 | // ScreenCapturer(s). So you may execute these test cases with |
| 26 | // --gtest_also_run_disabled_tests --gtest_filter=ScreenDrawerTest.*. |
| 27 | TEST(ScreenDrawerTest, DISABLED_DrawRectangles) { |
| 28 | std::unique_ptr<ScreenDrawer> drawer = ScreenDrawer::Create(); |
| 29 | if (!drawer) { |
zijiehe | 0f49dac | 2016-09-07 11:52:25 -0700 | [diff] [blame] | 30 | LOG(LS_WARNING) << "No ScreenDrawer implementation for current platform."; |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 31 | return; |
| 32 | } |
| 33 | |
zijiehe | 0f49dac | 2016-09-07 11:52:25 -0700 | [diff] [blame] | 34 | if (drawer->DrawableRegion().is_empty()) { |
| 35 | LOG(LS_WARNING) << "ScreenDrawer of current platform does not provide a " |
| 36 | "non-empty DrawableRegion()."; |
| 37 | return; |
| 38 | } |
| 39 | |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 40 | DesktopRect rect = drawer->DrawableRegion(); |
| 41 | Random random(rtc::TimeMicros()); |
| 42 | for (int i = 0; i < 100; i++) { |
| 43 | // Make sure we at least draw one pixel. |
| 44 | int left = random.Rand(rect.left(), rect.right() - 2); |
| 45 | int top = random.Rand(rect.top(), rect.bottom() - 2); |
| 46 | drawer->DrawRectangle( |
| 47 | DesktopRect::MakeLTRB(left, top, random.Rand(left + 1, rect.right()), |
| 48 | random.Rand(top + 1, rect.bottom())), |
zijiehe | 0f49dac | 2016-09-07 11:52:25 -0700 | [diff] [blame] | 49 | RgbaColor(random.Rand<uint8_t>(), random.Rand<uint8_t>(), |
| 50 | random.Rand<uint8_t>(), random.Rand<uint8_t>())); |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 51 | |
| 52 | if (i == 50) { |
| 53 | SleepMs(10000); |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | SleepMs(10000); |
zijiehe | 49c01d7 | 2016-08-16 17:33:55 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace webrtc |