blob: 2821af0fbf12304643cf1a5fef6b045ce359148b [file] [log] [blame]
zijiehe49c01d72016-08-16 17:33:55 -07001/*
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
zijiehe49c01d72016-08-16 17:33:55 -070015#include "webrtc/base/random.h"
16#include "webrtc/base/timeutils.h"
zijiehe0f49dac2016-09-07 11:52:25 -070017#include "webrtc/system_wrappers/include/logging.h"
zijiehe49c01d72016-08-16 17:33:55 -070018#include "webrtc/system_wrappers/include/sleep.h"
kwibergac9f8762016-09-30 22:29:43 -070019#include "webrtc/test/gtest.h"
zijiehe49c01d72016-08-16 17:33:55 -070020
21namespace 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.*.
27TEST(ScreenDrawerTest, DISABLED_DrawRectangles) {
28 std::unique_ptr<ScreenDrawer> drawer = ScreenDrawer::Create();
29 if (!drawer) {
zijiehe0f49dac2016-09-07 11:52:25 -070030 LOG(LS_WARNING) << "No ScreenDrawer implementation for current platform.";
zijiehe49c01d72016-08-16 17:33:55 -070031 return;
32 }
33
zijiehe0f49dac2016-09-07 11:52:25 -070034 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
zijiehe49c01d72016-08-16 17:33:55 -070040 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())),
zijiehe0f49dac2016-09-07 11:52:25 -070049 RgbaColor(random.Rand<uint8_t>(), random.Rand<uint8_t>(),
50 random.Rand<uint8_t>(), random.Rand<uint8_t>()));
zijiehe49c01d72016-08-16 17:33:55 -070051
52 if (i == 50) {
53 SleepMs(10000);
zijiehe49c01d72016-08-16 17:33:55 -070054 }
55 }
56
57 SleepMs(10000);
zijiehe49c01d72016-08-16 17:33:55 -070058}
59
60} // namespace webrtc