| OLD | NEW |
| (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/modules/desktop_capture/rgba_color.h" |
| 14 #include "webrtc/test/gtest.h" |
| 15 |
| 16 namespace webrtc { |
| 17 |
| 18 namespace { |
| 19 |
| 20 // A DesktopFrame implementation to store data in heap, but the stide is |
| 21 // doubled. |
| 22 class DoubleSizeDesktopFrame : public DesktopFrame { |
| 23 public: |
| 24 explicit DoubleSizeDesktopFrame(DesktopSize size); |
| 25 ~DoubleSizeDesktopFrame() override; |
| 26 }; |
| 27 |
| 28 DoubleSizeDesktopFrame::DoubleSizeDesktopFrame(DesktopSize size) |
| 29 : DesktopFrame( |
| 30 size, |
| 31 kBytesPerPixel * size.width() * 2, |
| 32 new uint8_t[kBytesPerPixel * size.width() * size.height() * 2], |
| 33 nullptr) {} |
| 34 |
| 35 DoubleSizeDesktopFrame::~DoubleSizeDesktopFrame() { |
| 36 delete[] data_; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 TEST(TestUtilsTest, BasicDataEqualsCases) { |
| 42 BasicDesktopFrame frame(DesktopSize(4, 4)); |
| 43 for (int i = 0; i < 4; i++) { |
| 44 for (int j = 0; j < 4; j++) { |
| 45 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 46 } |
| 47 } |
| 48 |
| 49 ASSERT_TRUE(DesktopFrameDataEquals(frame, frame)); |
| 50 BasicDesktopFrame other(DesktopSize(4, 4)); |
| 51 for (int i = 0; i < 4; i++) { |
| 52 for (int j = 0; j < 4; j++) { |
| 53 PaintDesktopFrame(&other, DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 54 } |
| 55 } |
| 56 ASSERT_TRUE(DesktopFrameDataEquals(frame, other)); |
| 57 PaintDesktopFrame(&other, DesktopVector(2, 2), RgbaColor(0)); |
| 58 ASSERT_FALSE(DesktopFrameDataEquals(frame, other)); |
| 59 } |
| 60 |
| 61 TEST(TestUtilsTest, DifferentSizeShouldNotEqual) { |
| 62 BasicDesktopFrame frame(DesktopSize(4, 4)); |
| 63 for (int i = 0; i < 4; i++) { |
| 64 for (int j = 0; j < 4; j++) { |
| 65 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 66 } |
| 67 } |
| 68 |
| 69 BasicDesktopFrame other(DesktopSize(2, 8)); |
| 70 for (int i = 0; i < 2; i++) { |
| 71 for (int j = 0; j < 8; j++) { |
| 72 PaintDesktopFrame(&other, DesktopVector(i, j), RgbaColor(2 * j + i)); |
| 73 } |
| 74 } |
| 75 |
| 76 ASSERT_FALSE(DesktopFrameDataEquals(frame, other)); |
| 77 } |
| 78 |
| 79 TEST(TestUtilsTest, DifferentStrideShouldBeComparable) { |
| 80 BasicDesktopFrame frame(DesktopSize(4, 4)); |
| 81 for (int i = 0; i < 4; i++) { |
| 82 for (int j = 0; j < 4; j++) { |
| 83 PaintDesktopFrame(&frame, DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 84 } |
| 85 } |
| 86 |
| 87 ASSERT_TRUE(DesktopFrameDataEquals(frame, frame)); |
| 88 DoubleSizeDesktopFrame other(DesktopSize(4, 4)); |
| 89 for (int i = 0; i < 4; i++) { |
| 90 for (int j = 0; j < 4; j++) { |
| 91 PaintDesktopFrame(&other, DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 92 } |
| 93 } |
| 94 ASSERT_TRUE(DesktopFrameDataEquals(frame, other)); |
| 95 } |
| 96 |
| 97 } // namespace webrtc |
| OLD | NEW |