zijiehe | 8eef7aa | 2017-05-18 12:27:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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_geometry.h" |
| 12 | |
| 13 | #include "webrtc/test/gtest.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | TEST(DesktopRectTest, UnionBetweenTwoNonEmptyRects) { |
| 18 | DesktopRect rect = DesktopRect::MakeLTRB(1, 1, 2, 2); |
| 19 | rect.UnionWith(DesktopRect::MakeLTRB(-2, -2, -1, -1)); |
| 20 | ASSERT_TRUE(rect.equals(DesktopRect::MakeLTRB(-2, -2, 2, 2))); |
| 21 | } |
| 22 | |
| 23 | TEST(DesktopRectTest, UnionWithEmptyRect) { |
| 24 | DesktopRect rect = DesktopRect::MakeWH(1, 1); |
| 25 | rect.UnionWith(DesktopRect()); |
| 26 | ASSERT_TRUE(rect.equals(DesktopRect::MakeWH(1, 1))); |
| 27 | |
| 28 | rect = DesktopRect::MakeXYWH(1, 1, 2, 2); |
| 29 | rect.UnionWith(DesktopRect()); |
| 30 | ASSERT_TRUE(rect.equals(DesktopRect::MakeXYWH(1, 1, 2, 2))); |
| 31 | |
| 32 | rect = DesktopRect::MakeXYWH(1, 1, 2, 2); |
| 33 | rect.UnionWith(DesktopRect::MakeXYWH(3, 3, 0, 0)); |
| 34 | ASSERT_TRUE(rect.equals(DesktopRect::MakeXYWH(1, 1, 2, 2))); |
| 35 | } |
| 36 | |
| 37 | TEST(DesktopRectTest, EmptyRectUnionWithNonEmptyOne) { |
| 38 | DesktopRect rect; |
| 39 | rect.UnionWith(DesktopRect::MakeWH(1, 1)); |
| 40 | ASSERT_TRUE(rect.equals(DesktopRect::MakeWH(1, 1))); |
| 41 | |
| 42 | rect = DesktopRect(); |
| 43 | rect.UnionWith(DesktopRect::MakeXYWH(1, 1, 2, 2)); |
| 44 | ASSERT_TRUE(rect.equals(DesktopRect::MakeXYWH(1, 1, 2, 2))); |
| 45 | |
| 46 | rect = DesktopRect::MakeXYWH(3, 3, 0, 0); |
| 47 | rect.UnionWith(DesktopRect::MakeXYWH(1, 1, 2, 2)); |
| 48 | ASSERT_TRUE(rect.equals(DesktopRect::MakeXYWH(1, 1, 2, 2))); |
| 49 | } |
| 50 | |
| 51 | TEST(DesktopRectTest, EmptyRectUnionWithEmptyOne) { |
| 52 | DesktopRect rect; |
| 53 | rect.UnionWith(DesktopRect()); |
| 54 | ASSERT_TRUE(rect.is_empty()); |
| 55 | |
| 56 | rect = DesktopRect::MakeXYWH(1, 1, 0, 0); |
| 57 | rect.UnionWith(DesktopRect()); |
| 58 | ASSERT_TRUE(rect.is_empty()); |
| 59 | |
| 60 | rect = DesktopRect(); |
| 61 | rect.UnionWith(DesktopRect::MakeXYWH(1, 1, 0, 0)); |
| 62 | ASSERT_TRUE(rect.is_empty()); |
| 63 | |
| 64 | rect = DesktopRect::MakeXYWH(1, 1, 0, 0); |
| 65 | rect.UnionWith(DesktopRect::MakeXYWH(-1, -1, 0, 0)); |
| 66 | ASSERT_TRUE(rect.is_empty()); |
| 67 | } |
| 68 | |
Zijie He | af5686a | 2017-08-25 11:36:52 -0700 | [diff] [blame] | 69 | TEST(DesktopRectTest, Scale) { |
| 70 | DesktopRect rect = DesktopRect::MakeXYWH(100, 100, 100, 100); |
| 71 | rect.Scale(1.1, 1.1); |
| 72 | ASSERT_EQ(rect.top(), 100); |
| 73 | ASSERT_EQ(rect.left(), 100); |
| 74 | ASSERT_EQ(rect.width(), 110); |
| 75 | ASSERT_EQ(rect.height(), 110); |
| 76 | |
| 77 | rect = DesktopRect::MakeXYWH(100, 100, 100, 100); |
| 78 | rect.Scale(0.01, 0.01); |
| 79 | ASSERT_EQ(rect.top(), 100); |
| 80 | ASSERT_EQ(rect.left(), 100); |
| 81 | ASSERT_EQ(rect.width(), 1); |
| 82 | ASSERT_EQ(rect.height(), 1); |
| 83 | |
| 84 | rect = DesktopRect::MakeXYWH(100, 100, 100, 100); |
| 85 | rect.Scale(1.1, 0.9); |
| 86 | ASSERT_EQ(rect.top(), 100); |
| 87 | ASSERT_EQ(rect.left(), 100); |
| 88 | ASSERT_EQ(rect.width(), 110); |
| 89 | ASSERT_EQ(rect.height(), 90); |
| 90 | |
| 91 | rect = DesktopRect::MakeXYWH(0, 0, 100, 100); |
| 92 | rect.Scale(1.1, 1.1); |
| 93 | ASSERT_EQ(rect.top(), 0); |
| 94 | ASSERT_EQ(rect.left(), 0); |
| 95 | ASSERT_EQ(rect.width(), 110); |
| 96 | ASSERT_EQ(rect.height(), 110); |
| 97 | |
| 98 | rect = DesktopRect::MakeXYWH(0, 100, 100, 100); |
| 99 | rect.Scale(1.1, 1.1); |
| 100 | ASSERT_EQ(rect.top(), 100); |
| 101 | ASSERT_EQ(rect.left(), 0); |
| 102 | ASSERT_EQ(rect.width(), 110); |
| 103 | ASSERT_EQ(rect.height(), 110); |
| 104 | } |
| 105 | |
zijiehe | 8eef7aa | 2017-05-18 12:27:16 -0700 | [diff] [blame] | 106 | } // namespace webrtc |