From 04b270fd7b1e63fb30c45f661a7492020526f0a9 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 1 Feb 2006 19:26:02 +0000 Subject: [PATCH] * flower/test-std.cc: Add simple unit test for vector migration. * stepmake/stepmake/test*: Unit test support. --- ChangeLog | 4 +++ flower/GNUmakefile | 13 +-------- flower/include/std-vector.hh | 15 ++++++---- flower/test-std.cc | 45 +++++++++++++++++++++++++++++ stepmake/stepmake/test-rules.make | 11 +++++++ stepmake/stepmake/test-targets.make | 6 ++++ stepmake/stepmake/test-vars.make | 5 ++++ 7 files changed, 82 insertions(+), 17 deletions(-) create mode 100644 flower/test-std.cc create mode 100644 stepmake/stepmake/test-rules.make create mode 100644 stepmake/stepmake/test-targets.make create mode 100644 stepmake/stepmake/test-vars.make diff --git a/ChangeLog b/ChangeLog index fa887d06d7..df45f6d6c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-02-01 Jan Nieuwenhuizen + * flower/test-std.cc: Add simple unit test for vector migration. + + * stepmake/stepmake/test*: Unit test support. + * flower/include/std-vector.hh (del): Remove. Use erase (), update callers. diff --git a/flower/GNUmakefile b/flower/GNUmakefile index 9a36eea33f..6c78043142 100644 --- a/flower/GNUmakefile +++ b/flower/GNUmakefile @@ -1,8 +1,3 @@ -# title top level makefile for FlowerLib -# file flower/Makefile - -# should reinstate versioning if shared libs are enabled. - depth = .. NAME = flower @@ -12,12 +7,6 @@ SUBDIRS = include SCRIPTS = README_FILES = NEWS-1.0 NEWS-1.1.46 README TODO EXTRA_DIST_FILES= VERSION $(README_FILES) $(SCRIPTS) -STEPMAKE_TEMPLATES=library c++ po - - +STEPMAKE_TEMPLATES=library c++ po test include $(depth)/make/stepmake.make - -foo: - echo $(DIST_FILES) $(O_FILES) $(OBJECT_FILES) - diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index ce88a5d628..db6cb9241e 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -260,6 +260,7 @@ namespace std { return VPOS; } #endif + } @@ -268,14 +269,18 @@ namespace std { namespace std { +#ifndef Array #define vector Array - using namespace std; +#endif - #ifndef VSIZE - #define VSIZE + using namespace std; + +#ifndef VSIZE +#define VSIZE typedef int vsize; - #define VPOS -1 - #endif +#define VPOS -1 +#endif + } diff --git a/flower/test-std.cc b/flower/test-std.cc new file mode 100644 index 0000000000..85e0a372fa --- /dev/null +++ b/flower/test-std.cc @@ -0,0 +1,45 @@ +#if !STD_VECTOR +#define Array flower_vector +#endif +#include "std-vector.hh" + +#include + +#include +#include + +using boost::unit_test::test_suite; + +template +void +print (vector v) +{ + for (vsize i = 0; i < v.size (); i++) + cout << "v[" << i << "] = " << v[i] << endl; +} + +BOOST_AUTO_UNIT_TEST (vector_erase) +{ + vector v; + v.push_back (0); + v.push_back (1); + BOOST_CHECK_EQUAL (v.size (), 2u); + v.erase (v.begin () + 1); + BOOST_CHECK_EQUAL (v.size (), 1u); + BOOST_CHECK_EQUAL (v.back (), 0); + + v.push_back (1); + BOOST_CHECK_EQUAL (v.size (), 2u); + v.erase (v.begin () + 0); + BOOST_CHECK_EQUAL (v.size (), 1u); + BOOST_CHECK_EQUAL (v.back (), 1); +} + + +test_suite* +init_unit_test_suite (int, char**) +{ + test_suite *test = BOOST_TEST_SUITE("std::Flower"); + test->add (BOOST_TEST_CASE (vector_erase)); + return test; +} diff --git a/stepmake/stepmake/test-rules.make b/stepmake/stepmake/test-rules.make new file mode 100644 index 0000000000..d733dbbe69 --- /dev/null +++ b/stepmake/stepmake/test-rules.make @@ -0,0 +1,11 @@ + +define MODULE_LIB_template \ +$(1)/$(outdir)/library.a : \ + $(MAKE) -C $(1) +endef + +$(foreach a, $(MODULE_LIBS), $(eval $(call MODULE_LIB_template,$(a)))) + +$(TEST_EXECUTABLE): $(outdir)/config.hh $(TEST_O_FILES) $(TEST_MODULE_LIBS:%=%/$(outdir)/library.a) + $(foreach a, $(TEST_MODULE_LIBS), $(MAKE) -C $(a) && ) true + $(LD) -o $@ $(TEST_O_FILES) $(TEST_LOADLIBES) $(ALL_LDFLAGS) diff --git a/stepmake/stepmake/test-targets.make b/stepmake/stepmake/test-targets.make new file mode 100644 index 0000000000..fd74538aae --- /dev/null +++ b/stepmake/stepmake/test-targets.make @@ -0,0 +1,6 @@ +.PHONY: check test + +check: test + +test: $(TEST_EXECUTABLE) + $(TEST_EXECUTABLE) diff --git a/stepmake/stepmake/test-vars.make b/stepmake/stepmake/test-vars.make new file mode 100644 index 0000000000..ffabc1bd29 --- /dev/null +++ b/stepmake/stepmake/test-vars.make @@ -0,0 +1,5 @@ +TEST_O_FILES := $(filter $(outdir)/test%, $(O_FILES)) +O_FILES := $(filter-out $(outdir)/test%, $(O_FILES)) + +TEST_EXECUTABLE = $(outdir)/test-$(NAME) +TEST_LOADLIBES = $(LOADLIBES) -lboost_unit_test_framework -- 2.39.2