Start work on a unit test for defspace.

This commit is contained in:
Bill Currie 2018-09-09 22:37:09 +09:00
parent 3a4667318c
commit 05fd2d8cdd
5 changed files with 133 additions and 3 deletions

View file

@ -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)

View file

@ -0,0 +1,110 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#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;
}

View file

@ -0,0 +1 @@
#include "../source/defspace.c"

View file

@ -0,0 +1 @@
#include "../source/diagnostic.c"

View file

@ -0,0 +1 @@
#include "../source/strpool.c"