Added unit test for FPoint

This commit is contained in:
Markus Gans 2018-03-11 19:20:36 +01:00
parent 9da31a7d7b
commit d2a688fdc2
7 changed files with 317 additions and 16 deletions

View File

@ -1,3 +1,6 @@
2017-03-11 Markus Gans <guru.mail@muenster.de>
* Added unit test for FPoint
2017-03-10 Markus Gans <guru.mail@muenster.de> 2017-03-10 Markus Gans <guru.mail@muenster.de>
* Unit tests for the FString class completed * Unit tests for the FString class completed
* Minor bug fixes in FString * Minor bug fixes in FString

View File

@ -7,11 +7,14 @@ AM_LDFLAGS = -L$(top_builddir)/src/.libs -lfinal $(CPPUNIT_LIBS)
AM_CPPFLAGS = -I$(top_srcdir)/include -Wall -Werror AM_CPPFLAGS = -I$(top_srcdir)/include -Wall -Werror
noinst_PROGRAMS = \ noinst_PROGRAMS = \
fstring_test fstring_test \
fpoint_test
fstring_test_SOURCES = fstring-test.cpp fstring_test_SOURCES = fstring-test.cpp
fpoint_test_SOURCES = fpoint-test.cpp
TESTS = fstring_test TESTS = fstring_test \
fpoint_test
check_PROGRAMS = $(TESTS) check_PROGRAMS = $(TESTS)

View File

@ -11,8 +11,8 @@ SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:%.cpp=%) OBJS = $(SRCS:%.cpp=%)
CCXFLAGS = $(OPTIMIZE) $(PROFILE) $(DEBUG) CCXFLAGS = $(OPTIMIZE) $(PROFILE) $(DEBUG)
MAKEFILE = -f Makefile.clang MAKEFILE = -f Makefile.clang
LDFLAGS = -L../src -lfinal -lcppunit -ldl LDFLAGS = -L.. -lfinal -lcppunit -ldl
INCLUDES = -I../include -I/usr/include/final INCLUDES = -I. -I../../include -I/usr/include/final
RM = rm -f RM = rm -f
ifdef DEBUG ifdef DEBUG

View File

@ -11,8 +11,8 @@ SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:%.cpp=%) OBJS = $(SRCS:%.cpp=%)
CCXFLAGS = $(OPTIMIZE) $(PROFILE) $(DEBUG) CCXFLAGS = $(OPTIMIZE) $(PROFILE) $(DEBUG)
MAKEFILE = -f Makefile.gcc MAKEFILE = -f Makefile.gcc
LDFLAGS = -L../src -lfinal -lcppunit -ldl LDFLAGS = -L.. -lfinal -lcppunit -ldl
INCLUDES = -I../include -I/usr/include/final INCLUDES = -I. -I../../include -I/usr/include/final
RM = rm -f RM = rm -f
ifdef DEBUG ifdef DEBUG

View File

@ -82,8 +82,9 @@ PRE_UNINSTALL = :
POST_UNINSTALL = : POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
@CPPUNIT_TEST_TRUE@noinst_PROGRAMS = fstring_test$(EXEEXT) @CPPUNIT_TEST_TRUE@noinst_PROGRAMS = fstring_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@TESTS = fstring_test$(EXEEXT) @CPPUNIT_TEST_TRUE@ fpoint_test$(EXEEXT)
@CPPUNIT_TEST_TRUE@TESTS = fstring_test$(EXEEXT) fpoint_test$(EXEEXT)
@CPPUNIT_TEST_TRUE@check_PROGRAMS = $(am__EXEEXT_1) @CPPUNIT_TEST_TRUE@check_PROGRAMS = $(am__EXEEXT_1)
subdir = src/test subdir = src/test
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
@ -100,16 +101,21 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES = CONFIG_CLEAN_VPATH_FILES =
@CPPUNIT_TEST_TRUE@am__EXEEXT_1 = fstring_test$(EXEEXT) @CPPUNIT_TEST_TRUE@am__EXEEXT_1 = fstring_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fpoint_test$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS) PROGRAMS = $(noinst_PROGRAMS)
am__fstring_test_SOURCES_DIST = fstring-test.cpp am__fpoint_test_SOURCES_DIST = fpoint-test.cpp
@CPPUNIT_TEST_TRUE@am_fstring_test_OBJECTS = fstring-test.$(OBJEXT) @CPPUNIT_TEST_TRUE@am_fpoint_test_OBJECTS = fpoint-test.$(OBJEXT)
fstring_test_OBJECTS = $(am_fstring_test_OBJECTS) fpoint_test_OBJECTS = $(am_fpoint_test_OBJECTS)
fstring_test_LDADD = $(LDADD) fpoint_test_LDADD = $(LDADD)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent am__v_lt_0 = --silent
am__v_lt_1 = am__v_lt_1 =
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)
fstring_test_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@) AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false am__v_P_0 = false
@ -144,8 +150,9 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_0 = @echo " CXXLD " $@;
am__v_CXXLD_1 = am__v_CXXLD_1 =
SOURCES = $(fstring_test_SOURCES) SOURCES = $(fpoint_test_SOURCES) $(fstring_test_SOURCES)
DIST_SOURCES = $(am__fstring_test_SOURCES_DIST) DIST_SOURCES = $(am__fpoint_test_SOURCES_DIST) \
$(am__fstring_test_SOURCES_DIST)
am__can_run_installinfo = \ am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \ case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \ n|no|NO) false;; \
@ -504,6 +511,7 @@ top_srcdir = @top_srcdir@
@CPPUNIT_TEST_TRUE@AM_LDFLAGS = -L$(top_builddir)/src/.libs -lfinal $(CPPUNIT_LIBS) @CPPUNIT_TEST_TRUE@AM_LDFLAGS = -L$(top_builddir)/src/.libs -lfinal $(CPPUNIT_LIBS)
@CPPUNIT_TEST_TRUE@AM_CPPFLAGS = -I$(top_srcdir)/include -Wall -Werror @CPPUNIT_TEST_TRUE@AM_CPPFLAGS = -I$(top_srcdir)/include -Wall -Werror
@CPPUNIT_TEST_TRUE@fstring_test_SOURCES = fstring-test.cpp @CPPUNIT_TEST_TRUE@fstring_test_SOURCES = fstring-test.cpp
@CPPUNIT_TEST_TRUE@fpoint_test_SOURCES = fpoint-test.cpp
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:
@ -557,6 +565,10 @@ clean-noinstPROGRAMS:
echo " rm -f" $$list; \ echo " rm -f" $$list; \
rm -f $$list rm -f $$list
fpoint_test$(EXEEXT): $(fpoint_test_OBJECTS) $(fpoint_test_DEPENDENCIES) $(EXTRA_fpoint_test_DEPENDENCIES)
@rm -f fpoint_test$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(fpoint_test_OBJECTS) $(fpoint_test_LDADD) $(LIBS)
fstring_test$(EXEEXT): $(fstring_test_OBJECTS) $(fstring_test_DEPENDENCIES) $(EXTRA_fstring_test_DEPENDENCIES) fstring_test$(EXEEXT): $(fstring_test_OBJECTS) $(fstring_test_DEPENDENCIES) $(EXTRA_fstring_test_DEPENDENCIES)
@rm -f fstring_test$(EXEEXT) @rm -f fstring_test$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(fstring_test_OBJECTS) $(fstring_test_LDADD) $(LIBS) $(AM_V_CXXLD)$(CXXLINK) $(fstring_test_OBJECTS) $(fstring_test_LDADD) $(LIBS)
@ -567,6 +579,7 @@ mostlyclean-compile:
distclean-compile: distclean-compile:
-rm -f *.tab.c -rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fpoint-test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring-test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring-test.Po@am__quote@
.cpp.o: .cpp.o:
@ -796,6 +809,13 @@ fstring_test.log: fstring_test$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \ --log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT) "$$tst" $(AM_TESTS_FD_REDIRECT)
fpoint_test.log: fpoint_test$(EXEEXT)
@p='fpoint_test$(EXEEXT)'; \
b='fpoint_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: .test.log:
@p='$<'; \ @p='$<'; \
$(am__set_b); \ $(am__set_b); \

275
src/test/fpoint-test.cpp Normal file
View File

@ -0,0 +1,275 @@
/***********************************************************************
* fpoint-test.cpp - FPoint 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 *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <final/final.h>
//----------------------------------------------------------------------
// class FPointTest
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FPointTest : public CPPUNIT_NS::TestFixture
{
public:
FPointTest()
{ }
protected:
void NoArgumentTest();
void copyConstructorTest();
void assignmentTest();
void additionAssignmentTest();
void subtractionAssignmentTest();
void equalTest();
void notEqualTest();
void additionTest();
void subtractionTest();
void referenceTest();
private:
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (FPointTest);
// Add a methods to the test suite
CPPUNIT_TEST (NoArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (additionAssignmentTest);
CPPUNIT_TEST (subtractionAssignmentTest);
CPPUNIT_TEST (equalTest);
CPPUNIT_TEST (notEqualTest);
CPPUNIT_TEST (additionTest);
CPPUNIT_TEST (subtractionTest);
CPPUNIT_TEST (referenceTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
#pragma pack(pop)
//----------------------------------------------------------------------
void FPointTest::NoArgumentTest()
{
const FPoint point;
CPPUNIT_ASSERT ( point.getX() == 0 );
CPPUNIT_ASSERT ( point.getY() == 0 );
CPPUNIT_ASSERT ( point.isNull() );
}
//----------------------------------------------------------------------
void FPointTest::copyConstructorTest()
{
const FPoint p1 (15,10);
const FPoint p2 (p1);
CPPUNIT_ASSERT ( p2.getX() == 15 );
CPPUNIT_ASSERT ( p2.getY() == 10 );
}
//----------------------------------------------------------------------
void FPointTest::assignmentTest()
{
const FPoint p1 (-99,100);
CPPUNIT_ASSERT ( p1.getX() == -99 );
CPPUNIT_ASSERT ( p1.getY() == 100 );
FPoint p2;
p2 = p1;
CPPUNIT_ASSERT ( p2.getX() == -99 );
CPPUNIT_ASSERT ( p2.getY() == 100 );
p2 = -p1;
CPPUNIT_ASSERT ( p2.getX() == 99 );
CPPUNIT_ASSERT ( p2.getY() == -100 );
p2.setPoint (80, 24);
CPPUNIT_ASSERT ( p2.getX() == 80 );
CPPUNIT_ASSERT ( p2.getY() == 24 );
p2.setX(40);
CPPUNIT_ASSERT ( p2.getX() == 40 );
CPPUNIT_ASSERT ( p2.getY() == 24 );
p2.setY(12);
CPPUNIT_ASSERT ( p2.getX() == 40 );
CPPUNIT_ASSERT ( p2.getY() == 12 );
// Value limit exceeded
const FPoint p3 (-999999,1000000);
CPPUNIT_ASSERT ( p3.getX() != -999999 );
CPPUNIT_ASSERT ( p3.getY() != 1000000 );
}
//----------------------------------------------------------------------
void FPointTest::additionAssignmentTest()
{
FPoint p1 (1,2);
p1 += FPoint (3,1);
CPPUNIT_ASSERT ( p1.getX() == 4 );
CPPUNIT_ASSERT ( p1.getY() == 3 );
p1 += FPoint (-4,-3);
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p1.isNull() );
// Value limit exceeded
FPoint p2 (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() == 18000 );
CPPUNIT_ASSERT ( p2.getY() == -18000 );
p2 += FPoint (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() != 36000 );
CPPUNIT_ASSERT ( p2.getY() != -36000 );
}
//----------------------------------------------------------------------
void FPointTest::subtractionAssignmentTest()
{
FPoint p1 (10,20);
p1 -= FPoint (5,5);
CPPUNIT_ASSERT ( p1.getX() == 5 );
CPPUNIT_ASSERT ( p1.getY() == 15 );
p1 -= FPoint (-5,20);
CPPUNIT_ASSERT ( p1.getX() == 10 );
CPPUNIT_ASSERT ( p1.getY() == -5 );
CPPUNIT_ASSERT ( ! p1.isNull() );
p1 -= FPoint (-10,0);
CPPUNIT_ASSERT ( p1.getX() == 20 );
CPPUNIT_ASSERT ( p1.getY() == -5 );
CPPUNIT_ASSERT ( ! p1.isNull() );
p1 -= FPoint (20,0);
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == -5 );
CPPUNIT_ASSERT ( ! p1.isNull() );
p1 -= FPoint (0,-6);
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 1 );
CPPUNIT_ASSERT ( ! p1.isNull() );
p1 -= FPoint (1,0);
CPPUNIT_ASSERT ( p1.getX() == -1 );
CPPUNIT_ASSERT ( p1.getY() == 1 );
CPPUNIT_ASSERT ( ! p1.isNull() );
p1 -= (FPoint (0,1) + FPoint (-1,0));
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p1.isNull() );
// Value limit exceeded
FPoint p2 (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() == 18000 );
CPPUNIT_ASSERT ( p2.getY() == -18000 );
p2 += FPoint (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() != 36000 );
CPPUNIT_ASSERT ( p2.getY() != -36000 );
}
//----------------------------------------------------------------------
void FPointTest::equalTest()
{
const FPoint p1 (1,2);
const FPoint p2 (1,2);
CPPUNIT_ASSERT ( p1 == p2 );
CPPUNIT_ASSERT ( FPoint(1,2) == p2 );
CPPUNIT_ASSERT ( p1 == FPoint(1,2) );
CPPUNIT_ASSERT ( FPoint() == FPoint() );
CPPUNIT_ASSERT ( FPoint() == -FPoint() );
}
//----------------------------------------------------------------------
void FPointTest::notEqualTest()
{
const FPoint p1 (1,2);
const FPoint p2 (2,4);
CPPUNIT_ASSERT ( p1 != p2 );
CPPUNIT_ASSERT ( FPoint(1,2) != p2 );
CPPUNIT_ASSERT ( p1 != FPoint(2,4) );
CPPUNIT_ASSERT ( FPoint() != p2 );
CPPUNIT_ASSERT ( p1 != FPoint() );
}
//----------------------------------------------------------------------
void FPointTest::additionTest()
{
const FPoint p1 (1,2);
const FPoint p2 (5,8);
const FPoint p3 = p1 + p2;
CPPUNIT_ASSERT ( p3.getX() == 6 );
CPPUNIT_ASSERT ( p3.getY() == 10 );
CPPUNIT_ASSERT ( p1 + p2 == FPoint(6,10) );
CPPUNIT_ASSERT ( p1 + FPoint() == p1 );
CPPUNIT_ASSERT ( FPoint() + p2 == p2 );
CPPUNIT_ASSERT ( FPoint() + FPoint() == FPoint() );
}
//----------------------------------------------------------------------
void FPointTest::subtractionTest()
{
const FPoint p1 (-5,-20);
const FPoint p2 (0,-30);
const FPoint p3 = p1 - p2;
CPPUNIT_ASSERT ( p3.getX() == -5 );
CPPUNIT_ASSERT ( p3.getY() == 10 );
CPPUNIT_ASSERT ( p1 - p2 == FPoint(-5,10) );
CPPUNIT_ASSERT ( p1 - FPoint() == p1 );
CPPUNIT_ASSERT ( FPoint() - FPoint() == FPoint() );
}
//----------------------------------------------------------------------
void FPointTest::referenceTest()
{
FPoint p1 (1,1);
CPPUNIT_ASSERT ( p1.getX() == 1 );
CPPUNIT_ASSERT ( p1.getY() == 1 );
p1.x_ref()++;
p1.y_ref()++;
CPPUNIT_ASSERT ( p1.getX() == 2 );
CPPUNIT_ASSERT ( p1.getY() == 2 );
short& x = p1.x_ref();
short& y = p1.y_ref();
x += 4;
y += 2;
CPPUNIT_ASSERT ( p1.getX() == 6 );
CPPUNIT_ASSERT ( p1.getY() == 4 );
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FPointTest);
// The general unit test main part
#include <main-test.inc>

View File

@ -95,6 +95,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture
// Adds code needed to register the test suite // Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (FStringTest); CPPUNIT_TEST_SUITE (FStringTest);
// Add a methods to the test suite
CPPUNIT_TEST (NoArgumentTest); CPPUNIT_TEST (NoArgumentTest);
CPPUNIT_TEST (initLengthTest); CPPUNIT_TEST (initLengthTest);
CPPUNIT_TEST (copyConstructorTest); CPPUNIT_TEST (copyConstructorTest);
@ -181,7 +182,6 @@ void FStringTest::NoArgumentTest()
CPPUNIT_ASSERT ( FString(std::wstring()).isEmpty() ); CPPUNIT_ASSERT ( FString(std::wstring()).isEmpty() );
CPPUNIT_ASSERT ( FString(wchar_t(0)).isEmpty() ); CPPUNIT_ASSERT ( FString(wchar_t(0)).isEmpty() );
CPPUNIT_ASSERT ( ! empty.includes('A') ); CPPUNIT_ASSERT ( ! empty.includes('A') );
CPPUNIT_ASSERT ( ! empty.includes(L'A') ); CPPUNIT_ASSERT ( ! empty.includes(L'A') );
CPPUNIT_ASSERT ( ! empty.includes("123") ); CPPUNIT_ASSERT ( ! empty.includes("123") );