From 3f0f262bc87035546d41cec089ba81fd0fd5f99c Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 27 Feb 2018 00:45:02 +0100 Subject: [PATCH] Unit tests update --- .codedocs | 1 + examples/string-operations.cpp | 1 - src/Makefile.am | 4 + src/Makefile.in | 179 +++++++++++++++++++++++++++------ src/test/fstring-test.cpp | 54 ++++++++-- 5 files changed, 200 insertions(+), 39 deletions(-) diff --git a/.codedocs b/.codedocs index 11be9fc9..5b2b06cb 100644 --- a/.codedocs +++ b/.codedocs @@ -1,3 +1,4 @@ PROJECT_NAME = "The Final Cut" EXCLUDE = debian, icon, logo, m4, scripts, examples +EXCLUDE_PATTERNS = */test/* diff --git a/examples/string-operations.cpp b/examples/string-operations.cpp index 5c080c31..03c2ad7f 100644 --- a/examples/string-operations.cpp +++ b/examples/string-operations.cpp @@ -232,7 +232,6 @@ void streamToInterger() { std::cerr << "Arithmetic error: " << ex.what() << std::endl; } - } //---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 17a0f70c..30ea0473 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,6 +4,8 @@ AM_CPPFLAGS = -I../include -Wall -Werror -DCOMPILE_FINAL_CUT +SUBDIRS = . test + lib_LTLIBRARIES = libfinal.la libfinal_la_SOURCES = \ @@ -109,5 +111,7 @@ finalcutinclude_HEADERS = \ clean-local: -find . \( -name "*.gcda" -o -name "*.gcno" -o -name "*.gcov" \) -delete +test: check + #uninstall: # rm -R -f $(includedir)/final diff --git a/src/Makefile.in b/src/Makefile.in index 170df16a..3ccb2c50 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -183,12 +183,28 @@ am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_1 = SOURCES = $(libfinal_la_SOURCES) DIST_SOURCES = $(libfinal_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac HEADERS = $(finalcutinclude_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is @@ -208,7 +224,33 @@ am__define_uniq_tagged_files = \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CXXFLAGS = @AM_CXXFLAGS@ @@ -336,6 +378,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CPPFLAGS = -I../include -Wall -Werror -DCOMPILE_FINAL_CUT +SUBDIRS = . test lib_LTLIBRARIES = libfinal.la libfinal_la_SOURCES = \ fstring.cpp \ @@ -435,7 +478,7 @@ finalcutinclude_HEADERS = \ ../include/final/fwidget.h \ ../include/final/fwindow.h -all: all-am +all: all-recursive .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj @@ -605,14 +648,61 @@ uninstall-finalcutincludeHEADERS: files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(finalcutincludedir)'; $(am__uninstall_files_from_dir) +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique -tags: tags-am +tags: tags-recursive TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ @@ -625,7 +715,7 @@ tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $$unique; \ fi; \ fi -ctags: ctags-am +ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) @@ -638,7 +728,7 @@ GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscopelist: cscopelist-am +cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ @@ -687,22 +777,48 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done check-am: all-am -check: check-am +check: check-recursive all-am: Makefile $(LTLIBRARIES) $(HEADERS) -installdirs: +installdirs: installdirs-recursive +installdirs-am: for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(finalcutincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -installcheck: installcheck-am +installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ @@ -724,83 +840,84 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -clean: clean-am +clean: clean-recursive clean-am: clean-generic clean-libLTLIBRARIES clean-libtool clean-local \ mostlyclean-am -distclean: distclean-am +distclean: distclean-recursive -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags -dvi: dvi-am +dvi: dvi-recursive dvi-am: -html: html-am +html: html-recursive html-am: -info: info-am +info: info-recursive info-am: install-data-am: install-finalcutincludeHEADERS -install-dvi: install-dvi-am +install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-libLTLIBRARIES -install-html: install-html-am +install-html: install-html-recursive install-html-am: -install-info: install-info-am +install-info: install-info-recursive install-info-am: install-man: -install-pdf: install-pdf-am +install-pdf: install-pdf-recursive install-pdf-am: -install-ps: install-ps-am +install-ps: install-ps-recursive install-ps-am: installcheck-am: -maintainer-clean: maintainer-clean-am +maintainer-clean: maintainer-clean-recursive -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic -mostlyclean: mostlyclean-am +mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool -pdf: pdf-am +pdf: pdf-recursive pdf-am: -ps: ps-am +ps: ps-recursive ps-am: uninstall-am: uninstall-finalcutincludeHEADERS \ uninstall-libLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: $(am__recursive_targets) install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ - clean-libLTLIBRARIES clean-libtool clean-local cscopelist-am \ - ctags ctags-am distclean distclean-compile distclean-generic \ +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ + check-am clean clean-generic clean-libLTLIBRARIES \ + clean-libtool clean-local cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ @@ -808,7 +925,7 @@ uninstall-am: uninstall-finalcutincludeHEADERS \ install-html-am install-info install-info-am \ install-libLTLIBRARIES install-man install-pdf install-pdf-am \ install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ + installcheck-am installdirs installdirs-am maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am \ @@ -818,6 +935,8 @@ uninstall-am: uninstall-finalcutincludeHEADERS \ clean-local: -find . \( -name "*.gcda" -o -name "*.gcno" -o -name "*.gcov" \) -delete +test: check + #uninstall: # rm -R -f $(includedir)/final diff --git a/src/test/fstring-test.cpp b/src/test/fstring-test.cpp index 98aae8bd..414341fc 100644 --- a/src/test/fstring-test.cpp +++ b/src/test/fstring-test.cpp @@ -28,8 +28,6 @@ #include #include -#include - #include #include #include @@ -38,6 +36,7 @@ #include #include +#include //---------------------------------------------------------------------- // class FStringTest @@ -51,12 +50,13 @@ class FStringTest : public CPPUNIT_NS::TestFixture public: FStringTest() { } - + void setUp(); void tearDown(); protected: - void NoArgument(); + void NoArgumentTest(); + void caseTest(); void equalTest(); void exceptionTest(); @@ -66,7 +66,8 @@ class FStringTest : public CPPUNIT_NS::TestFixture // Adds code needed to register the test suite CPPUNIT_TEST_SUITE (FStringTest); - CPPUNIT_TEST (NoArgument); + CPPUNIT_TEST (NoArgumentTest); + CPPUNIT_TEST (caseTest); CPPUNIT_TEST (equalTest); CPPUNIT_TEST (exceptionTest); @@ -87,7 +88,7 @@ void FStringTest::tearDown() delete s; } //---------------------------------------------------------------------- -void FStringTest::NoArgument() +void FStringTest::NoArgumentTest() { FString empty; CPPUNIT_ASSERT ( empty.isNull() ); @@ -106,7 +107,7 @@ void FStringTest::NoArgument() CPPUNIT_ASSERT ( str.length() == 0 ); CPPUNIT_ASSERT ( str.size() == 0 ); CPPUNIT_ASSERT ( str.empty() ); - FString fstr = str; + const FString fstr = str; CPPUNIT_ASSERT ( fstr == empty ); CPPUNIT_ASSERT ( empty == '\0' ); CPPUNIT_ASSERT ( empty == L'\0' ); @@ -131,17 +132,54 @@ void FStringTest::NoArgument() // Fill the empty string with "123" empty << "123"; CPPUNIT_ASSERT_EQUAL ( empty, FString(L"123") ); + + empty.clear(); + CPPUNIT_ASSERT ( empty.isNull() ); +} + +//---------------------------------------------------------------------- +void FStringTest::caseTest() +{ + FString str1("abc"); + CPPUNIT_ASSERT ( str1.toUpper() == "ABC" ); + + FString str2("XYZ"); + CPPUNIT_ASSERT ( str2.toLower() == "xyz" ); } //---------------------------------------------------------------------- void FStringTest::equalTest() { // std::string -> FString -> std::string - std::string s1; + const std::string s1 = "abc"; FString s2 = s1; std::string s3 = s2.toString(); CPPUNIT_ASSERT ( s1 == s3 ); + FString one_char('a'); + const char ch = 'a'; + CPPUNIT_ASSERT ( one_char == ch ); + CPPUNIT_ASSERT ( ch == one_char.c_str()[0] ); + CPPUNIT_ASSERT ( one_char.getLength() == 1 ); + + const wchar_t wch = L'a'; + CPPUNIT_ASSERT ( one_char == wch ); + CPPUNIT_ASSERT ( wch == one_char.wc_str()[0] ); + + FString str(L"abc"); + const char cstr[] = "abc"; + CPPUNIT_ASSERT ( str == cstr ); + CPPUNIT_ASSERT ( str.getLength() == 3 ); + CPPUNIT_ASSERT ( str.getUTF8length() == 3 ); + CPPUNIT_ASSERT ( strncmp(cstr, str.c_str(), 3) == 0 ); + + const wchar_t wcstr[] = L"abc"; + CPPUNIT_ASSERT ( str == wcstr ); + CPPUNIT_ASSERT ( wcsncmp(wcstr, str.wc_str(), 3) == 0 ); + + FString str2(L"abc"); + CPPUNIT_ASSERT ( str == str2 ); + CPPUNIT_ASSERT ( s->getLength() == 1 ); CPPUNIT_ASSERT ( s->c_str()[0] == 'c'); CPPUNIT_ASSERT ( s->c_str()[0] != 's');