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

Unified Diff: webrtc/modules/desktop_capture/desktop_frame_unittest.cc

Issue 2500883004: Add DesktopFrame rotation functions (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/desktop_frame_unittest.cc
diff --git a/webrtc/modules/desktop_capture/desktop_frame_unittest.cc b/webrtc/modules/desktop_capture/desktop_frame_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..55d349e6e26060bc1aeb1386b49692b72806152f
--- /dev/null
+++ b/webrtc/modules/desktop_capture/desktop_frame_unittest.cc
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/desktop_capture/desktop_frame.h"
+
+#include "webrtc/modules/desktop_capture/rgba_color.h"
+#include "webrtc/test/gtest.h"
+
+namespace webrtc {
+
+namespace {
+
+// A DesktopFrame implementation to store data in heap, but the stide is
+// doubled.
+class DoubleSizeDesktopFrame : public DesktopFrame {
+ public:
+ explicit DoubleSizeDesktopFrame(DesktopSize size);
+ ~DoubleSizeDesktopFrame() override;
+};
+
+DoubleSizeDesktopFrame::DoubleSizeDesktopFrame(DesktopSize size)
+ : DesktopFrame(
+ size, kBytesPerPixel * size.width() * 2,
+ new uint8_t[kBytesPerPixel * size.width() * size.height() * 2],
+ nullptr) {}
+
+DoubleSizeDesktopFrame::~DoubleSizeDesktopFrame() {
+ delete[] data_;
+}
+
+} // namespace
+
+TEST(DesktopFrameTest, BasicDataEqualsCases) {
+ BasicDesktopFrame frame(DesktopSize(4, 4));
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ frame.Paint(DesktopVector(i, j), RgbaColor(4 * j + i));
+ }
+ }
+
+ ASSERT_TRUE(frame.DataEquals(frame));
+ BasicDesktopFrame other(DesktopSize(4, 4));
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ other.Paint(DesktopVector(i, j), RgbaColor(4 * j + i));
+ }
+ }
+ ASSERT_TRUE(frame.DataEquals(other));
+ other.Paint(DesktopVector(2, 2), RgbaColor(0));
+ ASSERT_FALSE(frame.DataEquals(other));
+}
+
+TEST(DesktopFrameTest, DifferSizeShouldNotEqual) {
+ BasicDesktopFrame frame(DesktopSize(4, 4));
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ frame.Paint(DesktopVector(i, j), RgbaColor(4 * j + i));
+ }
+ }
+
+ BasicDesktopFrame other(DesktopSize(2, 8));
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 8; j++) {
+ other.Paint(DesktopVector(i, j), RgbaColor(2 * j + i));
+ }
+ }
+
+ ASSERT_FALSE(frame.DataEquals(other));
+}
+
+TEST(DesktopFrameTest, DifferentStrideShouldBeComparable) {
+ BasicDesktopFrame frame(DesktopSize(4, 4));
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ frame.Paint(DesktopVector(i, j), RgbaColor(4 * j + i));
+ }
+ }
+
+ ASSERT_TRUE(frame.DataEquals(frame));
+ DoubleSizeDesktopFrame other(DesktopSize(4, 4));
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ other.Paint(DesktopVector(i, j), RgbaColor(4 * j + i));
+ }
+ }
+ ASSERT_TRUE(frame.DataEquals(other));
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698