summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2022-08-23 19:30:02 +1000
committerTomaž Vajngerl <quikee@gmail.com>2022-08-24 10:55:29 +0200
commit6c0bb0f9b846b3f1fee3ff07fb67409708449e0a (patch)
tree5d7309d435042117c4e23f175930f864aaf2e7a3
parent59210b075b79e4fc58f86542d9947d6ed0073abd (diff)
tools: test Rectangle::Normalize()
Change-Id: Ia3fec45b2b6dd0011910c8db5819e161485336c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138713 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--tools/qa/cppunit/test_rectangle.cxx98
1 files changed, 98 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_rectangle.cxx b/tools/qa/cppunit/test_rectangle.cxx
index 4cf1b57d8b2b..02b355ad0576 100644
--- a/tools/qa/cppunit/test_rectangle.cxx
+++ b/tools/qa/cppunit/test_rectangle.cxx
@@ -18,9 +18,23 @@ class Test : public CppUnit::TestFixture
{
public:
void test_rectangle();
+ void test_rectnormalize_alreadynormal();
+ void test_rectnormalize_zerorect();
+ void test_rectnormalize_reverse_topleft_bottomright();
+ void test_rectnormalize_topright_bottomleft();
+ void test_rectnormalize_bottomleft_topright();
+ void test_rectnormalize_zerowidth_top_bottom_reversed();
+ void test_rectnormalize_zeroheight_left_right_reversed();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(test_rectangle);
+ CPPUNIT_TEST(test_rectnormalize_zerorect);
+ CPPUNIT_TEST(test_rectnormalize_alreadynormal);
+ CPPUNIT_TEST(test_rectnormalize_reverse_topleft_bottomright);
+ CPPUNIT_TEST(test_rectnormalize_topright_bottomleft);
+ CPPUNIT_TEST(test_rectnormalize_bottomleft_topright);
+ CPPUNIT_TEST(test_rectnormalize_zerowidth_top_bottom_reversed);
+ CPPUNIT_TEST(test_rectnormalize_zeroheight_left_right_reversed);
CPPUNIT_TEST_SUITE_END();
};
@@ -109,6 +123,90 @@ void Test::test_rectangle()
}
}
+void Test::test_rectnormalize_alreadynormal()
+{
+ Point aTopLeft(0, 0);
+ Point aBottomRight(1, 1);
+
+ tools::Rectangle aRect(aTopLeft, aBottomRight);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL(aRect.TopLeft(), aTopLeft);
+ CPPUNIT_ASSERT_EQUAL(aRect.BottomRight(), aBottomRight);
+}
+
+void Test::test_rectnormalize_zerorect()
+{
+ Point aTopLeft(53, 53);
+ Point aBottomRight(53, 53);
+
+ tools::Rectangle aRect(aTopLeft, aBottomRight);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL(aRect.TopLeft(), aTopLeft);
+ CPPUNIT_ASSERT_EQUAL(aRect.BottomRight(), aBottomRight);
+}
+
+void Test::test_rectnormalize_reverse_topleft_bottomright()
+{
+ Point aPoint1(1, 1);
+ Point aPoint2(0, 0);
+
+ tools::Rectangle aRect(aPoint1, aPoint2);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TopLeft() is wrong", Point(0, 0), aRect.TopLeft());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 1), aRect.BottomRight());
+}
+
+void Test::test_rectnormalize_topright_bottomleft()
+{
+ Point aPoint1(1, 0);
+ Point aPoint2(0, 1);
+
+ tools::Rectangle aRect(aPoint1, aPoint2);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TopLeft() is wrong", Point(0, 0), aRect.TopLeft());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 1), aRect.BottomRight());
+}
+
+void Test::test_rectnormalize_bottomleft_topright()
+{
+ Point aPoint1(0, 1);
+ Point aPoint2(1, 0);
+
+ tools::Rectangle aRect(aPoint1, aPoint2);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TopLeft() is wrong", Point(0, 0), aRect.TopLeft());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 1), aRect.BottomRight());
+}
+
+void Test::test_rectnormalize_zerowidth_top_bottom_reversed()
+{
+ Point aPoint1(0, 1);
+ Point aPoint2(0, 0);
+
+ tools::Rectangle aRect(aPoint1, aPoint2);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TopLeft() is wrong", Point(0, 0), aRect.TopLeft());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(0, 1), aRect.BottomRight());
+}
+
+void Test::test_rectnormalize_zeroheight_left_right_reversed()
+{
+ Point aPoint1(1, 0);
+ Point aPoint2(0, 0);
+
+ tools::Rectangle aRect(aPoint1, aPoint2);
+ aRect.Normalize();
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TopLeft() is wrong", Point(0, 0), aRect.TopLeft());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("BottomRight() is wrong", Point(1, 0), aRect.BottomRight());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}