diff options
Diffstat (limited to 'tinytest')
-rw-r--r-- | tinytest/Makefile.am | 6 | ||||
-rw-r--r-- | tinytest/Makefile.in | 478 | ||||
-rw-r--r-- | tinytest/tinytest.c | 515 | ||||
-rw-r--r-- | tinytest/tinytest.h | 431 | ||||
-rw-r--r-- | tinytest/tinytest.vcproj | 168 |
5 files changed, 1598 insertions, 0 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/tinytest/Makefile.in b/tinytest/Makefile.in new file mode 100644 index 0000000..6b52eb8 --- /dev/null +++ b/tinytest/Makefile.in @@ -0,0 +1,478 @@ +# 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, 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. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@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 +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +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)/aux-build/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/ac_config.h +CONFIG_CLEAN_FILES = +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)/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) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libtinytest_a_SOURCES) +DIST_SOURCES = $(libtinytest_a_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +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@ +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@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +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_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LIBRARIES = libtinytest.a +libtinytest_a_SOURCES = tinytest.c tinytest.h +EXTRA_DIST = tinytest.vcproj +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(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 ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + 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 \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(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-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) + +distclean-compile: + -rm -f *.tab.c + +@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@ $(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@ $(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@ $(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 $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + 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; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + 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; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + 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) + 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)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + 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 -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +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-noinstLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +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 + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + 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 \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + 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>
|