Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: webrtc/modules/desktop_capture/test_utils_unittest.cc

Issue 2500883004: Add DesktopFrame rotation functions (Closed)
Patch Set: Sync latest changes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/desktop_capture/test_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/test_utils.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/modules/desktop_capture/rgba_color.h"
15 #include "webrtc/test/gtest.h"
16
17 namespace webrtc {
18
19 namespace {
20
21 void PaintDesktopFrame(DesktopFrame* frame,
22 DesktopVector pos,
23 RgbaColor color) {
24 RTC_DCHECK(frame);
25 RTC_DCHECK(DesktopRect::MakeSize(frame->size()).Contains(pos));
26 *reinterpret_cast<uint32_t*>(frame->GetFrameDataAtPos(pos)) =
27 color.ToUInt32();
28 }
29
30 // A DesktopFrame implementation to store data in heap, but the stide is
31 // doubled.
32 class DoubleSizeDesktopFrame : public DesktopFrame {
33 public:
34 explicit DoubleSizeDesktopFrame(DesktopSize size);
35 ~DoubleSizeDesktopFrame() override;
36 };
37
38 DoubleSizeDesktopFrame::DoubleSizeDesktopFrame(DesktopSize size)
39 : DesktopFrame(
40 size,
41 kBytesPerPixel * size.width() * 2,
42 new uint8_t[kBytesPerPixel * size.width() * size.height() * 2],
43 nullptr) {}
44
45 DoubleSizeDesktopFrame::~DoubleSizeDesktopFrame() {
46 delete[] data_;
47 }
48
49 } // namespace
50
51 TEST(TestUtilsTest, BasicDataEqualsCases) {
52 BasicDesktopFrame frame(DesktopSize(4, 4));
53 for (int i = 0; i < 4; i++) {
54 for (int j = 0; j < 4; j++) {
55 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4U * j + i));
56 }
57 }
58
59 ASSERT_TRUE(DesktopFrameDataEquals(frame, frame));
60 BasicDesktopFrame other(DesktopSize(4, 4));
61 for (int i = 0; i < 4; i++) {
62 for (int j = 0; j < 4; j++) {
63 PaintDesktopFrame(&other, DesktopVector(i, j), RgbaColor(4U * j + i));
64 }
65 }
66 ASSERT_TRUE(DesktopFrameDataEquals(frame, other));
67 PaintDesktopFrame(&other, DesktopVector(2, 2), RgbaColor(0U));
68 ASSERT_FALSE(DesktopFrameDataEquals(frame, other));
69 }
70
71 TEST(TestUtilsTest, DifferentSizeShouldNotEqual) {
72 BasicDesktopFrame frame(DesktopSize(4, 4));
73 for (int i = 0; i < 4; i++) {
74 for (int j = 0; j < 4; j++) {
75 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4U * j + i));
76 }
77 }
78
79 BasicDesktopFrame other(DesktopSize(2, 8));
80 for (int i = 0; i < 2; i++) {
81 for (int j = 0; j < 8; j++) {
82 PaintDesktopFrame(&other, DesktopVector(i, j), RgbaColor(2U * j + i));
83 }
84 }
85
86 ASSERT_FALSE(DesktopFrameDataEquals(frame, other));
87 }
88
89 TEST(TestUtilsTest, DifferentStrideShouldBeComparable) {
90 BasicDesktopFrame frame(DesktopSize(4, 4));
91 for (int i = 0; i < 4; i++) {
92 for (int j = 0; j < 4; j++) {
93 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4U * j + i));
94 }
95 }
96
97 ASSERT_TRUE(DesktopFrameDataEquals(frame, frame));
98 DoubleSizeDesktopFrame other(DesktopSize(4, 4));
99 for (int i = 0; i < 4; i++) {
100 for (int j = 0; j < 4; j++) {
101 PaintDesktopFrame(&other, DesktopVector(i, j), RgbaColor(4U * j + i));
102 }
103 }
104 ASSERT_TRUE(DesktopFrameDataEquals(frame, other));
105 }
106
107 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698