From b53f133381ef6ffa9f7ecefbf4d134d55ad94455 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 7 Feb 2011 17:30:20 +0100 Subject: Add unit test for reflist --- Makefile.am | 6 +++ Makefile.in | 152 ++++++++++++++++++++++++++++++++++++++++++++++++----- tests/.gitignore | 4 ++ tests/list_check.c | 129 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 277 insertions(+), 14 deletions(-) create mode 100644 tests/.gitignore create mode 100644 tests/list_check.c diff --git a/Makefile.am b/Makefile.am index 81cc91a5..0761af9a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,6 +7,10 @@ bin_PROGRAMS = src/pattern_sim src/process_hkl src/get_hkl src/indexamajig \ src/calibrate_detector src/partialator src/reintegrate \ src/estimate_background src/check_hkl +noinst_PROGRAMS = tests/list_check + +TESTS = tests/list_check + if HAVE_GTK bin_PROGRAMS += src/hdfsee endif @@ -98,6 +102,8 @@ src_reintegrate_SOURCES = src/reintegrate.c src/cell.c src/hdf5-file.c \ src_estimate_background_SOURCES = src/estimate_background.c src/stream.c \ src/utils.c src/cell.c src/thread-pool.c +tests_list_check_SOURCES = tests/list_check.c src/reflist.c + INCLUDES = "-I$(top_srcdir)/data" EXTRA_DIST += src/cell.h src/hdf5-file.h src/image.h src/utils.h \ diff --git a/Makefile.in b/Makefile.in index 71045159..48b858ca 100644 --- a/Makefile.in +++ b/Makefile.in @@ -42,6 +42,8 @@ bin_PROGRAMS = src/pattern_sim$(EXEEXT) src/process_hkl$(EXEEXT) \ src/partialator$(EXEEXT) src/reintegrate$(EXEEXT) \ src/estimate_background$(EXEEXT) src/check_hkl$(EXEEXT) \ $(am__EXEEXT_1) $(am__EXEEXT_2) +noinst_PROGRAMS = tests/list_check$(EXEEXT) +TESTS = tests/list_check$(EXEEXT) @HAVE_GTK_TRUE@am__append_1 = src/hdfsee @HAVE_CAIRO_TRUE@am__append_2 = src/cubeit @HAVE_OPENCL_TRUE@am__append_3 = src/diffraction-gpu.c src/cl-utils.c @@ -77,7 +79,7 @@ CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(crystfeldir)" \ "$(DESTDIR)$(crystfeldocdir)" "$(DESTDIR)$(hdfseedir)" \ "$(DESTDIR)$(scriptdir)" -PROGRAMS = $(bin_PROGRAMS) +PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS) am__dirstamp = $(am__leading_dot)dirstamp am_src_calibrate_detector_OBJECTS = src/calibrate_detector.$(OBJEXT) \ src/utils.$(OBJEXT) src/hdf5-file.$(OBJEXT) \ @@ -222,6 +224,11 @@ am_src_render_hkl_OBJECTS = src/render_hkl.$(OBJEXT) \ src_render_hkl_OBJECTS = $(am_src_render_hkl_OBJECTS) src_render_hkl_LDADD = $(LDADD) src_render_hkl_DEPENDENCIES = $(top_builddir)/lib/libgnu.a +am_tests_list_check_OBJECTS = tests/list_check.$(OBJEXT) \ + src/reflist.$(OBJEXT) +tests_list_check_OBJECTS = $(am_tests_list_check_OBJECTS) +tests_list_check_LDADD = $(LDADD) +tests_list_check_DEPENDENCIES = $(top_builddir)/lib/libgnu.a DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp am__depfiles_maybe = depfiles @@ -248,7 +255,8 @@ SOURCES = $(src_calibrate_detector_SOURCES) $(src_check_hkl_SOURCES) \ $(src_hdfsee_SOURCES) $(src_indexamajig_SOURCES) \ $(src_partialator_SOURCES) $(src_pattern_sim_SOURCES) \ $(src_powder_plot_SOURCES) $(src_process_hkl_SOURCES) \ - $(src_reintegrate_SOURCES) $(src_render_hkl_SOURCES) + $(src_reintegrate_SOURCES) $(src_render_hkl_SOURCES) \ + $(tests_list_check_SOURCES) DIST_SOURCES = $(src_calibrate_detector_SOURCES) \ $(src_check_hkl_SOURCES) $(src_compare_hkl_SOURCES) \ $(am__src_cubeit_SOURCES_DIST) \ @@ -257,7 +265,7 @@ DIST_SOURCES = $(src_calibrate_detector_SOURCES) \ $(am__src_indexamajig_SOURCES_DIST) $(src_partialator_SOURCES) \ $(am__src_pattern_sim_SOURCES_DIST) $(src_powder_plot_SOURCES) \ $(src_process_hkl_SOURCES) $(src_reintegrate_SOURCES) \ - $(src_render_hkl_SOURCES) + $(src_render_hkl_SOURCES) $(tests_list_check_SOURCES) RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ html-recursive info-recursive install-data-recursive \ install-dvi-recursive install-exec-recursive \ @@ -295,6 +303,8 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ distdir dist dist-all distcheck ETAGS = etags CTAGS = ctags +am__tty_colors = \ +red=; grn=; lgn=; blu=; std= DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) @@ -628,6 +638,7 @@ src_reintegrate_SOURCES = src/reintegrate.c src/cell.c src/hdf5-file.c \ src_estimate_background_SOURCES = src/estimate_background.c src/stream.c \ src/utils.c src/cell.c src/thread-pool.c +tests_list_check_SOURCES = tests/list_check.c src/reflist.c INCLUDES = "-I$(top_srcdir)/data" hdfseedir = $(datadir)/hdfsee hdfsee_DATA = data/displaywindow.ui @@ -753,6 +764,9 @@ uninstall-binPROGRAMS: clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +clean-noinstPROGRAMS: + -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) src/$(am__dirstamp): @$(MKDIR_P) src @: > src/$(am__dirstamp) @@ -878,6 +892,17 @@ src/povray.$(OBJEXT): src/$(am__dirstamp) \ src/render_hkl$(EXEEXT): $(src_render_hkl_OBJECTS) $(src_render_hkl_DEPENDENCIES) src/$(am__dirstamp) @rm -f src/render_hkl$(EXEEXT) $(AM_V_CCLD)$(LINK) $(src_render_hkl_OBJECTS) $(src_render_hkl_LDADD) $(LIBS) +tests/$(am__dirstamp): + @$(MKDIR_P) tests + @: > tests/$(am__dirstamp) +tests/$(DEPDIR)/$(am__dirstamp): + @$(MKDIR_P) tests/$(DEPDIR) + @: > tests/$(DEPDIR)/$(am__dirstamp) +tests/list_check.$(OBJEXT): tests/$(am__dirstamp) \ + tests/$(DEPDIR)/$(am__dirstamp) +tests/list_check$(EXEEXT): $(tests_list_check_OBJECTS) $(tests_list_check_DEPENDENCIES) tests/$(am__dirstamp) + @rm -f tests/list_check$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(tests_list_check_OBJECTS) $(tests_list_check_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -923,6 +948,7 @@ mostlyclean-compile: -rm -f src/templates.$(OBJEXT) -rm -f src/thread-pool.$(OBJEXT) -rm -f src/utils.$(OBJEXT) + -rm -f tests/list_check.$(OBJEXT) distclean-compile: -rm -f *.tab.c @@ -969,6 +995,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/templates.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/thread-pool.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/utils.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/list_check.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -1203,6 +1230,98 @@ GTAGS: distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + echo "$$grn$$dashes"; \ + else \ + echo "$$red$$dashes"; \ + fi; \ + echo "$$banner"; \ + test -z "$$skipped" || echo "$$skipped"; \ + test -z "$$report" || echo "$$report"; \ + echo "$$dashes$$std"; \ + test "$$failed" -eq 0; \ + else :; fi + distdir: $(DISTFILES) $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @@ -1379,6 +1498,7 @@ distcleancheck: distclean $(distcleancheck_listfiles) ; \ exit 1; } >&2 check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-recursive all-am: Makefile $(PROGRAMS) $(DATA) config.h installdirs: installdirs-recursive @@ -1409,17 +1529,20 @@ distclean-generic: -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) -rm -f src/$(DEPDIR)/$(am__dirstamp) -rm -f src/$(am__dirstamp) + -rm -f tests/$(DEPDIR)/$(am__dirstamp) + -rm -f tests/$(am__dirstamp) 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-recursive -clean-am: clean-binPROGRAMS clean-generic mostlyclean-am +clean-am: clean-binPROGRAMS clean-generic clean-noinstPROGRAMS \ + mostlyclean-am distclean: distclean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) - -rm -rf src/$(DEPDIR) + -rm -rf src/$(DEPDIR) tests/$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-hdr distclean-tags @@ -1468,7 +1591,7 @@ installcheck-am: maintainer-clean: maintainer-clean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(top_srcdir)/autom4te.cache - -rm -rf src/$(DEPDIR) + -rm -rf src/$(DEPDIR) tests/$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1488,17 +1611,18 @@ uninstall-am: uninstall-binPROGRAMS uninstall-crystfelDATA \ uninstall-crystfeldocDATA uninstall-hdfseeDATA \ uninstall-scriptDATA -.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \ +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all check-am \ ctags-recursive install-am install-strip tags-recursive .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ - all all-am am--refresh check check-am clean clean-binPROGRAMS \ - clean-generic ctags ctags-recursive dist dist-all dist-bzip2 \ - dist-gzip dist-lzma dist-shar dist-tarZ dist-xz dist-zip \ - distcheck distclean distclean-compile distclean-generic \ - distclean-hdr distclean-tags distcleancheck distdir \ - distuninstallcheck dvi dvi-am html html-am info info-am \ - install install-am install-binPROGRAMS install-crystfelDATA \ + all all-am am--refresh check check-TESTS check-am clean \ + clean-binPROGRAMS clean-generic clean-noinstPROGRAMS ctags \ + ctags-recursive dist dist-all dist-bzip2 dist-gzip dist-lzma \ + dist-shar dist-tarZ dist-xz dist-zip distcheck distclean \ + distclean-compile distclean-generic distclean-hdr \ + distclean-tags distcleancheck distdir distuninstallcheck dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-crystfelDATA \ install-crystfeldocDATA install-data install-data-am \ install-dvi install-dvi-am install-exec install-exec-am \ install-hdfseeDATA install-html install-html-am install-info \ diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..3c726461 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,4 @@ +*.o +.deps +list_check +.dirstamp diff --git a/tests/list_check.c b/tests/list_check.c new file mode 100644 index 00000000..be427af0 --- /dev/null +++ b/tests/list_check.c @@ -0,0 +1,129 @@ +/* + * list_check.c + * + * Unit test for the reflection list module + * + * (c) 2011 Thomas White + * + * Part of CrystFEL - crystallography with a FEL + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + + +#include +#include + +#include "../src/reflist.h" + + +struct refltemp { + signed int h; + signed int k; + signed int l; + int del; + int dup; +}; + +#define RANDOM_INDEX (128*random()/RAND_MAX - 256*random()/RAND_MAX) + + +static int test_lists(int num_items) +{ + struct refltemp *check; + RefList *list; + int i; + + check = malloc(num_items * sizeof(struct refltemp)); + list = reflist_new(); + + for ( i=0; i