diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2011-12-01 22:56:23 +0000 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2011-12-01 22:56:23 +0000 |
commit | 429e46051dba814e7d6c74368eb1bba550222cbe (patch) | |
tree | ed1dd43cd23c69f156aae2165006a16a66262cef /tinytest | |
parent | 58bf1382be0cbcf3f9649286fd2719b789a1595f (diff) | |
download | libconfig-faaa576c7d4f56a6633683e3261ae99582bf887a.tar.gz |
Imported Upstream version 1.4.8upstream/1.4.8
Diffstat (limited to '')
-rw-r--r-- | tinytest/Makefile.am | 6 | ||||
-rw-r--r-- | tinytest/Makefile.in (renamed from samples/c/Makefile.in) | 172 | ||||
-rw-r--r-- | tinytest/tinytest.c | 515 | ||||
-rw-r--r-- | tinytest/tinytest.h | 431 | ||||
-rw-r--r-- | tinytest/tinytest.vcproj | 168 |
5 files changed, 1206 insertions, 86 deletions
diff --git a/tinytest/Makefile.am b/tinytest/Makefile.am new file mode 100644 index 0000000..b49750d --- /dev/null +++ b/tinytest/Makefile.am @@ -0,0 +1,6 @@ + +noinst_LIBRARIES = libtinytest.a + +libtinytest_a_SOURCES = tinytest.c tinytest.h + +EXTRA_DIST = tinytest.vcproj diff --git a/samples/c/Makefile.in b/tinytest/Makefile.in index 1aaf2be..6b52eb8 100644 --- a/samples/c/Makefile.in +++ b/tinytest/Makefile.in @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -16,8 +17,9 @@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c @@ -33,37 +35,26 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ -noinst_PROGRAMS = stub$(EXEEXT) sample1$(EXEEXT) sample2$(EXEEXT) \ - sample3$(EXEEXT) -subdir = samples/c +subdir = tinytest DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +mkinstalldirs = $(SHELL) $(top_srcdir)/aux-build/mkinstalldirs CONFIG_HEADER = $(top_builddir)/ac_config.h CONFIG_CLEAN_FILES = -PROGRAMS = $(noinst_PROGRAMS) -am_sample1_OBJECTS = sample1.$(OBJEXT) -sample1_OBJECTS = $(am_sample1_OBJECTS) -sample1_LDADD = $(LDADD) -sample1_DEPENDENCIES = -am_sample2_OBJECTS = sample2.$(OBJEXT) -sample2_OBJECTS = $(am_sample2_OBJECTS) -sample2_LDADD = $(LDADD) -sample2_DEPENDENCIES = -am_sample3_OBJECTS = sample3.$(OBJEXT) -sample3_OBJECTS = $(am_sample3_OBJECTS) -sample3_LDADD = $(LDADD) -sample3_DEPENDENCIES = -am_stub_OBJECTS = stub.$(OBJEXT) -stub_OBJECTS = $(am_stub_OBJECTS) -stub_LDADD = $(LDADD) -stub_DEPENDENCIES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +ARFLAGS = cru +libtinytest_a_AR = $(AR) $(ARFLAGS) +libtinytest_a_LIBADD = +am_libtinytest_a_OBJECTS = tinytest.$(OBJEXT) +libtinytest_a_OBJECTS = $(am_libtinytest_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp +depcomp = $(SHELL) $(top_srcdir)/aux-build/depcomp am__depfiles_maybe = depfiles +am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ @@ -73,10 +64,8 @@ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = $(sample1_SOURCES) $(sample2_SOURCES) $(sample3_SOURCES) \ - $(stub_SOURCES) -DIST_SOURCES = $(sample1_SOURCES) $(sample2_SOURCES) \ - $(sample3_SOURCES) $(stub_SOURCES) +SOURCES = $(libtinytest_a_SOURCES) +DIST_SOURCES = $(libtinytest_a_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -102,20 +91,20 @@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ -ECHO = @ECHO@ +DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ +FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ LDFLAGS = @LDFLAGS@ LEX = @LEX@ LEXLIB = @LEXLIB@ @@ -123,18 +112,23 @@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ @@ -151,7 +145,7 @@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ @@ -201,12 +195,9 @@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -stub_SOURCES = stub.c -sample1_SOURCES = sample1.c -sample2_SOURCES = sample2.c -sample3_SOURCES = sample3.c -AM_CPPFLAGS = -I $(top_srcdir) -LDADD = -L../../.libs -lconfig +noinst_LIBRARIES = libtinytest.a +libtinytest_a_SOURCES = tinytest.c tinytest.h +EXTRA_DIST = tinytest.vcproj all: all-am .SUFFIXES: @@ -215,14 +206,14 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu samples/c/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu samples/c/Makefile + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tinytest/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu tinytest/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -240,25 +231,14 @@ $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): -clean-noinstPROGRAMS: - @list='$(noinst_PROGRAMS)'; for p in $$list; do \ - f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f $$p $$f"; \ - rm -f $$p $$f ; \ - done -sample1$(EXEEXT): $(sample1_OBJECTS) $(sample1_DEPENDENCIES) - @rm -f sample1$(EXEEXT) - $(LINK) $(sample1_OBJECTS) $(sample1_LDADD) $(LIBS) -sample2$(EXEEXT): $(sample2_OBJECTS) $(sample2_DEPENDENCIES) - @rm -f sample2$(EXEEXT) - $(LINK) $(sample2_OBJECTS) $(sample2_LDADD) $(LIBS) -sample3$(EXEEXT): $(sample3_OBJECTS) $(sample3_DEPENDENCIES) - @rm -f sample3$(EXEEXT) - $(LINK) $(sample3_OBJECTS) $(sample3_LDADD) $(LIBS) -stub$(EXEEXT): $(stub_OBJECTS) $(stub_DEPENDENCIES) - @rm -f stub$(EXEEXT) - $(LINK) $(stub_OBJECTS) $(stub_LDADD) $(LIBS) +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) +libtinytest.a: $(libtinytest_a_OBJECTS) $(libtinytest_a_DEPENDENCIES) + -rm -f libtinytest.a + $(libtinytest_a_AR) libtinytest.a $(libtinytest_a_OBJECTS) $(libtinytest_a_LIBADD) + $(RANLIB) libtinytest.a mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -266,28 +246,25 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sample1.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sample2.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sample3.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stub.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tinytest.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< @@ -303,14 +280,14 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) - tags=; \ + set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ @@ -318,29 +295,34 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) - tags=; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ + test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique + $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags @@ -361,19 +343,23 @@ distdir: $(DISTFILES) if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am -all-am: Makefile $(PROGRAMS) +all-am: Makefile $(LIBRARIES) installdirs: install: install-am install-exec: install-exec-am @@ -395,13 +381,14 @@ clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 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-am: clean-generic clean-libtool clean-noinstPROGRAMS \ +clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \ mostlyclean-am distclean: distclean-am @@ -416,6 +403,8 @@ dvi-am: html: html-am +html-am: + info: info-am info-am: @@ -424,18 +413,28 @@ install-data-am: install-dvi: install-dvi-am +install-dvi-am: + install-exec-am: install-html: install-html-am +install-html-am: + install-info: install-info-am +install-info-am: + install-man: install-pdf: install-pdf-am +install-pdf-am: + install-ps: install-ps-am +install-ps-am: + installcheck-am: maintainer-clean: maintainer-clean-am @@ -461,7 +460,7 @@ uninstall-am: .MAKE: install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool clean-noinstPROGRAMS ctags distclean \ + clean-libtool clean-noinstLIBRARIES ctags 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 \ @@ -473,6 +472,7 @@ uninstall-am: mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ pdf pdf-am ps ps-am tags uninstall uninstall-am + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/tinytest/tinytest.c b/tinytest/tinytest.c new file mode 100644 index 0000000..24d0c2f --- /dev/null +++ b/tinytest/tinytest.c @@ -0,0 +1,515 @@ +/* ---------------------------------------------------------------------------- + tinytest - A tiny C unit-testing library + Copyright (C) 2010 Mark A Lindner + + This file is part of tinytest. + + This library 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 2.1 of + the License, or (at your option) any later version. + + This library 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 Library General Public + License along with this library; if not, see + <http://www.gnu.org/licenses/>. + ---------------------------------------------------------------------------- +*/ + +#include "tinytest.h" + +#include <stdarg.h> +#include <stdio.h> + +/* + */ + +static tt_testsuite_t *__tt_current_suite = NULL; + +static const char *__tt_op_strings[] = { "==", "!=", "<", "<=", ">", ">=", + "==", "!=", "<", "<=", ">", ">=", + "==", "!=", "<", "<=", ">", ">=", + "==", "!=", "<", "<=", ">", ">=", + "==", "!=", "<", "<=", ">", ">=", + "==", "!=", "<", "<=", ">", ">=", + "==", "!=", "", "!", + "==file", "!=file" }; + +/* + */ + +static tt_bool_t __tt_compare_files(const char *file1, const char *file2, + tt_bool_t verbose) +{ + FILE *fp1, *fp2; + char buf1[4096], buf2[4096]; + int line = 1; + int character = 0; + size_t r1, r2; + tt_bool_t done = TT_FALSE, matched = TT_TRUE; + + if(!(fp1 = fopen(file1, "rb"))) + { + printf("cannot open file: %s\n", file1); + return(TT_FALSE); + } + + if(!(fp2 = fopen(file2, "rb"))) + { + fclose(fp1); + printf("cannot open file: %s\n", file2); + return(TT_FALSE); + } + + while(!done) + { + char *p, *q, *pe, *qe; + + r1 = fread(buf1, 1, sizeof(buf1), fp1); + r2 = fread(buf2, 1, sizeof(buf2), fp2); + + p = buf1; + q = buf2; + pe = buf1 + r1; + qe = buf2 + r2; + + while(p < pe && q < qe) + { + if(*p != *q) + { + matched = TT_FALSE; + done = TT_TRUE; + break; + } + + if(*p == '\n') + { + ++line; + character = 0; + } + else + ++character; + + ++p; + ++q; + } + + if(p < pe || q < qe) + { + matched = TT_FALSE; + break; + } + + if(feof(fp1) || feof(fp2)) + break; + } + + fclose(fp1); + fclose(fp2); + + if(!matched && verbose) + printf("files \"%s\" and \"%s\" differ starting at line %d, char %d\n", + file1, file2, line, character); + + return(matched); +} + +/* + */ + +tt_testsuite_t *tt_suite_create(const char *name) +{ + tt_testsuite_t *suite = calloc(1, sizeof(tt_testsuite_t)); + suite->name = strdup(name); + return(suite); +} + +/* + */ + +void tt_suite_destroy(tt_testsuite_t *suite) +{ + tt_test_t *test = suite->first_test; + + while(test) + { + tt_test_t *tmp = test->next; + free((void *)test->name); + free(test); + test = tmp; + } + + free((void *)suite->name); + free(suite); +} + +/* + */ + +void tt_suite_add_test(tt_testsuite_t *suite, const char *name, + void (*function)(void)) +{ + tt_test_t *test = calloc(1, sizeof(tt_test_t)); + test->name = strdup(name); + test->function = function; + + if(suite->last_test != NULL) + suite->last_test->next = test; + + suite->last_test = test; + + if(suite->first_test == NULL) + suite->first_test = test; + + ++suite->num_tests; +} + +/* + */ + +void tt_suite_run(tt_testsuite_t *suite) +{ + __tt_current_suite = suite; + + suite->num_failures = 0; + + for(suite->current_test = suite->first_test; + suite->current_test; + suite->current_test = suite->current_test->next) + { + printf("[TEST] %s\n", suite->current_test->name); + + if(setjmp(suite->jump_buf) == 0) + { + suite->current_test->function(); + } + + if(suite->current_test->failed) + { + printf("[FAIL] %s\n", suite->current_test->name); + ++suite->num_failures; + } + else + { + printf("[ OK ] %s\n", suite->current_test->name); + } + } + + if(suite->num_failures > 0) + puts("*** FAILURES! ***"); + + printf("%d tests; %d passed, %d failed\n", + suite->num_tests, suite->num_tests - suite->num_failures, + suite->num_failures); + + suite->current_test = NULL; + __tt_current_suite = NULL; +} + +/* + */ + +void tt_output_val(FILE *stream, const tt_val_t *val) +{ + switch(val->type) + { + case TT_VAL_INT: + fprintf(stream, "%d", val->value.int_val); + break; + + case TT_VAL_UINT: + fprintf(stream, "%u", val->value.uint_val); + break; + + case TT_VAL_INT64: + fprintf(stream, "%lld", val->value.int64_val); + break; + + case TT_VAL_UINT64: + fprintf(stream, "%llu", val->value.uint64_val); + break; + + case TT_VAL_DOUBLE: + fprintf(stream, "%f", val->value.double_val); + break; + + case TT_VAL_STR: + { + const char *p; + + fputc('\"', stream); + for(p = val->value.str_val; *p; ++p) + { + if(*p == '\n') + fputs("\\n", stream); + else if(*p == '\r') + fputs("\\r", stream); + else if(*p == '\t') + fputs("\\t", stream); + else if(*p == '\f') + fputs("\\f", stream); + else if(*p < ' ') + fprintf(stream, "\\0x%02X", *p); + else + fputc(*p, stream); + } + fputc('\"', stream); + break; + } + + case TT_VAL_PTR: + fprintf(stream, "%p", val->value.ptr_val); + break; + + default: + fputs("???", stream); + break; + } +} + +/* + */ + +void tt_expect(const char *file, int line, const char *aexpr, + tt_op_t op, const char *bexpr, const tt_val_t a, + const tt_val_t b, tt_bool_t fatal) +{ + tt_bool_t result = TT_FALSE; + + switch(op) + { + case TT_OP_INT_EQ: + result = (a.value.int_val == b.value.int_val); + break; + + case TT_OP_INT_NE: + result = (a.value.int_val != b.value.int_val); + break; + + case TT_OP_INT_LT: + result = (a.value.int_val < b.value.int_val); + break; + + case TT_OP_INT_LE: + result = (a.value.int_val <= b.value.int_val); + break; + + case TT_OP_INT_GT: + result = (a.value.int_val > b.value.int_val); + break; + + case TT_OP_INT_GE: + result = (a.value.int_val >= b.value.int_val); + break; + + case TT_OP_UINT_EQ: + result = (a.value.uint_val == b.value.uint_val); + break; + + case TT_OP_UINT_NE: + result = (a.value.uint_val != b.value.uint_val); + break; + + case TT_OP_UINT_LT: + result = (a.value.uint_val < b.value.uint_val); + break; + + case TT_OP_UINT_LE: + result = (a.value.uint_val <= b.value.uint_val); + break; + + case TT_OP_UINT_GT: + result = (a.value.uint_val > b.value.uint_val); + break; + + case TT_OP_UINT_GE: + result = (a.value.uint_val >= b.value.uint_val); + break; + + case TT_OP_INT64_EQ: + result = (a.value.int64_val == b.value.int64_val); + break; + + case TT_OP_INT64_NE: + result = (a.value.int64_val != b.value.int64_val); + break; + + case TT_OP_INT64_LT: + result = (a.value.int64_val < b.value.int64_val); + break; + + case TT_OP_INT64_LE: + result = (a.value.int64_val <= b.value.int64_val); + break; + + case TT_OP_INT64_GT: + result = (a.value.int64_val > b.value.int64_val); + break; + + case TT_OP_INT64_GE: + result = (a.value.int64_val >= b.value.int64_val); + break; + + case TT_OP_UINT64_EQ: + result = (a.value.uint64_val == b.value.uint64_val); + break; + + case TT_OP_UINT64_NE: + result = (a.value.uint64_val != b.value.uint64_val); + break; + + case TT_OP_UINT64_LT: + result = (a.value.uint64_val < b.value.uint64_val); + break; + + case TT_OP_UINT64_LE: + result = (a.value.uint64_val <= b.value.uint64_val); + break; + + case TT_OP_UINT64_GT: + result = (a.value.uint64_val > b.value.uint64_val); + break; + + case TT_OP_UINT64_GE: + result = (a.value.uint64_val >= b.value.uint64_val); + break; + + case TT_OP_DOUBLE_EQ: + result = (a.value.double_val == b.value.double_val); + break; + + case TT_OP_DOUBLE_NE: + { + double diff = (a.value.double_val - b.value.double_val); + result = ((diff < -.0001) || (diff > .0001)); + break; + } + + case TT_OP_DOUBLE_LT: + result = (a.value.double_val < b.value.double_val); + break; + + case TT_OP_DOUBLE_LE: + result = (a.value.double_val <= b.value.double_val); + break; + + case TT_OP_DOUBLE_GT: + result = (a.value.double_val > b.value.double_val); + break; + + case TT_OP_DOUBLE_GE: + result = (a.value.double_val >= b.value.double_val); + break; + + case TT_OP_STR_EQ: + result = !strcmp(a.value.str_val, b.value.str_val); + break; + + case TT_OP_STR_NE: + result = strcmp(a.value.str_val, b.value.str_val); + break; + + case TT_OP_STR_LT: + result = (strcmp(a.value.str_val, b.value.str_val) < 0); + break; + + case TT_OP_STR_LE: + result = (strcmp(a.value.str_val, b.value.str_val) <= 0); + break; + + case TT_OP_STR_GT: + result = (strcmp(a.value.str_val, b.value.str_val) > 0); + break; + + case TT_OP_STR_GE: + result = (strcmp(a.value.str_val, b.value.str_val) >= 0); + break; + + case TT_OP_PTR_EQ: + result = (a.value.ptr_val == b.value.ptr_val); + break; + + case TT_OP_PTR_NE: + result = (a.value.ptr_val != b.value.ptr_val); + break; + + case TT_OP_FILE_EQ: + result = __tt_compare_files(a.value.str_val, b.value.str_val, TT_TRUE); + break; + + case TT_OP_FILE_NE: + result = !__tt_compare_files(a.value.str_val, b.value.str_val, TT_TRUE); + break; + + default: + break; + } + + if(!result) + { + __tt_current_suite->current_test->failed = TT_TRUE; + + printf("%s:%d: failed %s: %s [", file, line, (fatal ? "assert" : "expect"), + aexpr); + tt_output_val(stdout, &a); + printf("] %s %s [", __tt_op_strings[op], bexpr); + tt_output_val(stdout, &b); + puts("]"); + + if(fatal) + longjmp(__tt_current_suite->jump_buf, 0); + } +} + +/* + */ + +void tt_expect_bool(const char *file, int line, const char *expr, tt_op_t op, + int val, tt_bool_t fatal) +{ + tt_bool_t result = TT_FALSE; + + switch(op) + { + case TT_OP_TRUE: + result = (val != 0); + break; + + case TT_OP_FALSE: + result = (val == 0); + break; + + default: + break; + } + + if(!result) + { + __tt_current_suite->current_test->failed = TT_TRUE; + + printf("%s:%d: failed %s: %s(%s)\n", file, line, + (fatal ? "assert" : "expect"), __tt_op_strings[op], expr); + + if(fatal) + longjmp(__tt_current_suite->jump_buf, 0); + } +} + +/* + */ + +void tt_fail(const char *file, int line, const char *message, ...) +{ + va_list vp; + va_start(vp, message); + printf("%s:%d: failed: ", file, line); + vprintf(message, vp); + va_end(vp); + putchar('\n'); +} + +/* end of source file */ diff --git a/tinytest/tinytest.h b/tinytest/tinytest.h new file mode 100644 index 0000000..29a95e8 --- /dev/null +++ b/tinytest/tinytest.h @@ -0,0 +1,431 @@ +/* ---------------------------------------------------------------------------- + tinytest - A tiny C unit-testing library + Copyright (C) 2010 Mark A Lindner + + This file is part of tinytest. + + This library 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 2.1 of + the License, or (at your option) any later version. + + This library 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 Library General Public + License along with this library; if not, see + <http://www.gnu.org/licenses/>. + ---------------------------------------------------------------------------- +*/ + +#ifndef __tinytest_h +#define __tinytest_h + +#include <setjmp.h> +#include <string.h> +#include <stdlib.h> + +typedef int tt_bool_t; + +#define TT_TRUE (1) +#define TT_FALSE (0) + +typedef struct tt_test_t +{ + const char *name; + void (*function)(void); + tt_bool_t failed; + struct tt_test_t *next; +} tt_test_t; + +typedef struct tt_testsuite_t +{ + const char *name; + tt_test_t *first_test; + tt_test_t *last_test; + tt_test_t *current_test; + int num_tests; + int num_failures; + jmp_buf jump_buf; +} tt_testsuite_t; + +typedef enum { TT_VAL_INT, TT_VAL_UINT, TT_VAL_INT64, TT_VAL_UINT64, + TT_VAL_DOUBLE, TT_VAL_STR, TT_VAL_PTR } tt_valtype_t; + +typedef enum { TT_OP_INT_EQ, TT_OP_INT_NE, TT_OP_INT_LT, TT_OP_INT_LE, + TT_OP_INT_GT, TT_OP_INT_GE, TT_OP_UINT_EQ, TT_OP_UINT_NE, + TT_OP_UINT_LT, TT_OP_UINT_LE, TT_OP_UINT_GT, TT_OP_UINT_GE, + TT_OP_INT64_EQ, TT_OP_INT64_NE, TT_OP_INT64_LT, TT_OP_INT64_LE, + TT_OP_INT64_GT, TT_OP_INT64_GE, TT_OP_UINT64_EQ, + TT_OP_UINT64_NE, TT_OP_UINT64_LT, TT_OP_UINT64_LE, + TT_OP_UINT64_GT, TT_OP_UINT64_GE, TT_OP_DOUBLE_EQ, + TT_OP_DOUBLE_NE, TT_OP_DOUBLE_LT, TT_OP_DOUBLE_LE, + TT_OP_DOUBLE_GT, TT_OP_DOUBLE_GE, TT_OP_STR_EQ, TT_OP_STR_NE, + TT_OP_STR_LT, TT_OP_STR_LE, TT_OP_STR_GT, TT_OP_STR_GE, + TT_OP_PTR_EQ, TT_OP_PTR_NE, TT_OP_TRUE, TT_OP_FALSE, + TT_OP_FILE_EQ, TT_OP_FILE_NE } tt_op_t; + +typedef struct tt_val_t +{ + tt_valtype_t type; + union { + int int_val; + unsigned int uint_val; + long long int64_val; + unsigned long long uint64_val; + double double_val; + const char *str_val; + const void *ptr_val; + } value; +} tt_val_t; + + +extern tt_testsuite_t *tt_suite_create(const char *name); + +extern void tt_suite_destroy(tt_testsuite_t *suite); + +extern void tt_suite_add_test(tt_testsuite_t *suite, const char *name, + void (*function)(void)); + +extern void tt_suite_run(tt_testsuite_t *suite); + +extern void tt_expect(const char *file, int line, const char *aexpr, + tt_op_t op, const char *bexpr, + const tt_val_t a, const tt_val_t b, + tt_bool_t fatal); + +extern void tt_expect_bool(const char *file, int line, const char *expr, + tt_op_t op, int val, tt_bool_t fatal); + +extern void tt_fail(const char *file, int line, const char *message, ...); + + +#define TT_TEST_INT_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_INT, .value.int_val = (A) }, \ + (tt_val_t){ TT_VAL_INT, .value.int_val = (B) }, \ + (F)) + +#define TT_EXPECT_INT_EQ(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_EQ, (B), TT_FALSE) + +#define TT_ASSERT_INT_EQ(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_EQ, (B), TT_TRUE) + +#define TT_EXPECT_INT_NE(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_NE, (B), TT_FALSE) + +#define TT_ASSERT_INT_NE(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_NE, (B), TT_TRUE) + +#define TT_EXPECT_INT_LT(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_LT, (B), TT_FALSE) + +#define TT_ASSERT_INT_LT(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_LT, (B), TT_TRUE) + +#define TT_EXPECT_INT_LE(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_LE, (B), TT_FALSE) + +#define TT_ASSERT_INT_LE(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_LE, (B), TT_TRUE) + +#define TT_EXPECT_INT_GT(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_GT, (B), TT_FALSE) + +#define TT_ASSERT_INT_GT(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_GT, (B), TT_TRUE) + +#define TT_EXPECT_INT_GE(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_GE, (B), TT_FALSE) + +#define TT_ASSERT_INT_GE(A, B) \ + TT_TEST_INT_((A), TT_OP_INT_GE, (B), TT_TRUE) + +#define TT_TEST_UINT_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_UINT, .value.uint_val = (A) }, \ + (tt_val_t){ TT_VAL_UINT, .value.uint_val = (B) }, \ + (F)) + +#define TT_EXPECT_UINT_EQ(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_EQ, (B), TT_FALSE) + +#define TT_ASSERT_UINT_EQ(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_EQ, (B), TT_TRUE) + +#define TT_EXPECT_UINT_NE(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_NE, (B), TT_FALSE) + +#define TT_ASSERT_UINT_NE(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_NE, (B), TT_TRUE) + +#define TT_EXPECT_UINT_LT(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_LT, (B), TT_FALSE) + +#define TT_ASSERT_UINT_LT(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_LT, (B), TT_TRUE) + +#define TT_EXPECT_UINT_LE(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_LE, (B), TT_FALSE) + +#define TT_ASSERT_UINT_LE(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_LE, (B), TT_TRUE) + +#define TT_EXPECT_UINT_GT(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_GT, (B), TT_FALSE) + +#define TT_ASSERT_UINT_GT(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_GT, (B), TT_TRUE) + +#define TT_EXPECT_UINT_GE(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_GE, (B), TT_FALSE) + +#define TT_ASSERT_UINT_GE(A, B) \ + TT_TEST_UINT_((A), TT_OP_UINT_GE, (B), TT_TRUE) + +#define TT_TEST_INT64_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_INT64, .value.int64_val = (A) }, \ + (tt_val_t){ TT_VAL_INT64, .value.int64_val = (B) }, \ + (F)) + +#define TT_EXPECT_INT64_EQ(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_EQ, (B), TT_FALSE) + +#define TT_ASSERT_INT64_EQ(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_EQ, (B), TT_TRUE) + +#define TT_EXPECT_INT64_NE(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_NE, (B), TT_FALSE) + +#define TT_ASSERT_INT64_NE(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_NE, (B), TT_TRUE) + +#define TT_EXPECT_INT64_LT(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_LT, (B), TT_FALSE) + +#define TT_ASSERT_INT64_LT(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_LT, (B), TT_TRUE) + +#define TT_EXPECT_INT64_LE(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_LE, (B), TT_FALSE) + +#define TT_ASSERT_INT64_LE(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_LE, (B), TT_TRUE) + +#define TT_EXPECT_INT64_GT(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_GT, (B), TT_FALSE) + +#define TT_ASSERT_INT64_GT(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_GT, (B), TT_TRUE) + +#define TT_EXPECT_INT64_GE(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_GE, (B), TT_FALSE) + +#define TT_ASSERT_INT64_GE(A, B) \ + TT_TEST_INT64_((A), TT_OP_INT64_GE, (B), TT_TRUE) + +#define TT_TEST_UINT64_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_UINT64, .value.uint64_val = (A) }, \ + (tt_val_t){ TT_VAL_UINT64, .value.uint64_val = (B) }, \ + (F)) + +#define TT_EXPECT_UINT64_EQ(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_EQ, (B), TT_FALSE) + +#define TT_ASSERT_UINT64_EQ(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_EQ, (B), TT_TRUE) + +#define TT_EXPECT_UINT64_NE(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_NE, (B), TT_FALSE) + +#define TT_ASSERT_UINT64_NE(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_NE, (B), TT_TRUE) + +#define TT_EXPECT_UINT64_LT(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_LT, (B), TT_FALSE) + +#define TT_ASSERT_UINT64_LT(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_LT, (B), TT_TRUE) + +#define TT_EXPECT_UINT64_LE(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_LE, (B), TT_FALSE) + +#define TT_ASSERT_UINT64_LE(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_LE, (B), TT_TRUE) + +#define TT_EXPECT_UINT64_GT(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_GT, (B), TT_FALSE) + +#define TT_ASSERT_UINT64_GT(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_GT, (B), TT_TRUE) + +#define TT_EXPECT_UINT64_GE(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_GE, (B), TT_FALSE) + +#define TT_ASSERT_UINT64_GE(A, B) \ + TT_TEST_UINT64_((A), TT_OP_UINT64_GE, (B), TT_TRUE) + +#define TT_TEST_DOUBLE_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_DOUBLE, .value.double_val = (A) }, \ + (tt_val_t){ TT_VAL_DOUBLE, .value.double_val = (B) }, \ + (F)) + +#define TT_EXPECT_DOUBLE_EQ(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_EQ, (B), TT_FALSE) + +#define TT_ASSERT_DOUBLE_EQ(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_EQ, (B), TT_TRUE) + +#define TT_EXPECT_DOUBLE_NE(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_NE, (B), TT_FALSE) + +#define TT_ASSERT_DOUBLE_NE(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_NE, (B), TT_TRUE) + +#define TT_EXPECT_DOUBLE_LT(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_LT, (B), TT_FALSE) + +#define TT_ASSERT_DOUBLE_LT(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_LT, (B), TT_TRUE) + +#define TT_EXPECT_DOUBLE_LE(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_LE, (B), TT_FALSE) + +#define TT_ASSERT_DOUBLE_LE(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_LE, (B), TT_TRUE) + +#define TT_EXPECT_DOUBLE_GT(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_GT, (B), TT_FALSE) + +#define TT_ASSERT_DOUBLE_GT(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_GT, (B), TT_TRUE) + +#define TT_EXPECT_DOUBLE_GE(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_GE, (B), TT_FALSE) + +#define TT_ASSERT_DOUBLE_GE(A, B) \ + TT_TEST_DOUBLE_((A), TT_OP_DOUBLE_GE, (B), TT_TRUE) + +#define TT_TEST_STR_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_STR, .value.str_val = (A) }, \ + (tt_val_t){ TT_VAL_STR, .value.str_val = (B) }, \ + (F)) + +#define TT_EXPECT_STR_EQ(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_EQ, (B), TT_FALSE) + +#define TT_ASSERT_STR_EQ(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_EQ, (B), TT_TRUE) + +#define TT_EXPECT_STR_NE(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_NE, (B), TT_FALSE) + +#define TT_ASSERT_STR_NE(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_NE, (B), TT_TRUE) + +#define TT_EXPECT_STR_LT(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_LT, (B), TT_FALSE) + +#define TT_ASSERT_STR_LT(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_LT, (B), TT_TRUE) + +#define TT_EXPECT_STR_LE(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_LE, (B), TT_FALSE) + +#define TT_ASSERT_STR_LE(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_LE, (B), TT_TRUE) + +#define TT_EXPECT_STR_GT(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_GT, (B), TT_FALSE) + +#define TT_ASSERT_STR_GT(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_GT, (B), TT_TRUE) + +#define TT_EXPECT_STR_GE(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_GE, (B), TT_FALSE) + +#define TT_ASSERT_STR_GE(A, B) \ + TT_TEST_STR_((A), TT_OP_STR_GE, (B), TT_TRUE) + +#define TT_TEST_PTR_(A, OP, B, F) \ + tt_expect(__FILE__, __LINE__, #A, OP, #B, \ + (tt_val_t){ TT_VAL_PTR, .value.ptr_val = (A) }, \ + (tt_val_t){ TT_VAL_PTR, .value.ptr_val = (B) }, \ + (F)) + +#define TT_EXPECT_PTR_EQ(A, B) \ + TT_TEST_PTR_((A), TT_OP_PTR_EQ, (B), TT_FALSE) + +#define TT_ASSERT_PTR_EQ(A, B) \ + TT_TEST_PTR_((A), TT_OP_PTR_EQ, (B), TT_TRUE) + +#define TT_EXPECT_PTR_NE(A, B) \ + TT_TEST_PTR_((A), TT_OP_PTR_NE, (B), TT_FALSE) + +#define TT_ASSERT_PTR_NE(A, B) \ + TT_TEST_PTR_((A), TT_OP_PTR_NE, (B), TT_TRUE) + +#define TT_EXPECT_PTR_NOTNULL(A) \ + TT_TEST_PTR_((A), TT_OP_PTR_NE, NULL, TT_FALSE) + +#define TT_ASSERT_PTR_NOTNULL(A) \ + TT_TEST_PTR_((A), TT_OP_PTR_NE, NULL, TT_TRUE) + +#define TT_EXPECT_PTR_NULL(A) \ + TT_TEST_PTR_((A), TT_OP_PTR_EQ, NULL, TT_FALSE) + +#define TT_ASSERT_PTR_NULL(A) \ + TT_TEST_PTR_((A), TT_OP_PTR_EQ, NULL, TT_TRUE) + +#define TT_EXPECT_TRUE(A) \ + tt_expect_bool(__FILE__, __LINE__, #A, TT_OP_TRUE, (A), TT_FALSE) + +#define TT_ASSERT_TRUE(A) \ + tt_expect_bool(__FILE__, __LINE__, #A, TT_OP_TRUE, (A), TT_TRUE) + +#define TT_EXPECT_FALSE(A) \ + tt_expect_bool(__FILE__, __LINE__, #A, TT_OP_FALSE, (A), TT_FALSE) + +#define TT_ASSERT_FALSE(A) \ + tt_expect_bool(__FILE__, __LINE__, #A, TT_OP_FALSE, (A), TT_TRUE) + +#define TT_EXPECT_FILE_EQ(A, B) \ + TT_TEST_STR_((A), TT_OP_FILE_EQ, (B), TT_FALSE) + +#define TT_ASSERT_FILE_EQ(A, B) \ + TT_TEST_STR_((A), TT_OP_FILE_EQ, (B), TT_TRUE) + +#define TT_EXPECT_FILE_NE(A, B) \ + TT_TEST_STR_((A), TT_OP_FILE_NE, (B), TT_FALSE) + +#define TT_ASSERT_FILE_NE(A, B) \ + TT_TEST_STR_((A), TT_OP_FILE_NE, (B), TT_TRUE) + + +#define TT_FAIL(M, ...) \ + tt_fail(__FILE__, __LINE__, (M), __VA_ARGS__) + +#define TT_SUITE_START(S) \ + tt_testsuite_t *__suite__ ## S = tt_suite_create(#S) + +#define TT_SUITE_TEST(S, F) \ + tt_suite_add_test(__suite__ ## S, #F, F); + +#define TT_TEST(F) \ + static void F(void) + +#define TT_SUITE_END(S) \ + tt_suite_destroy(__suite__ ## S) + +#define TT_SUITE_RUN(S) \ + tt_suite_run(__suite__ ## S) + + +#endif // __tinytest_h diff --git a/tinytest/tinytest.vcproj b/tinytest/tinytest.vcproj new file mode 100644 index 0000000..109089e --- /dev/null +++ b/tinytest/tinytest.vcproj @@ -0,0 +1,168 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="libtinytest"
+ ProjectGUID="{58F43D41-FE56-40E1-BB83-9CB8CDE0B7AA}"
+ RootNamespace="libtinytest"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ProjectName)\$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="."
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ DisableSpecificWarnings="4996"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ProjectName)\$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="."
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ DisableSpecificWarnings="4996"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ >
+ <File
+ RelativePath=".\tinytest.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ >
+ <File
+ RelativePath=".\tinytest.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
|