Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / core / test_rect.cxx
blobcfb9fa63a04f648ba7309d9d927948b646851ce0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
15 #include <swrect.hxx>
17 class RectUnittest : public CppUnit::TestFixture
19 public:
20 void testBasic();
21 void testUnion();
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));
56 SwRect tmp;
58 tmp = rect1;
59 tmp.Union(rect2);
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));
63 tmp = rect1;
64 tmp.Union(rect3);
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));
68 tmp = rect1;
69 tmp.Union(SwRect());
70 CPPUNIT_ASSERT_EQUAL(rect1, tmp);
71 CPPUNIT_ASSERT_EQUAL(rect1, rect1.GetUnion(SwRect()));
72 tmp = SwRect();
73 tmp.Union(rect1);
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));
83 SwRect tmp;
85 tmp = rect1;
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));
90 tmp = rect1;
91 tmp.Intersection(rect3);
92 CPPUNIT_ASSERT(tmp.IsEmpty());
93 CPPUNIT_ASSERT(rect1.GetIntersection(rect3).IsEmpty());
95 tmp = rect1;
96 tmp.Intersection(SwRect());
97 CPPUNIT_ASSERT(tmp.IsEmpty());
98 CPPUNIT_ASSERT(rect1.GetIntersection(SwRect()).IsEmpty());
99 tmp = SwRect();
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: */