1 #include <gtest/gtest.h>
5 class VRegionTest : public ::testing::Test {
7 VRegionTest():rgn1(-10, -10, 20, 20)
12 rect1 = VRect(-10, -10, 20, 20);
13 rect2 = VRect(-15, 5, 10, 10);
32 TEST_F(VRegionTest, constructor) {
33 ASSERT_EQ(rgn1.rectCount() , 1);
34 ASSERT_TRUE(rgn1.rectAt(0) == rect1);
35 ASSERT_TRUE(rgn1==rgn3);
36 ASSERT_TRUE(rgn1!=rgn2);
39 TEST_F(VRegionTest, moveSemantics) {
44 tmp = std::move(rgn1);
45 ASSERT_TRUE(rgn1.empty());
49 VRegion mvrgn = std::move(rgn1);
50 ASSERT_TRUE(rgn1.empty());
51 ASSERT_TRUE(mvrgn == rect1);
53 TEST_F(VRegionTest, isEmpty) {
54 ASSERT_TRUE(emptyRgn.empty());
55 ASSERT_TRUE(emptyRgn == VRegion());
56 ASSERT_TRUE(emptyRgn.rectCount() == 0);
57 ASSERT_TRUE(emptyRgn.boundingRect() == VRect());
60 TEST_F(VRegionTest, boundingRect) {
64 ASSERT_TRUE(region.boundingRect() == rect);
67 VRect rect(10, -20, 30, 40);
69 ASSERT_TRUE(region.boundingRect() == rect);
72 VRect rect(15,25,10,10);
74 ASSERT_TRUE(region.boundingRect() == rect);
78 TEST_F(VRegionTest, swap) {
79 VRegion r1(VRect(0, 0,10,10));
80 VRegion r2(VRect(10,10,10,10));
82 ASSERT_TRUE(r1.rectAt(0) == VRect(10,10,10,10));
83 ASSERT_TRUE(r2.rectAt(0) == VRect(0, 0,10,10));
86 TEST_F(VRegionTest, substracted) {
87 VRegion r1(VRect(0, 0,20,20));
88 VRegion r2 = r1.subtracted(VRect(5,5,5,5));
90 expected += VRect(0,0,20,5);
91 expected += VRect(0,5,5,5);
92 expected += VRect(10,5,10,5);
93 expected += VRect(0,10,20,10);
94 ASSERT_TRUE(r2.rectCount() == expected.rectCount());
95 ASSERT_TRUE(r2 == expected);
97 ASSERT_TRUE(r2 == r1);
100 TEST_F(VRegionTest, translate) {
101 VRegion r1(VRect(0, 0,20,20));
102 VPoint offset(10,10);
103 VRegion r2 = r1.translated(offset);
104 r1.translate(offset);
105 ASSERT_TRUE(r2 == r2);
108 TEST_F(VRegionTest, intersects) {
109 VRegion r1(VRect(0, 0,20,20));
110 VRegion r2(VRect(20, 20,10,10));
111 ASSERT_FALSE(r1.intersects(r2));
112 r2 += VRect(5, 0,20,20);
113 ASSERT_TRUE(r1.intersects(r2));
116 TEST_F(VRegionTest, contains) {
117 VRegion r1(VRect(0, 0,20,20));
118 ASSERT_TRUE(r1.contains(VRect(5,5,10,10)));
119 ASSERT_FALSE(r1.contains(VRect(11,5,10,10)));