1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
17 class RectUnittest
: public CppUnit::TestFixture
22 void testIntersection();
24 CPPUNIT_TEST_SUITE(RectUnittest
);
25 CPPUNIT_TEST(testBasic
);
26 CPPUNIT_TEST(testUnion
);
27 CPPUNIT_TEST(testIntersection
);
28 CPPUNIT_TEST_SUITE_END();
31 void RectUnittest::testBasic()
33 SwRect
rect(Point(10, 15), Size(20, 25));
35 CPPUNIT_ASSERT_EQUAL(rect
, SwRect(10, 15, 20, 25));
36 CPPUNIT_ASSERT_EQUAL(rect
, SwRect(Point(10, 15), Point(10 + 20 - 1, 15 + 25 - 1)));
38 CPPUNIT_ASSERT_EQUAL(tools::Long(20), rect
.Width());
39 CPPUNIT_ASSERT_EQUAL(tools::Long(25), rect
.Height());
40 CPPUNIT_ASSERT_EQUAL(tools::Long(10), rect
.Left());
41 CPPUNIT_ASSERT_EQUAL(tools::Long(15), rect
.Top());
42 CPPUNIT_ASSERT_EQUAL(tools::Long(10 + 20 - 1), rect
.Right());
43 CPPUNIT_ASSERT_EQUAL(tools::Long(15 + 25 - 1), rect
.Bottom());
45 CPPUNIT_ASSERT_EQUAL(Point(rect
.Left(), rect
.Top()), rect
.TopLeft());
46 CPPUNIT_ASSERT_EQUAL(Point(rect
.Right(), rect
.Top()), rect
.TopRight());
47 CPPUNIT_ASSERT_EQUAL(Point(rect
.Left(), rect
.Bottom()), rect
.BottomLeft());
48 CPPUNIT_ASSERT_EQUAL(Point(rect
.Right(), rect
.Bottom()), rect
.BottomRight());
51 void RectUnittest::testUnion()
53 SwRect
rect1(Point(10, 10), Size(10, 10));
54 SwRect
rect2(Point(15, 15), Size(10, 10));
55 SwRect
rect3(Point(30, 30), Size(10, 10));
60 CPPUNIT_ASSERT_EQUAL(SwRect(Point(10, 10), Size(15, 15)), tmp
);
61 CPPUNIT_ASSERT_EQUAL(SwRect(Point(10, 10), Size(15, 15)), rect1
.GetUnion(rect2
));
65 CPPUNIT_ASSERT_EQUAL(SwRect(Point(10, 10), Size(30, 30)), tmp
);
66 CPPUNIT_ASSERT_EQUAL(SwRect(Point(10, 10), Size(30, 30)), rect1
.GetUnion(rect3
));
70 CPPUNIT_ASSERT_EQUAL(rect1
, tmp
);
71 CPPUNIT_ASSERT_EQUAL(rect1
, rect1
.GetUnion(SwRect()));
74 CPPUNIT_ASSERT_EQUAL(rect1
, tmp
);
75 CPPUNIT_ASSERT_EQUAL(rect1
, SwRect().GetUnion(rect1
));
78 void RectUnittest::testIntersection()
80 SwRect
rect1(Point(10, 10), Size(10, 10));
81 SwRect
rect2(Point(15, 15), Size(10, 10));
82 SwRect
rect3(Point(30, 30), Size(10, 10));
86 tmp
.Intersection(rect2
);
87 CPPUNIT_ASSERT_EQUAL(SwRect(Point(15, 15), Size(5, 5)), tmp
);
88 CPPUNIT_ASSERT_EQUAL(SwRect(Point(15, 15), Size(5, 5)), rect1
.GetIntersection(rect2
));
91 tmp
.Intersection(rect3
);
92 CPPUNIT_ASSERT(tmp
.IsEmpty());
93 CPPUNIT_ASSERT(rect1
.GetIntersection(rect3
).IsEmpty());
96 tmp
.Intersection(SwRect());
97 CPPUNIT_ASSERT(tmp
.IsEmpty());
98 CPPUNIT_ASSERT(rect1
.GetIntersection(SwRect()).IsEmpty());
100 tmp
.Intersection(rect1
);
101 CPPUNIT_ASSERT(tmp
.IsEmpty());
102 CPPUNIT_ASSERT(SwRect().GetIntersection(rect1
).IsEmpty());
105 CPPUNIT_TEST_SUITE_REGISTRATION(RectUnittest
);
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */