diff --git a/tools/qfcc/test/Makefile.am b/tools/qfcc/test/Makefile.am index 23e366078..cf982bd69 100644 --- a/tools/qfcc/test/Makefile.am +++ b/tools/qfcc/test/Makefile.am @@ -1,4 +1,9 @@ AUTOMAKE_OPTIONS= foreign + +QFCC_LIBS=@QFCC_LIBS@ +QFCC_DEPS=@QFCC_DEPS@ +QFCC_INCS=@QFCC_INCS@ + AM_CPPFLAGS= -I$(top_srcdir)/include $(QFCC_INCS) QFCC_DEP=$(builddir)/../source/qfcc$(EXEEXT) @@ -18,6 +23,11 @@ QFCC_TEST_LIBS=@QFCC_TEST_LIBS@ QFCC_TEST_DEPS=@QFCC_TEST_DEPS@ QFCC_TEST_INCS=@QFCC_TEST_INCS@ +test_bins=\ + test-defspace + +fail_bins= + test_progs_dat=\ chewed-alias.dat \ chewed-return.dat \ @@ -40,10 +50,17 @@ test_progs_dat=\ fail_progs_dat= -TESTS=$(test_progs_dat:.dat=.run) -XFAIL_TESTS=$(fail_progs_dat:.dat=.run) +test_defspace_src=\ + tw-defspace.c tw-diagnostic.c tw-strpool.c -check_PROGRAMS=test-harness $(test_progs_dat) +TESTS=$(test_bins) $(test_progs_dat:.dat=.run) +XFAIL_TESTS=$(fail_bins) $(fail_progs_dat:.dat=.run) + +check_PROGRAMS=test-harness $(test_progs_dat) $(test_bins) + +test_defspace_SOURCES= test-defspace.c $(test_defspace_src) +test_defspace_LDADD= $(QFCC_LIBS) +test_defspace_DEPENDENCIES= $(QFCC_DEPS) test_harness_SOURCES= test-bi.c test-harness.c test_harness_LDADD= $(QFCC_TEST_LIBS) diff --git a/tools/qfcc/test/test-defspace.c b/tools/qfcc/test/test-defspace.c new file mode 100644 index 000000000..bc5f45077 --- /dev/null +++ b/tools/qfcc/test/test-defspace.c @@ -0,0 +1,110 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include + +#include "class.h" +#include "defspace.h" +#include "expr.h" +#include "function.h" +#include "options.h" +#include "strpool.h" +#include "qfcc.h" + +options_t options; +pr_info_t pr; +function_t *current_func; +class_type_t *current_class; + +const char * +get_class_name (class_type_t *class_type, int prett) +{ + return 0; +} + +expr_t * +new_expr (void) +{ + return calloc(1, sizeof (expr_t)); +} + +static int +check_init_state (const defspace_t *space, const char *name) +{ + int pass = 1; + + if (space->free_locs) { + printf ("%s free_locs not null\n", name); + pass = 0; + } + if (space->defs) { + printf ("%s defs not null\n", name); + pass = 0; + } + if (space->def_tail != &space->defs) { + printf ("%s def_tail not pointing to defs\n", name); + pass = 0; + } + if (space->data) { + printf ("%s data not null\n", name); + pass = 0; + } + if (space->size) { + printf ("%s size not 0\n", name); + pass = 0; + } + if (space->max_size) { + printf ("%s max_size not 0\n", name); + pass = 0; + } + if (!space->grow) { + printf ("%s grow is null\n", name); + pass = 0; + } + if (space->qfo_space) { + printf ("%s qfo_space not 0\n", name); + pass = 0; + } + return pass; +} + +static int +test_init (void) +{ + int pass = 1; + defspace_t *backed = defspace_new (ds_backed); + defspace_t *virtual = defspace_new (ds_virtual); + + if (backed->grow == virtual->grow) { + printf ("expected different grow functions for backed and virtual\n"); + pass = 0; + } + + if (backed->type != ds_backed) { + printf ("backed ds has wrong type\n"); + pass = 0; + } + + if (virtual->type != ds_virtual) { + printf ("virtual ds has wrong type\n"); + pass = 0; + } + + pass &= check_init_state (backed, "backed"); + pass &= check_init_state (virtual, "virtual"); + + return pass; +} + +int +main (int argc, const char **argv) +{ + pr.strings = strpool_new (); + + int pass = 1; + + pass &= test_init (); + + return !pass; +} diff --git a/tools/qfcc/test/tw-defspace.c b/tools/qfcc/test/tw-defspace.c new file mode 100644 index 000000000..c3b950324 --- /dev/null +++ b/tools/qfcc/test/tw-defspace.c @@ -0,0 +1 @@ +#include "../source/defspace.c" diff --git a/tools/qfcc/test/tw-diagnostic.c b/tools/qfcc/test/tw-diagnostic.c new file mode 100644 index 000000000..d84f8ad33 --- /dev/null +++ b/tools/qfcc/test/tw-diagnostic.c @@ -0,0 +1 @@ +#include "../source/diagnostic.c" diff --git a/tools/qfcc/test/tw-strpool.c b/tools/qfcc/test/tw-strpool.c new file mode 100644 index 000000000..74fbb8d75 --- /dev/null +++ b/tools/qfcc/test/tw-strpool.c @@ -0,0 +1 @@ +#include "../source/strpool.c"