diff --git a/.gitignore b/.gitignore index c26c8719..4a655f56 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,5 @@ examples/ui src/test/.deps/ src/test/.libs/ src/test/fstring_test +src/test/fpoint_test +src/test/frect_test diff --git a/ChangeLog b/ChangeLog index 9684039b..a469f8c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-03-13 Markus Gans + * Added unit test for FRect + 2017-03-11 Markus Gans * Added unit test for FPoint diff --git a/include/final/fstring.h b/include/final/fstring.h index 01070e52..f656dac2 100644 --- a/include/final/fstring.h +++ b/include/final/fstring.h @@ -210,6 +210,9 @@ class FString friend std::wostream& operator << (std::wostream& outstr, const FString& s); friend std::wistream& operator >> (std::wistream& instr, FString& s); + // Accessor + virtual const char* getClassName(); + // inquiries bool isNull() const; bool isEmpty() const; @@ -390,6 +393,10 @@ class FString // FString inline functions +//---------------------------------------------------------------------- +inline const char* FString::getClassName() +{ return "FString"; } + //---------------------------------------------------------------------- inline bool FString::isNull() const { return ! string; } diff --git a/src/test/Makefile.am b/src/test/Makefile.am index f340e7f4..1782f7c3 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -8,13 +8,16 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -Wall -Werror noinst_PROGRAMS = \ fstring_test \ - fpoint_test + fpoint_test \ + frect_test fstring_test_SOURCES = fstring-test.cpp fpoint_test_SOURCES = fpoint-test.cpp +frect_test_SOURCES = frect-test.cpp TESTS = fstring_test \ - fpoint_test + fpoint_test \ + frect_test check_PROGRAMS = $(TESTS) diff --git a/src/test/Makefile.in b/src/test/Makefile.in index 4f01d0d9..0974ea02 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -83,8 +83,9 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @CPPUNIT_TEST_TRUE@noinst_PROGRAMS = fstring_test$(EXEEXT) \ -@CPPUNIT_TEST_TRUE@ fpoint_test$(EXEEXT) -@CPPUNIT_TEST_TRUE@TESTS = fstring_test$(EXEEXT) fpoint_test$(EXEEXT) +@CPPUNIT_TEST_TRUE@ fpoint_test$(EXEEXT) frect_test$(EXEEXT) +@CPPUNIT_TEST_TRUE@TESTS = fstring_test$(EXEEXT) fpoint_test$(EXEEXT) \ +@CPPUNIT_TEST_TRUE@ frect_test$(EXEEXT) @CPPUNIT_TEST_TRUE@check_PROGRAMS = $(am__EXEEXT_1) subdir = src/test DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ @@ -102,7 +103,7 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @CPPUNIT_TEST_TRUE@am__EXEEXT_1 = fstring_test$(EXEEXT) \ -@CPPUNIT_TEST_TRUE@ fpoint_test$(EXEEXT) +@CPPUNIT_TEST_TRUE@ fpoint_test$(EXEEXT) frect_test$(EXEEXT) PROGRAMS = $(noinst_PROGRAMS) am__fpoint_test_SOURCES_DIST = fpoint-test.cpp @CPPUNIT_TEST_TRUE@am_fpoint_test_OBJECTS = fpoint-test.$(OBJEXT) @@ -112,6 +113,10 @@ AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = +am__frect_test_SOURCES_DIST = frect-test.cpp +@CPPUNIT_TEST_TRUE@am_frect_test_OBJECTS = frect-test.$(OBJEXT) +frect_test_OBJECTS = $(am_frect_test_OBJECTS) +frect_test_LDADD = $(LDADD) am__fstring_test_SOURCES_DIST = fstring-test.cpp @CPPUNIT_TEST_TRUE@am_fstring_test_OBJECTS = fstring-test.$(OBJEXT) fstring_test_OBJECTS = $(am_fstring_test_OBJECTS) @@ -150,8 +155,10 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_1 = -SOURCES = $(fpoint_test_SOURCES) $(fstring_test_SOURCES) +SOURCES = $(fpoint_test_SOURCES) $(frect_test_SOURCES) \ + $(fstring_test_SOURCES) DIST_SOURCES = $(am__fpoint_test_SOURCES_DIST) \ + $(am__frect_test_SOURCES_DIST) \ $(am__fstring_test_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ @@ -512,6 +519,7 @@ top_srcdir = @top_srcdir@ @CPPUNIT_TEST_TRUE@AM_CPPFLAGS = -I$(top_srcdir)/include -Wall -Werror @CPPUNIT_TEST_TRUE@fstring_test_SOURCES = fstring-test.cpp @CPPUNIT_TEST_TRUE@fpoint_test_SOURCES = fpoint-test.cpp +@CPPUNIT_TEST_TRUE@frect_test_SOURCES = frect-test.cpp all: all-am .SUFFIXES: @@ -569,6 +577,10 @@ fpoint_test$(EXEEXT): $(fpoint_test_OBJECTS) $(fpoint_test_DEPENDENCIES) $(EXTRA @rm -f fpoint_test$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(fpoint_test_OBJECTS) $(fpoint_test_LDADD) $(LIBS) +frect_test$(EXEEXT): $(frect_test_OBJECTS) $(frect_test_DEPENDENCIES) $(EXTRA_frect_test_DEPENDENCIES) + @rm -f frect_test$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(frect_test_OBJECTS) $(frect_test_LDADD) $(LIBS) + fstring_test$(EXEEXT): $(fstring_test_OBJECTS) $(fstring_test_DEPENDENCIES) $(EXTRA_fstring_test_DEPENDENCIES) @rm -f fstring_test$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(fstring_test_OBJECTS) $(fstring_test_LDADD) $(LIBS) @@ -580,6 +592,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fpoint-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frect-test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring-test.Po@am__quote@ .cpp.o: @@ -816,6 +829,13 @@ fpoint_test.log: fpoint_test$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +frect_test.log: frect_test$(EXEEXT) + @p='frect_test$(EXEEXT)'; \ + b='frect_test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) .test.log: @p='$<'; \ $(am__set_b); \ diff --git a/src/test/fpoint-test.cpp b/src/test/fpoint-test.cpp index 6dbbd147..1d640df5 100644 --- a/src/test/fpoint-test.cpp +++ b/src/test/fpoint-test.cpp @@ -44,6 +44,7 @@ class FPointTest : public CPPUNIT_NS::TestFixture { } protected: + void classNameTest(); void NoArgumentTest(); void copyConstructorTest(); void assignmentTest(); @@ -60,6 +61,7 @@ class FPointTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE (FPointTest); // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); CPPUNIT_TEST (NoArgumentTest); CPPUNIT_TEST (copyConstructorTest); CPPUNIT_TEST (assignmentTest); @@ -76,6 +78,14 @@ class FPointTest : public CPPUNIT_NS::TestFixture }; #pragma pack(pop) +//---------------------------------------------------------------------- +void FPointTest::classNameTest() +{ + FPoint p; + const char* const classname = p.getClassName(); + CPPUNIT_ASSERT ( std::strcmp(classname, "FPoint") == 0 ); +} + //---------------------------------------------------------------------- void FPointTest::NoArgumentTest() { diff --git a/src/test/frect-test.cpp b/src/test/frect-test.cpp new file mode 100644 index 00000000..4c483e5a --- /dev/null +++ b/src/test/frect-test.cpp @@ -0,0 +1,480 @@ +/*********************************************************************** +* frect-test.cpp - FRect unit tests * +* * +* This file is part of the Final Cut widget toolkit * +* * +* Copyright 2018 Markus Gans * +* * +* The Final Cut is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Lesser General Public License * +* as published by the Free Software Foundation; either version 3 of * +* the License, or (at your option) any later version. * +* * +* The Final Cut is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with this program. If not, see * +* . * +***********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +//---------------------------------------------------------------------- +// class FRectTest +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FRectTest : public CPPUNIT_NS::TestFixture +{ + public: + FRectTest() + { } + + protected: + void classNameTest(); + void NoArgumentTest(); + void copyConstructorTest(); + void assignmentTest(); + void equalTest(); + void notEqualTest(); + void additionTest(); + void subtractionTest(); + void referenceTest(); + void moveTest(); + void containsTest(); + void overlapTest(); + void intersectTest(); + void combinedTest(); + + private: + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE (FRectTest); + + // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); + CPPUNIT_TEST (NoArgumentTest); + CPPUNIT_TEST (copyConstructorTest); + CPPUNIT_TEST (assignmentTest); + CPPUNIT_TEST (equalTest); + CPPUNIT_TEST (notEqualTest); + CPPUNIT_TEST (additionTest); + CPPUNIT_TEST (subtractionTest); + CPPUNIT_TEST (referenceTest); + CPPUNIT_TEST (moveTest); + CPPUNIT_TEST (containsTest); + CPPUNIT_TEST (overlapTest); + CPPUNIT_TEST (intersectTest); + CPPUNIT_TEST (combinedTest); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; +#pragma pack(pop) + +//---------------------------------------------------------------------- +void FRectTest::classNameTest() +{ + FRect r; + const char* const classname = r.getClassName(); + CPPUNIT_ASSERT ( std::strcmp(classname, "FRect") == 0 ); +} + +//---------------------------------------------------------------------- +void FRectTest::NoArgumentTest() +{ + const FRect rectangle; + CPPUNIT_ASSERT ( rectangle.getX1() == 0 ); + CPPUNIT_ASSERT ( rectangle.getY1() == 0 ); + CPPUNIT_ASSERT ( rectangle.getX2() == -1 ); + CPPUNIT_ASSERT ( rectangle.getY2() == -1 ); + CPPUNIT_ASSERT ( rectangle.isNull() ); + CPPUNIT_ASSERT ( rectangle.getWidth() == 0 ); + CPPUNIT_ASSERT ( rectangle.getHeight() == 0 ); + CPPUNIT_ASSERT ( rectangle.getPos() == FPoint(0, 0) ); + CPPUNIT_ASSERT ( rectangle.getUpperLeftPos() == FPoint(0, 0) ); + CPPUNIT_ASSERT ( rectangle.getUpperRightPos() == FPoint(-1, 0) ); + CPPUNIT_ASSERT ( rectangle.getLowerLeftPos() == FPoint(0, -1) ); + CPPUNIT_ASSERT ( rectangle.getLowerRightPos() == FPoint(-1, -1) ); +} + +//---------------------------------------------------------------------- +void FRectTest::copyConstructorTest() +{ + const FRect r1(1, 1, 20, 10); + const FRect r2 (r1); + CPPUNIT_ASSERT ( r2.getX() == 1 ); + CPPUNIT_ASSERT ( r2.getY() == 1 ); + CPPUNIT_ASSERT ( ! r2.isNull() ); + CPPUNIT_ASSERT ( r2.getWidth() == 20 ); + CPPUNIT_ASSERT ( r2.getHeight() == 10 ); +} + +//---------------------------------------------------------------------- +void FRectTest::assignmentTest() +{ + const FRect r1(3, 5, 45, 14); + CPPUNIT_ASSERT ( r1.getX1() == 3 ); + CPPUNIT_ASSERT ( r1.getY1() == 5 ); + CPPUNIT_ASSERT ( r1.getX2() == 47 ); + CPPUNIT_ASSERT ( r1.getY2() == 18 ); + CPPUNIT_ASSERT ( r1.getWidth() == 45 ); + CPPUNIT_ASSERT ( r1.getHeight() == 14 ); + + FRect r2 (r1); + CPPUNIT_ASSERT ( r2 == r1 ); + CPPUNIT_ASSERT ( r2.getX1() == 3 ); + CPPUNIT_ASSERT ( r2.getY1() == 5 ); + CPPUNIT_ASSERT ( r2.getX2() == 47 ); + CPPUNIT_ASSERT ( r2.getY2() == 18 ); + CPPUNIT_ASSERT ( r2.getWidth() == 45 ); + CPPUNIT_ASSERT ( r2.getHeight() == 14 ); + + FRect r3(3, 3, 10, 10); + r3 = r2; + CPPUNIT_ASSERT ( r3 == r2 ); + CPPUNIT_ASSERT ( r3.getX1() == 3 ); + CPPUNIT_ASSERT ( r3.getY1() == 5 ); + CPPUNIT_ASSERT ( r3.getX2() == 47 ); + CPPUNIT_ASSERT ( r3.getY2() == 18 ); + CPPUNIT_ASSERT ( r3.getWidth() == 45 ); + CPPUNIT_ASSERT ( r3.getHeight() == 14 ); + + r3.setPos(FPoint(1, 1)); + CPPUNIT_ASSERT ( r3 != r2 ); + CPPUNIT_ASSERT ( r3.getX1() == 1 ); + CPPUNIT_ASSERT ( r3.getY1() == 1 ); + CPPUNIT_ASSERT ( r3.getX2() == 45 ); + CPPUNIT_ASSERT ( r3.getY2() == 14 ); + CPPUNIT_ASSERT ( r3.getWidth() == 45 ); + CPPUNIT_ASSERT ( r3.getHeight() == 14 ); + + r3.setPos(-5, -5); + CPPUNIT_ASSERT ( r3 != r2 ); + CPPUNIT_ASSERT ( r3.getX1() == -5 ); + CPPUNIT_ASSERT ( r3.getY1() == -5 ); + CPPUNIT_ASSERT ( r3.getX2() == 39 ); + CPPUNIT_ASSERT ( r3.getY2() == 8 ); + CPPUNIT_ASSERT ( r3.getWidth() == 45 ); + CPPUNIT_ASSERT ( r3.getHeight() == 14 ); + + r3.setRect(-3, -3, 6, 6); + CPPUNIT_ASSERT ( r3.getX1() == -3 ); + CPPUNIT_ASSERT ( r3.getY1() == -3 ); + CPPUNIT_ASSERT ( r3.getX2() == 2 ); + CPPUNIT_ASSERT ( r3.getY2() == 2 ); + CPPUNIT_ASSERT ( r3.getWidth() == 6 ); + CPPUNIT_ASSERT ( r3.getHeight() == 6 ); + + r3.setRect(r1); + CPPUNIT_ASSERT ( r3 == r1 ); + CPPUNIT_ASSERT ( r3.getX1() == 3 ); + CPPUNIT_ASSERT ( r3.getY1() == 5 ); + CPPUNIT_ASSERT ( r3.getX2() == 47 ); + CPPUNIT_ASSERT ( r3.getY2() == 18 ); + CPPUNIT_ASSERT ( r3.getWidth() == 45 ); + CPPUNIT_ASSERT ( r3.getHeight() == 14 ); + + r3.setX1(1); + CPPUNIT_ASSERT ( r3 != r1 ); + CPPUNIT_ASSERT ( r3.getX1() == 1 ); + CPPUNIT_ASSERT ( r3.getY1() == 5 ); + CPPUNIT_ASSERT ( r3.getX2() == 47 ); + CPPUNIT_ASSERT ( r3.getY2() == 18 ); + CPPUNIT_ASSERT ( r3.getWidth() == 47 ); + CPPUNIT_ASSERT ( r3.getHeight() == 14 ); + + r3.setY1(1); + CPPUNIT_ASSERT ( r3.getX1() == 1 ); + CPPUNIT_ASSERT ( r3.getY1() == 1 ); + CPPUNIT_ASSERT ( r3.getX2() == 47 ); + CPPUNIT_ASSERT ( r3.getY2() == 18 ); + CPPUNIT_ASSERT ( r3.getWidth() == 47 ); + CPPUNIT_ASSERT ( r3.getHeight() == 18 ); + + r3.setX2(10); + CPPUNIT_ASSERT ( r3.getX1() == 1 ); + CPPUNIT_ASSERT ( r3.getY1() == 1 ); + CPPUNIT_ASSERT ( r3.getX2() == 10 ); + CPPUNIT_ASSERT ( r3.getY2() == 18 ); + CPPUNIT_ASSERT ( r3.getWidth() == 10 ); + CPPUNIT_ASSERT ( r3.getHeight() == 18 ); + + r3.setY2(10); + CPPUNIT_ASSERT ( r3.getX1() == 1 ); + CPPUNIT_ASSERT ( r3.getY1() == 1 ); + CPPUNIT_ASSERT ( r3.getX2() == 10 ); + CPPUNIT_ASSERT ( r3.getY2() == 10 ); + CPPUNIT_ASSERT ( r3.getWidth() == 10 ); + CPPUNIT_ASSERT ( r3.getHeight() == 10 ); + + r3.setX(2); + CPPUNIT_ASSERT ( r3.getX1() == 2 ); + CPPUNIT_ASSERT ( r3.getY1() == 1 ); + CPPUNIT_ASSERT ( r3.getX2() == 11 ); + CPPUNIT_ASSERT ( r3.getY2() == 10 ); + CPPUNIT_ASSERT ( r3.getWidth() == 10 ); + CPPUNIT_ASSERT ( r3.getHeight() == 10 ); + + r3.setY(2); + CPPUNIT_ASSERT ( r3.getX1() == 2 ); + CPPUNIT_ASSERT ( r3.getY1() == 2 ); + CPPUNIT_ASSERT ( r3.getX2() == 11 ); + CPPUNIT_ASSERT ( r3.getY2() == 11 ); + CPPUNIT_ASSERT ( r3.getWidth() == 10 ); + CPPUNIT_ASSERT ( r3.getHeight() == 10 ); + + r3.setWidth(8); + CPPUNIT_ASSERT ( r3.getX1() == 2 ); + CPPUNIT_ASSERT ( r3.getY1() == 2 ); + CPPUNIT_ASSERT ( r3.getX2() == 9 ); + CPPUNIT_ASSERT ( r3.getY2() == 11 ); + CPPUNIT_ASSERT ( r3.getWidth() == 8 ); + CPPUNIT_ASSERT ( r3.getHeight() == 10 ); + + r3.setHeight(8); + CPPUNIT_ASSERT ( r3.getX1() == 2 ); + CPPUNIT_ASSERT ( r3.getY1() == 2 ); + CPPUNIT_ASSERT ( r3.getX2() == 9 ); + CPPUNIT_ASSERT ( r3.getY2() == 9 ); + CPPUNIT_ASSERT ( r3.getWidth() == 8 ); + CPPUNIT_ASSERT ( r3.getHeight() == 8 ); + + r3.setSize(5, 5); + CPPUNIT_ASSERT ( r3.getX1() == 2 ); + CPPUNIT_ASSERT ( r3.getY1() == 2 ); + CPPUNIT_ASSERT ( r3.getX2() == 6 ); + CPPUNIT_ASSERT ( r3.getY2() == 6 ); + CPPUNIT_ASSERT ( r3.getWidth() == 5 ); + CPPUNIT_ASSERT ( r3.getHeight() == 5 ); + + const FPoint p1(3, 3); + const FPoint p2(30, 10); + r3.setCoordinates (p1, p2); + CPPUNIT_ASSERT ( r3.getX1() == 3 ); + CPPUNIT_ASSERT ( r3.getY1() == 3 ); + CPPUNIT_ASSERT ( r3.getX2() == 30 ); + CPPUNIT_ASSERT ( r3.getY2() == 10 ); + CPPUNIT_ASSERT ( r3.getWidth() == 28 ); + CPPUNIT_ASSERT ( r3.getHeight() == 8 ); + + r3.setCoordinates (10, 12, 40, 50); + CPPUNIT_ASSERT ( r3.getX1() == 10 ); + CPPUNIT_ASSERT ( r3.getY1() == 12 ); + CPPUNIT_ASSERT ( r3.getX2() == 40 ); + CPPUNIT_ASSERT ( r3.getY2() == 50 ); + CPPUNIT_ASSERT ( r3.getWidth() == 31 ); + CPPUNIT_ASSERT ( r3.getHeight() == 39 ); +} + +//---------------------------------------------------------------------- +void FRectTest::equalTest() +{ + const FRect r1 (1, 2, 10, 20); + const FRect r2 (1, 2, 10, 20); + CPPUNIT_ASSERT ( r1 == r2 ); + CPPUNIT_ASSERT ( FRect(1, 2, 10, 20) == r2 ); + CPPUNIT_ASSERT ( r1 == FRect(1, 2, 10, 20) ); + CPPUNIT_ASSERT ( FRect() == FRect() ); +} + +//---------------------------------------------------------------------- +void FRectTest::notEqualTest() +{ + const FRect r1 (1, 2, 10, 20); + const FRect r2 (1, 2, 15, 25); + CPPUNIT_ASSERT ( r1 != r2 ); + CPPUNIT_ASSERT ( FRect(1, 2, 10, 20) != r2 ); + CPPUNIT_ASSERT ( r1 != FRect(3, 4, 10, 20) ); + CPPUNIT_ASSERT ( FRect() != r2 ); + CPPUNIT_ASSERT ( r1 != FRect() ); +} + +//---------------------------------------------------------------------- +void FRectTest::additionTest() +{ + const FRect r1 (1, 2, 10, 10); + const FPoint p (3, 5); + const FRect r2 = r1 + p; + CPPUNIT_ASSERT ( r2.getX1() == 1 ); + CPPUNIT_ASSERT ( r2.getY1() == 2 ); + CPPUNIT_ASSERT ( r2.getX2() == 13 ); + CPPUNIT_ASSERT ( r2.getY2() == 16 ); + CPPUNIT_ASSERT ( r2.getWidth() == 13 ); + CPPUNIT_ASSERT ( r2.getHeight() == 15 ); +} + +//---------------------------------------------------------------------- +void FRectTest::subtractionTest() +{ + const FRect r1 (2, 2, 12, 12); + const FPoint p (5, 5); + const FRect r2 = r1 - p; + CPPUNIT_ASSERT ( r2.getX1() == 2 ); + CPPUNIT_ASSERT ( r2.getY1() == 2 ); + CPPUNIT_ASSERT ( r2.getX2() == 8 ); + CPPUNIT_ASSERT ( r2.getY2() == 8 ); + CPPUNIT_ASSERT ( r2.getWidth() == 7 ); + CPPUNIT_ASSERT ( r2.getHeight() == 7 ); +} + +//---------------------------------------------------------------------- +void FRectTest::referenceTest() +{ + FRect r1 (1, 1, 10, 20); + CPPUNIT_ASSERT ( r1.getX1() == 1 ); + CPPUNIT_ASSERT ( r1.getY1() == 1 ); + CPPUNIT_ASSERT ( r1.getX2() == 10 ); + CPPUNIT_ASSERT ( r1.getY2() == 20 ); + + // Use references to coordinates + r1.x1_ref()++; + r1.y1_ref()++; + r1.x2_ref()--; + r1.y2_ref()--; + CPPUNIT_ASSERT ( r1.getX1() == 2 ); + CPPUNIT_ASSERT ( r1.getY1() == 2 ); + CPPUNIT_ASSERT ( r1.getX2() == 9 ); + CPPUNIT_ASSERT ( r1.getY2() == 19 ); + + short& x1 = r1.x1_ref(); + short& y1 = r1.y1_ref(); + short& x2 = r1.x2_ref(); + short& y2 = r1.y2_ref(); + x1 += 2; + y1 -= 2; + x2 -= 3; + y2 += 4; + CPPUNIT_ASSERT ( r1.getX1() == 4 ); + CPPUNIT_ASSERT ( r1.getY1() == 0 ); + CPPUNIT_ASSERT ( r1.getX2() == 6 ); + CPPUNIT_ASSERT ( r1.getY2() == 23 ); +} + +//---------------------------------------------------------------------- +void FRectTest::moveTest() +{ + FRect r1 (1, 2, 10, 20); + CPPUNIT_ASSERT ( r1.getX() == 1 ); + CPPUNIT_ASSERT ( r1.getY() == 2 ); + CPPUNIT_ASSERT ( r1.getWidth() == 10 ); + CPPUNIT_ASSERT ( r1.getHeight() == 20 ); + CPPUNIT_ASSERT ( r1.getX2() == 10 ); + CPPUNIT_ASSERT ( r1.getY2() == 21 ); + + const FPoint p1 (2,3); + r1.move(p1); + CPPUNIT_ASSERT ( r1.getX() == 3 ); + CPPUNIT_ASSERT ( r1.getY() == 5 ); + CPPUNIT_ASSERT ( r1.getWidth() == 10 ); + CPPUNIT_ASSERT ( r1.getHeight() == 20 ); + CPPUNIT_ASSERT ( r1.getX2() == 12 ); + CPPUNIT_ASSERT ( r1.getY2() == 24 ); + + r1.move (-5, -5); + CPPUNIT_ASSERT ( r1.getX() == -2 ); + CPPUNIT_ASSERT ( r1.getY() == 0 ); + CPPUNIT_ASSERT ( r1.getWidth() == 10 ); + CPPUNIT_ASSERT ( r1.getHeight() == 20 ); + CPPUNIT_ASSERT ( r1.getX2() == 7 ); + CPPUNIT_ASSERT ( r1.getY2() == 19 ); +} + +//---------------------------------------------------------------------- +void FRectTest::containsTest() +{ + const FRect r1 (1, 2, 10, 20); + CPPUNIT_ASSERT ( r1.contains(5, 5) ); + CPPUNIT_ASSERT ( ! r1.contains(0, 1) ); + + const FPoint p1 (3, 4); + const FPoint p2 (3, 25); + CPPUNIT_ASSERT ( r1.contains(p1) ); + CPPUNIT_ASSERT ( ! r1.contains(p2) ); + + const FRect r2 (5, 5, 10, 20); + const FRect r3 (2, 3, 9, 19); + CPPUNIT_ASSERT ( !r1.contains(r2) ); + CPPUNIT_ASSERT ( r1.contains(r3) ); +} + +//---------------------------------------------------------------------- +void FRectTest::overlapTest() +{ + const FRect r1 (1, 2, 10, 20); + const FRect r2 (5, 5, 10, 20); + const FRect r3 (2, 3, 9, 19); + const FRect r4 (10, 20, 10, 20); + const FRect r5 (11, 21, 10, 20); + const FRect r6 (-5, -3, 2, 3); + CPPUNIT_ASSERT ( r1.overlap(r2) ); + CPPUNIT_ASSERT ( r1.overlap(r3) ); + CPPUNIT_ASSERT ( r1.overlap(r4) ); + CPPUNIT_ASSERT ( ! r1.overlap(r5) ); + CPPUNIT_ASSERT ( ! r1.overlap(r6) ); +} + +//---------------------------------------------------------------------- +void FRectTest::intersectTest() +{ + const FRect r1 (1, 2, 5, 5); + const FRect r2 (1, 2, 5, 5); + FRect r3 = r1.intersect(r2); + CPPUNIT_ASSERT ( r3.getX() == 1 ); + CPPUNIT_ASSERT ( r3.getY() == 2 ); + CPPUNIT_ASSERT ( r3.getWidth() == 5 ); + CPPUNIT_ASSERT ( r3.getHeight() == 5 ); + CPPUNIT_ASSERT ( r3.getX2() == 5 ); + CPPUNIT_ASSERT ( r3.getY2() == 6 ); + + const FRect r4 (4, 2, 5, 6); + r3 = r1.intersect(r4); + CPPUNIT_ASSERT ( r3.getX() == 4 ); + CPPUNIT_ASSERT ( r3.getY() == 2 ); + CPPUNIT_ASSERT ( r3.getWidth() == 2 ); + CPPUNIT_ASSERT ( r3.getHeight() == 5 ); + CPPUNIT_ASSERT ( r3.getX2() == 5 ); + CPPUNIT_ASSERT ( r3.getY2() == 6 ); +} + +//---------------------------------------------------------------------- +void FRectTest::combinedTest() +{ + const FRect r1 (1, 2, 5, 5); + const FRect r2 (1, 2, 5, 5); + FRect r3 = r1.combined(r2); + CPPUNIT_ASSERT ( r3.getX() == 1 ); + CPPUNIT_ASSERT ( r3.getY() == 2 ); + CPPUNIT_ASSERT ( r3.getWidth() == 5 ); + CPPUNIT_ASSERT ( r3.getHeight() == 5 ); + CPPUNIT_ASSERT ( r3.getX2() == 5 ); + CPPUNIT_ASSERT ( r3.getY2() == 6 ); + + const FRect r4 (4, 2, 5, 6); + r3 = r1.combined(r4); + CPPUNIT_ASSERT ( r3.getX() == 1 ); + CPPUNIT_ASSERT ( r3.getY() == 2 ); + CPPUNIT_ASSERT ( r3.getWidth() == 8 ); + CPPUNIT_ASSERT ( r3.getHeight() == 6 ); + CPPUNIT_ASSERT ( r3.getX2() == 8 ); + CPPUNIT_ASSERT ( r3.getY2() == 7 ); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION (FRectTest); + +// The general unit test main part +#include + diff --git a/src/test/fstring-test.cpp b/src/test/fstring-test.cpp index 9069320f..ded1becf 100644 --- a/src/test/fstring-test.cpp +++ b/src/test/fstring-test.cpp @@ -58,6 +58,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture void tearDown(); protected: + void classNameTest(); void NoArgumentTest(); void initLengthTest(); void copyConstructorTest(); @@ -96,6 +97,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE (FStringTest); // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); CPPUNIT_TEST (NoArgumentTest); CPPUNIT_TEST (initLengthTest); CPPUNIT_TEST (copyConstructorTest); @@ -145,6 +147,14 @@ void FStringTest::tearDown() delete s; } +//---------------------------------------------------------------------- +void FStringTest::classNameTest() +{ + FString s; + const char* const classname = s.getClassName(); + CPPUNIT_ASSERT ( std::strcmp(classname, "FString") == 0 ); +} + //---------------------------------------------------------------------- void FStringTest::NoArgumentTest() {