| 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/desktop_frame.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, kBytesPerPixel * size.width() * 2, |
| 31 new uint8_t[kBytesPerPixel * size.width() * size.height() * 2], |
| 32 nullptr) {} |
| 33 |
| 34 DoubleSizeDesktopFrame::~DoubleSizeDesktopFrame() { |
| 35 delete[] data_; |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 TEST(DesktopFrameTest, BasicDataEqualsCases) { |
| 41 BasicDesktopFrame frame(DesktopSize(4, 4)); |
| 42 for (int i = 0; i < 4; i++) { |
| 43 for (int j = 0; j < 4; j++) { |
| 44 frame.Paint(DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 45 } |
| 46 } |
| 47 |
| 48 ASSERT_TRUE(frame.DataEquals(frame)); |
| 49 BasicDesktopFrame other(DesktopSize(4, 4)); |
| 50 for (int i = 0; i < 4; i++) { |
| 51 for (int j = 0; j < 4; j++) { |
| 52 other.Paint(DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 53 } |
| 54 } |
| 55 ASSERT_TRUE(frame.DataEquals(other)); |
| 56 other.Paint(DesktopVector(2, 2), RgbaColor(0)); |
| 57 ASSERT_FALSE(frame.DataEquals(other)); |
| 58 } |
| 59 |
| 60 TEST(DesktopFrameTest, DifferSizeShouldNotEqual) { |
| 61 BasicDesktopFrame frame(DesktopSize(4, 4)); |
| 62 for (int i = 0; i < 4; i++) { |
| 63 for (int j = 0; j < 4; j++) { |
| 64 frame.Paint(DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 65 } |
| 66 } |
| 67 |
| 68 BasicDesktopFrame other(DesktopSize(2, 8)); |
| 69 for (int i = 0; i < 2; i++) { |
| 70 for (int j = 0; j < 8; j++) { |
| 71 other.Paint(DesktopVector(i, j), RgbaColor(2 * j + i)); |
| 72 } |
| 73 } |
| 74 |
| 75 ASSERT_FALSE(frame.DataEquals(other)); |
| 76 } |
| 77 |
| 78 TEST(DesktopFrameTest, DifferentStrideShouldBeComparable) { |
| 79 BasicDesktopFrame frame(DesktopSize(4, 4)); |
| 80 for (int i = 0; i < 4; i++) { |
| 81 for (int j = 0; j < 4; j++) { |
| 82 frame.Paint(DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 83 } |
| 84 } |
| 85 |
| 86 ASSERT_TRUE(frame.DataEquals(frame)); |
| 87 DoubleSizeDesktopFrame other(DesktopSize(4, 4)); |
| 88 for (int i = 0; i < 4; i++) { |
| 89 for (int j = 0; j < 4; j++) { |
| 90 other.Paint(DesktopVector(i, j), RgbaColor(4 * j + i)); |
| 91 } |
| 92 } |
| 93 ASSERT_TRUE(frame.DataEquals(other)); |
| 94 } |
| 95 |
| 96 } // namespace webrtc |
| OLD | NEW |