From bada6666c70977a058755ccf232e7d67b24adeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 15:21:29 +0200 Subject: New upstream release --- libcutl/tests/Makefile.am | 5 + libcutl/tests/compiler/cxx-indenter/driver.cxx | 168 ++++++++++++++ libcutl/tests/compiler/cxx-indenter/makefile | 70 ++++++ libcutl/tests/compiler/cxx-indenter/output.std | 103 ++++++++ libcutl/tests/compiler/makefile | 17 ++ libcutl/tests/compiler/sloc-counter/driver.cxx | 36 +++ libcutl/tests/compiler/sloc-counter/makefile | 70 ++++++ libcutl/tests/compiler/sloc-counter/test.cxx | 34 +++ libcutl/tests/compiler/sloc-counter/test.std | 36 +++ libcutl/tests/compiler/traversal/driver.cxx | 139 +++++++++++ libcutl/tests/compiler/traversal/makefile | 70 ++++++ libcutl/tests/compiler/traversal/output.std | 16 ++ libcutl/tests/container/makefile | 17 ++ libcutl/tests/container/multi-index/driver.cxx | 292 +++++++++++++++++++++++ libcutl/tests/container/multi-index/makefile | 69 ++++++ libcutl/tests/fs/makefile | 17 ++ libcutl/tests/fs/path/driver.cxx | 144 ++++++++++++ libcutl/tests/fs/path/makefile | 69 ++++++ libcutl/tests/makefile | 26 +++ libcutl/tests/re/driver.cxx | 83 +++++++ libcutl/tests/re/makefile | 69 ++++++ libcutl/tests/shared-ptr/driver.cxx | 185 +++++++++++++++ libcutl/tests/shared-ptr/makefile | 69 ++++++ libcutl/tests/xml/makefile | 17 ++ libcutl/tests/xml/parser/driver.cxx | 310 +++++++++++++++++++++++++ libcutl/tests/xml/parser/makefile | 69 ++++++ libcutl/tests/xml/roundtrip/attribute.xml | 3 + libcutl/tests/xml/roundtrip/characters.xml | 84 +++++++ libcutl/tests/xml/roundtrip/driver.cxx | 127 ++++++++++ libcutl/tests/xml/roundtrip/followup-1.xml | 8 + libcutl/tests/xml/roundtrip/followup-2.xml | 1 + libcutl/tests/xml/roundtrip/makefile | 74 ++++++ libcutl/tests/xml/roundtrip/namespace.xml | 6 + libcutl/tests/xml/serializer/driver.cxx | 63 +++++ libcutl/tests/xml/serializer/makefile | 69 ++++++ 35 files changed, 2635 insertions(+) create mode 100644 libcutl/tests/Makefile.am create mode 100644 libcutl/tests/compiler/cxx-indenter/driver.cxx create mode 100644 libcutl/tests/compiler/cxx-indenter/makefile create mode 100644 libcutl/tests/compiler/cxx-indenter/output.std create mode 100644 libcutl/tests/compiler/makefile create mode 100644 libcutl/tests/compiler/sloc-counter/driver.cxx create mode 100644 libcutl/tests/compiler/sloc-counter/makefile create mode 100644 libcutl/tests/compiler/sloc-counter/test.cxx create mode 100644 libcutl/tests/compiler/sloc-counter/test.std create mode 100644 libcutl/tests/compiler/traversal/driver.cxx create mode 100644 libcutl/tests/compiler/traversal/makefile create mode 100644 libcutl/tests/compiler/traversal/output.std create mode 100644 libcutl/tests/container/makefile create mode 100644 libcutl/tests/container/multi-index/driver.cxx create mode 100644 libcutl/tests/container/multi-index/makefile create mode 100644 libcutl/tests/fs/makefile create mode 100644 libcutl/tests/fs/path/driver.cxx create mode 100644 libcutl/tests/fs/path/makefile create mode 100644 libcutl/tests/makefile create mode 100644 libcutl/tests/re/driver.cxx create mode 100644 libcutl/tests/re/makefile create mode 100644 libcutl/tests/shared-ptr/driver.cxx create mode 100644 libcutl/tests/shared-ptr/makefile create mode 100644 libcutl/tests/xml/makefile create mode 100644 libcutl/tests/xml/parser/driver.cxx create mode 100644 libcutl/tests/xml/parser/makefile create mode 100644 libcutl/tests/xml/roundtrip/attribute.xml create mode 100644 libcutl/tests/xml/roundtrip/characters.xml create mode 100644 libcutl/tests/xml/roundtrip/driver.cxx create mode 100644 libcutl/tests/xml/roundtrip/followup-1.xml create mode 100644 libcutl/tests/xml/roundtrip/followup-2.xml create mode 100644 libcutl/tests/xml/roundtrip/makefile create mode 100644 libcutl/tests/xml/roundtrip/namespace.xml create mode 100644 libcutl/tests/xml/serializer/driver.cxx create mode 100644 libcutl/tests/xml/serializer/makefile (limited to 'libcutl/tests') diff --git a/libcutl/tests/Makefile.am b/libcutl/tests/Makefile.am new file mode 100644 index 0000000..8c4a4c8 --- /dev/null +++ b/libcutl/tests/Makefile.am @@ -0,0 +1,5 @@ +# file : Makefile.am +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +SUBDIRS = __path__(dirs) diff --git a/libcutl/tests/compiler/cxx-indenter/driver.cxx b/libcutl/tests/compiler/cxx-indenter/driver.cxx new file mode 100644 index 0000000..665c6ab --- /dev/null +++ b/libcutl/tests/compiler/cxx-indenter/driver.cxx @@ -0,0 +1,168 @@ +// file : tests/compiler/cxx-indenter/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +using namespace std; +using namespace cutl::compiler; + +int +main () +{ + //std::wostream& os (wcout); + //ostream_filter filt (os); + + std::ostream& os (cout); + ostream_filter filt (os); + + os << "if (true)" + << "{" + << "// Hello there" << endl + << "//" << endl + << "a ();" + << "}" + << "else" + << "{" + << "b ();" + << "}"; + + os << "if (true)" << endl + << "// Hello there" << endl + << "//" << endl + << "a ();" + << "else" << endl + << "b ();" + << endl; + + os << "if (false)" + << "{" + << "if (true)" + << "{" + << "// test" << endl + << "}" + << "else" + << "{" + << "// test" << endl + << "b ();" + << "}" + << "}"; + + os << "namespace a" + << "{" + << "void f ();" + << "}" + << "#if defined(__HP_aCC) && __HP_aCC <= 39999" << endl + << "#include " << endl + << "#endif" << endl + << endl + << "namespace b" + << "{" + << "void f ();" + << "}"; + + // Test do-while handling. + // + os << "do" << endl + << "f ();" + << "while (false);" + << endl; + + os << "do" + << "{" + << "f ();" + << "}" + << "while (false);" + << endl; + + os << "do" + << "{" + << "if (f ())" + << "{" + << "g ();" + << "}" + << "}" + << "while (false);" + << endl; + + os << "do" + << "{" + << "do" << endl + << "f ();" + << "while (false);" + << "}" + << "while (false);" + << endl; + + os << "do" + << "{" + << "do" + << "{" + << "f ();" + << "}" + << "while (false);" + << "}" + << "while (false);" + << endl; + + os << "{" + << "f (\"CREATE TABLE \\\"test\\\" (\"" << endl + << "\"'id',\"" << endl + << "\"'name')\");" + << "}"; + + os << "namespace N" + << "{" + << "static int i[] = {{0,\n0},{1,\n1}};" + << "}"; + +/* + @@ TODO: still misindents (if-else association problem) + + os << "{" + << "if (foo != bar)" << endl + << "if (foo (bar))" << endl + << "baz = true;" + << "else" << endl + << "baz = false;" + << "else" << endl + << "biz = true;" + << endl + << "biz = false;" + << "}"; + + os << "{" + << "if (foo != bar)" << endl + << "if (foo (bar))" + << "{" + << "baz = true;" + + << "if (x)" << endl + << "test ();" + << "else" << endl + << "test ();" + << endl + + << "if (x)" << endl + << "if (y)" + << "{" + << "test ();" + << "}" + << "else" + << "{" + << "test ();" + << "}" + + << "}" + << "else" + << "{" + << "test ();" + << "}" + << "biz = false;" + << "}"; +*/ +} diff --git a/libcutl/tests/compiler/cxx-indenter/makefile b/libcutl/tests/compiler/cxx-indenter/makefile new file mode 100644 index 0000000..da5dbe0 --- /dev/null +++ b/libcutl/tests/compiler/cxx-indenter/makefile @@ -0,0 +1,70 @@ +# file : tests/compiler/cxx-indenter/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output.std + $(call message,test $$1,$$1 | diff -u $(src_base)/output.std -,$(driver)) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/compiler/cxx-indenter/output.std b/libcutl/tests/compiler/cxx-indenter/output.std new file mode 100644 index 0000000..79e74f4 --- /dev/null +++ b/libcutl/tests/compiler/cxx-indenter/output.std @@ -0,0 +1,103 @@ +if (true) +{ + // Hello there + // + a (); +} +else +{ + b (); +} + +if (true) + // Hello there + // + a (); +else + b (); + +if (false) +{ + if (true) + { + // test + } + else + { + // test + b (); + } +} + +namespace a +{ + void f (); +} + +#if defined(__HP_aCC) && __HP_aCC <= 39999 +#include +#endif + +namespace b +{ + void f (); +} + +do + f (); +while (false); + +do +{ + f (); +} +while (false); + +do +{ + if (f ()) + { + g (); + } +} +while (false); + +do +{ + do + f (); + while (false); +} +while (false); + +do +{ + do + { + f (); + } + while (false); +} +while (false); + +{ + f ("CREATE TABLE \"test\" (" + "'id'," + "'name')"); +} + +namespace N +{ + static int i[] = + { + { + 0, + 0 + }, + { + 1, + 1 + } + }; +} + diff --git a/libcutl/tests/compiler/makefile b/libcutl/tests/compiler/makefile new file mode 100644 index 0000000..11506fd --- /dev/null +++ b/libcutl/tests/compiler/makefile @@ -0,0 +1,17 @@ +# file : tests/compiler/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +tests := cxx-indenter sloc-counter traversal + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/libcutl/tests/compiler/sloc-counter/driver.cxx b/libcutl/tests/compiler/sloc-counter/driver.cxx new file mode 100644 index 0000000..504fbb7 --- /dev/null +++ b/libcutl/tests/compiler/sloc-counter/driver.cxx @@ -0,0 +1,36 @@ +// file : tests/compiler/sloc-counter/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +using namespace std; +using namespace cutl::compiler; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " " << endl; + return 1; + } + + ostream_filter filt (cout); + + ifstream ifs(argv[1]); + + for (istream::int_type c (ifs.get ()); + c != istream::traits_type::eof (); + c = ifs.get ()) + { + cout.put (istream::traits_type::to_char_type (c)); + } + + cout << endl + << filt.stream ().count () << endl; +} diff --git a/libcutl/tests/compiler/sloc-counter/makefile b/libcutl/tests/compiler/sloc-counter/makefile new file mode 100644 index 0000000..74c9a4a --- /dev/null +++ b/libcutl/tests/compiler/sloc-counter/makefile @@ -0,0 +1,70 @@ +# file : tests/compiler/sloc-counter/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.cxx $(src_base)/test.std + $(call message,test $$1,$$1 $(src_base)/test.cxx | diff -u $(src_base)/test.std -,$(driver)) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/compiler/sloc-counter/test.cxx b/libcutl/tests/compiler/sloc-counter/test.cxx new file mode 100644 index 0000000..ff0f5b2 --- /dev/null +++ b/libcutl/tests/compiler/sloc-counter/test.cxx @@ -0,0 +1,34 @@ +// C++ comment + // C++ comment + +/* C comment */ + +/* Multiline + C + Comment + + +*/ + +#include + +char str[] = "multi\ +line\ +string\ +literal"; + +using namespace std; + + +int main( + int argc /*count*/, + char* argv[] /*array*/) +{ + /* comment start */ int x = 0; + char* s = + /* comment start */"foo"; + int y = 2 + /* tricky stuff *// + 2; + cerr << "Hello, \"world!" << '\'' << endl; +} diff --git a/libcutl/tests/compiler/sloc-counter/test.std b/libcutl/tests/compiler/sloc-counter/test.std new file mode 100644 index 0000000..00b9c31 --- /dev/null +++ b/libcutl/tests/compiler/sloc-counter/test.std @@ -0,0 +1,36 @@ +// C++ comment + // C++ comment + +/* C comment */ + +/* Multiline + C + Comment + + +*/ + +#include + +char str[] = "multi\ +line\ +string\ +literal"; + +using namespace std; + + +int main( + int argc /*count*/, + char* argv[] /*array*/) +{ + /* comment start */ int x = 0; + char* s = + /* comment start */"foo"; + int y = 2 + /* tricky stuff *// + 2; + cerr << "Hello, \"world!" << '\'' << endl; +} + +18 diff --git a/libcutl/tests/compiler/traversal/driver.cxx b/libcutl/tests/compiler/traversal/driver.cxx new file mode 100644 index 0000000..b1fea74 --- /dev/null +++ b/libcutl/tests/compiler/traversal/driver.cxx @@ -0,0 +1,139 @@ +// file : tests/compiler/traversal/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include + +#include +#include + +using namespace std; +using namespace cutl; + +// Data types. +// +struct base +{ + virtual ~base () {} +}; + +struct derived1: base {}; +struct derived2: base {}; + +typedef vector > objects; + +struct init +{ + init () + { + using compiler::type_info; + + { + type_info ti (typeid (base)); + insert (ti); + } + + { + type_info ti (typeid (derived1)); + ti.add_base (typeid (base)); + insert (ti); + } + + { + type_info ti (typeid (derived2)); + ti.add_base (typeid (base)); + insert (ti); + } + } +} init_; + +// Traversers. +// +template +struct traverser: compiler::traverser_impl, + virtual compiler::dispatcher +{ + void + add_traverser (compiler::traverser_map& m) + { + compiler::dispatcher::traverser (m); + } +}; + +typedef traverser base_trav; +typedef traverser derived1_trav; +typedef traverser derived2_trav; + +struct base_impl: base_trav +{ + virtual void + traverse (type&) + { + cout << "base_impl: base" << endl; + } +}; + +struct derived1_impl: derived1_trav +{ + virtual void + traverse (type&) + { + cout << "derived1_impl: derived1" << endl; + } +}; + +struct combined_impl: derived1_trav, derived2_trav +{ + virtual void + traverse (derived1&) + { + cout << "combined_impl: derived1" << endl; + } + + virtual void + traverse (derived2&) + { + cout << "combined_impl: derived2" << endl; + } +}; + +int +main () +{ + objects o; + o.push_back (shared_ptr (new (shared) base)); + o.push_back (shared_ptr (new (shared) derived1)); + o.push_back (shared_ptr (new (shared) derived2)); + + base_impl base; + derived1_impl derived1; + combined_impl combined; + + for (objects::iterator i (o.begin ()); i != o.end (); ++i) + base.dispatch (**i); + + cout << endl; + + for (objects::iterator i (o.begin ()); i != o.end (); ++i) + derived1.dispatch (**i); + + cout << endl; + + for (objects::iterator i (o.begin ()); i != o.end (); ++i) + combined.dispatch (**i); + + cout << endl; + + base.add_traverser (derived1); + for (objects::iterator i (o.begin ()); i != o.end (); ++i) + base.dispatch (**i); + + cout << endl; + + derived1.add_traverser (combined); + for (objects::iterator i (o.begin ()); i != o.end (); ++i) + derived1.dispatch (**i); +} diff --git a/libcutl/tests/compiler/traversal/makefile b/libcutl/tests/compiler/traversal/makefile new file mode 100644 index 0000000..f1c0fcf --- /dev/null +++ b/libcutl/tests/compiler/traversal/makefile @@ -0,0 +1,70 @@ +# file : tests/compiler/traversal/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output.std + $(call message,test $$1,$$1 | diff -u $(src_base)/output.std -,$(driver)) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/compiler/traversal/output.std b/libcutl/tests/compiler/traversal/output.std new file mode 100644 index 0000000..095739c --- /dev/null +++ b/libcutl/tests/compiler/traversal/output.std @@ -0,0 +1,16 @@ +base_impl: base +base_impl: base +base_impl: base + +derived1_impl: derived1 + +combined_impl: derived1 +combined_impl: derived2 + +base_impl: base +derived1_impl: derived1 +base_impl: base + +derived1_impl: derived1 +combined_impl: derived1 +combined_impl: derived2 diff --git a/libcutl/tests/container/makefile b/libcutl/tests/container/makefile new file mode 100644 index 0000000..b81d01e --- /dev/null +++ b/libcutl/tests/container/makefile @@ -0,0 +1,17 @@ +# file : tests/container/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +tests := multi-index + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/libcutl/tests/container/multi-index/driver.cxx b/libcutl/tests/container/multi-index/driver.cxx new file mode 100644 index 0000000..289ec4a --- /dev/null +++ b/libcutl/tests/container/multi-index/driver.cxx @@ -0,0 +1,292 @@ +// file : tests/container/multi-index/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace cutl::container; + +struct person +{ + person (const string& e, const string& f, const string& l, unsigned short a) + : email (e), first (f), last (l), age (a) {} + + const string email; + const string first; + const string last; + unsigned short age; +}; + +struct person_email_set +{ + typedef map, person> email_map; + typedef map_const_iterator const_iterator; + + pair + insert (const person& v) + { + pair r ( + email_map_.insert (email_map::value_type (v.email, v))); + + const_iterator i (r.first); + + if (r.second) + r.first->first.assign (i->email); + + return make_pair (i, r.second); + } + + const_iterator + find (const string& email) const + { + return email_map_.find (email); + } + + const_iterator begin () const {return email_map_.begin ();} + const_iterator end () const {return email_map_.end ();} + +private: + email_map email_map_; +}; + +struct person_name_set +{ + typedef key name_key; + typedef map name_map; + typedef map_const_iterator const_iterator; + + pair + insert (const person& v) + { + pair r ( + name_map_.insert ( + name_map::value_type (name_key (v.first, v.last), v))); + + const_iterator i (r.first); + + if (r.second) + r.first->first.assign (i->first, i->last); + + return make_pair (i, r.second); + } + + const_iterator + find (const string& first, const string& last) const + { + return name_map_.find (name_key (first, last)); + } + + const_iterator begin () const {return name_map_.begin ();} + const_iterator end () const {return name_map_.end ();} + +private: + name_map name_map_; +}; + +struct person_email_name_set +{ + typedef key name_key; + typedef map name_map; + typedef map_iterator iterator; + typedef map_const_iterator const_iterator; + + typedef map, iterator> email_map; + + pair + insert (const person& v) + { + // First check that we don't have any collisions in the secondary + // indexes. + // + { + email_map::iterator i (email_map_.find (v.email)); + + if (i != email_map_.end ()) + return make_pair (i->second, false); + } + + pair r ( + name_map_.insert ( + name_map::value_type (name_key (v.first, v.last), v))); + + iterator i (r.first); + + if (r.second) + { + r.first->first.assign (i->first, i->last); + email_map_.insert (email_map::value_type (i->email, i)); + } + + return make_pair (i, r.second); + } + + iterator + find (const string& first, const string& last) + { + return name_map_.find (name_key (first, last)); + } + + const_iterator + find (const string& first, const string& last) const + { + return name_map_.find (name_key (first, last)); + } + + iterator + find (const string& email) + { + email_map::iterator i (email_map_.find (email)); + return i != email_map_.end () ? i->second : end (); + } + + const_iterator + find (const string& email) const + { + email_map::const_iterator i (email_map_.find (email)); + return i != email_map_.end () ? i->second : end (); + } + + void + erase (iterator i ) + { + email_map_.erase (i->email); + name_map_.erase (i); + } + + iterator begin () {return name_map_.begin ();} + const_iterator begin () const {return name_map_.begin ();} + + iterator end () {return name_map_.end ();} + const_iterator end () const {return name_map_.end ();} + +private: + name_map name_map_; + email_map email_map_; +}; + +struct person_list_email_set +{ + typedef list person_list; + typedef person_list::iterator iterator; + typedef person_list::const_iterator const_iterator; + + typedef map, iterator> email_map; + + pair + insert (const person& v) + { + // First check that we don't have any collisions in the secondary + // indexes. + // + { + email_map::iterator i (email_map_.find (v.email)); + + if (i != email_map_.end ()) + return make_pair (i->second, false); + } + + iterator i (person_list_.insert (end (), v)); + email_map_.insert (email_map::value_type (i->email, i)); + return make_pair (i, true); + } + + iterator + find (const string& email) + { + email_map::iterator i (email_map_.find (email)); + return i != email_map_.end () ? i->second : end (); + } + + const_iterator + find (const string& email) const + { + email_map::const_iterator i (email_map_.find (email)); + return i != email_map_.end () ? i->second : end (); + } + + iterator begin () {return person_list_.begin ();} + const_iterator begin () const {return person_list_.begin ();} + + iterator end () {return person_list_.end ();} + const_iterator end () const {return person_list_.end ();} + +private: + person_list person_list_; + email_map email_map_; +}; + +int +main () +{ + { + person_email_set s; + + assert (s.insert (person ("john@doe.com", "John", "Doe", 20)).second); + assert (s.insert (person ("jane@doe.com", "Jane", "Doe", 21)).second); + assert (!s.insert (person ("john@doe.com", "Johnny", "Doe", 22)).second); + + assert (s.find ("john@doe.com") != s.end ()); + assert (s.find ("jane@doe.com") != s.end ()); + assert (s.find ("john@doe.org") == s.end ()); + } + + { + person_name_set s; + + assert (s.insert (person ("john@doe.com", "John", "Doe", 20)).second); + assert (s.insert (person ("jane@doe.com", "Jane", "Doe", 21)).second); + assert (!s.insert (person ("john@doe.org", "John", "Doe", 22)).second); + + assert (s.find ("John", "Doe") != s.end ()); + assert (s.find ("Jane", "Doe") != s.end ()); + assert (s.find ("Johnny", "Doe") == s.end ()); + } + + { + person_email_name_set s; + person_email_name_set const& cs (s); + + assert (s.insert (person ("john@doe.com", "John", "Doe", 20)).second); + assert (s.insert (person ("jane@doe.com", "Jane", "Doe", 21)).second); + assert (!s.insert (person ("john@doe.org", "John", "Doe", 22)).second); + assert (!s.insert (person ("john@doe.com", "Johnny", "Doe", 23)).second); + + assert (s.find ("John", "Doe") != s.end ()); + assert (cs.find ("Jane", "Doe") != cs.end ()); + assert (s.find ("john@doe.com") != s.end ()); + assert (cs.find ("jane@doe.com") != s.end ()); + assert (s.find ("Johnny", "Doe") == s.end ()); + assert (cs.find ("john@doe.org") == s.end ()); + + person_email_name_set::iterator i (s.find ("John", "Doe")); + i->age++; + + s.erase (i); + assert (s.find ("John", "Doe") == s.end ()); + assert (s.find ("john@doe.com") == s.end ()); + } + + { + person_list_email_set s; + + assert (s.insert (person ("john@doe.com", "John", "Doe", 20)).second); + assert (s.insert (person ("jane@doe.com", "Jane", "Doe", 21)).second); + assert (!s.insert (person ("john@doe.com", "Johnny", "Doe", 22)).second); + + assert (s.find ("john@doe.com") != s.end ()); + assert (s.find ("jane@doe.com") != s.end ()); + assert (s.find ("jane@doe.org") == s.end ()); + + person_list_email_set::iterator i (s.begin ()); + assert (i != s.end () && i->email == "john@doe.com"); + assert (++i != s.end () && i->email == "jane@doe.com"); + assert (++i == s.end ()); + } +} diff --git a/libcutl/tests/container/multi-index/makefile b/libcutl/tests/container/multi-index/makefile new file mode 100644 index 0000000..d5b805f --- /dev/null +++ b/libcutl/tests/container/multi-index/makefile @@ -0,0 +1,69 @@ +# file : tests/container/multi-index/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/fs/makefile b/libcutl/tests/fs/makefile new file mode 100644 index 0000000..9bf1523 --- /dev/null +++ b/libcutl/tests/fs/makefile @@ -0,0 +1,17 @@ +# file : tests/fs/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +tests := path + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/libcutl/tests/fs/path/driver.cxx b/libcutl/tests/fs/path/driver.cxx new file mode 100644 index 0000000..6c77e67 --- /dev/null +++ b/libcutl/tests/fs/path/driver.cxx @@ -0,0 +1,144 @@ +// file : tests/fs/path/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include + +using std::cerr; +using std::endl; + +using namespace cutl::fs; + +int +main () +{ + assert (path ("/").string () == "/"); + assert (path ("//").string () == "/"); + assert (path ("/tmp/foo/").string () == "/tmp/foo"); +#ifdef _WIN32 + assert (path ("\\\\").string () == "\\"); + assert (path ("/\\").string () == "/"); + assert (path ("C:").string () == "C:"); + assert (path ("C:\\").string () == "C:"); + assert (path ("C:\\tmp\\foo\\").string () == "C:\\tmp\\foo"); +#endif + + // abslote/relative/root + // +#ifndef _WIN32 + assert (path ("/").root ()); + assert (path ("//").root ()); + assert (path ("/").absolute ()); + assert (path ("/foo/bar").absolute ()); + assert (path ("bar/baz").relative ()); +#else + assert (path ("C:").root ()); + assert (path ("C:\\").root ()); + assert (path ("C:\\").absolute ()); + assert (path ("C:\\foo\\bar").absolute ()); + assert (path ("bar\\baz").relative ()); +#endif + + + // leaf + // +#ifndef _WIN32 + assert (path ("/").leaf ().string () == ""); + assert (path ("/tmp").leaf ().string () == "tmp"); + assert (path ("//tmp").leaf ().string () == "tmp"); +#else + assert (path ("C:").leaf ().string () == "C:"); + assert (path ("C:\\tmp").leaf ().string () == "tmp"); + assert (path ("C:\\\\tmp").leaf ().string () == "tmp"); +#endif + + // directory + // +#ifndef _WIN32 + assert (path ("/").directory ().string () == ""); + assert (path ("/tmp").directory ().string () == "/"); + assert (path ("//tmp").directory ().string () == "/"); +#else + assert (path ("C:").directory ().string () == ""); + assert (path ("C:\\tmp").directory ().string () == "C:"); + assert (path ("C:\\\\tmp").directory ().string () == "C:"); +#endif + + // base + // + assert (path ("/").base ().string () == "/"); + assert (path ("/foo.txt").base ().string () == "/foo"); + assert (path (".txt").base ().string () == ".txt"); + assert (path ("/.txt").base ().string () == "/.txt"); + assert (path ("foo.txt.orig").base ().string () == "foo.txt"); +#ifdef _WIN32 + assert (path ("C:").base ().string () == "C:"); + assert (path ("C:\\foo.txt").base ().string () == "C:\\foo"); +#endif + + // operator/ + // +#ifndef _WIN32 + assert ((path ("/") / path ("tmp")).string () == "/tmp"); + assert ((path ("foo") / path ("bar")).string () == "foo/bar"); +#else + assert ((path ("\\") / path ("tmp")).string () == "\\tmp"); + assert ((path ("C:\\") / path ("tmp")).string () == "C:\\tmp"); + assert ((path ("foo") / path ("bar")).string () == "foo\\bar"); +#endif + + // normalize + // +#ifndef _WIN32 + assert (path ("../foo").normalize ().string () == "../foo"); + assert (path ("..///foo").normalize ().string () == "../foo"); + assert (path ("../../foo").normalize ().string () == "../../foo"); + assert (path (".././foo").normalize ().string () == "../foo"); + assert (path (".").normalize ().string () == ""); + assert (path ("./..").normalize ().string () == ".."); + assert (path ("../.").normalize ().string () == ".."); + assert (path ("foo/./..").normalize ().string () == ""); + assert (path ("/foo/./..").normalize ().string () == "/"); + assert (path ("./foo").normalize ().string () == "foo"); +#else + assert (path ("../foo").normalize ().string () == "..\\foo"); + assert (path ("..///foo").normalize ().string () == "..\\foo"); + assert (path ("..\\../foo").normalize ().string () == "..\\..\\foo"); + assert (path (".././foo").normalize ().string () == "..\\foo"); + assert (path (".").normalize ().string () == ""); + assert (path ("./..").normalize ().string () == ".."); + assert (path ("../.").normalize ().string () == ".."); + assert (path ("foo/./..").normalize ().string () == ""); + assert (path ("C:/foo/./..").normalize ().string () == "c:"); + assert (path ("./foo").normalize ().string () == "foo"); + + assert (path ("C:").normalize ().string () == "c:"); + assert (path ("C:\\Foo12//Bar").normalize ().string () == "c:\\foo12\\bar"); +#endif + + // posix_string + // + assert (path ("foo/bar/../baz").posix_string () == "foo/bar/../baz"); +#ifdef _WIN32 + assert (path ("foo\\bar\\..\\baz").posix_string () == "foo/bar/../baz"); + try + { + path ("c:\\foo\\bar\\..\\baz").posix_string (); + assert (false); + } + catch (const invalid_path&) {} +#endif + + /* + path p ("../foo"); + p.complete (); + + cerr << path::current () << endl; + cerr << p << endl; + p.normalize (); + cerr << p << endl; + */ +} diff --git a/libcutl/tests/fs/path/makefile b/libcutl/tests/fs/path/makefile new file mode 100644 index 0000000..184510b --- /dev/null +++ b/libcutl/tests/fs/path/makefile @@ -0,0 +1,69 @@ +# file : tests/fs/path/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/makefile b/libcutl/tests/makefile new file mode 100644 index 0000000..3735414 --- /dev/null +++ b/libcutl/tests/makefile @@ -0,0 +1,26 @@ +# file : tests/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make + +tests := compiler container fs re shared-ptr + +default := $(out_base)/ +test := $(out_base)/.test +dist := $(out_base)/.dist +clean := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) + +$(dist): export dirs := +$(dist): #$(addprefix $(out_base)/,$(addsuffix /.dist,$(tests))) + $(call meta-automake) + +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/automake.make) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/libcutl/tests/re/driver.cxx b/libcutl/tests/re/driver.cxx new file mode 100644 index 0000000..4b070dd --- /dev/null +++ b/libcutl/tests/re/driver.cxx @@ -0,0 +1,83 @@ +// file : tests/re/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include + +#include + +using namespace cutl::re; + +int +main () +{ + // empty() and str(). + // + { + regex r; + assert (r.empty ()); + r = "['`]foo([^ ]*)bar['`]"; + assert (!r.empty ()); + assert (r.str () == "['`]foo([^ ]*)bar['`]"); + } + + // Error handling. + // + try + { + regex r ("['`]foo([^ ]*bar['`]"); + assert (false); + } + catch (format const& e) + { + assert (e.regex () == "['`]foo([^ ]*bar['`]"); + assert (!e.description ().empty ()); + //std::cerr << e.description () << std::endl; + } + + // match(), search(), and replace(). + // + { + regex r ("['`]foo([^ ]*)bar['`]"); + + assert (r.match ("'foofoxbar'")); + assert (!r.match ("'foof xbar'")); + + assert (r.search ("prefix 'foofoxbar' suffix")); + assert (!r.search ("prefix 'foof xbar' suffix")); + + assert (r.replace ("'foofoxbar'", "\\u$1") == "Fox"); + } + + // regexsub + // + { + regexsub r ("/['`]foo([^ ]*)bar['`]/\\u$1/"); + + assert (r.replace ("'foofoxbar'") == "Fox"); + } + + // regexsub escaping + // + { + regexsub r ("#a\\#\\\\#a?\\\\#"); + + assert (r.replace ("a#\\") == "a?\\"); + } + + // regexsub error handling. + // + try + { + regexsub r ("/['`]foo([^ ]*)bar['`]#\\u$1/"); + assert (false); + } + catch (format const& e) + { + assert (e.regex () == "/['`]foo([^ ]*)bar['`]#\\u$1/"); + assert (!e.description ().empty ()); + //std::cerr << e.description () << std::endl; + } +} diff --git a/libcutl/tests/re/makefile b/libcutl/tests/re/makefile new file mode 100644 index 0000000..3d22640 --- /dev/null +++ b/libcutl/tests/re/makefile @@ -0,0 +1,69 @@ +# file : tests/re/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/shared-ptr/driver.cxx b/libcutl/tests/shared-ptr/driver.cxx new file mode 100644 index 0000000..3e763a0 --- /dev/null +++ b/libcutl/tests/shared-ptr/driver.cxx @@ -0,0 +1,185 @@ +// file : tests/shared-ptr/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include + +using namespace cutl; + +struct type +{ + type (int x, char const* y) : x_ (x), y_ (y) {} + + int x_; + std::string y_; +}; + +struct base1 +{ + virtual + ~base1 () {} + base1 (int x) : x_ (x) {} + + int x_; +}; + +struct base2 +{ + virtual + ~base2 () {} + base2 (char const* y) : y_ (y) {} + + std::string y_; +}; + +struct derived: base1, base2 +{ + derived (int x, char const* y) : base1 (x), base2 (y) {} +}; + +struct shared_type: shared_base +{ + shared_type (int x, char const* y) + : x_ (x), y_ (y) + { + assert (ref_count (this) == 1); + } + + int x_; + std::string y_; +}; + +int +main () +{ + // + // inc_ref, dec_ref, ref_count + // + + // Non-polymorphic type. + // + { + type* x (new (shared) type (5, "foo")); + assert (ref_count (x) == 1); + inc_ref (x); + assert (ref_count (x) == 2); + dec_ref (x); + assert (ref_count (x) == 1); + dec_ref (x); + } + + // Polymorphic type. + // + { + base2* x (new (shared) derived (5, "foo")); + assert (ref_count (x) == 1); + inc_ref (x); + assert (ref_count (x) == 2); + dec_ref (x); + assert (ref_count (x) == 1); + dec_ref (x); + } + + // Shared type. + // + { + shared_type* x (new (shared) shared_type (5, "foo")); + assert (ref_count (x) == 1); + inc_ref (x); + assert (ref_count (x) == 2); + dec_ref (x); + assert (ref_count (x) == 1); + dec_ref (x); + } + + // Error handling (this theoretically can segfault). + // + { + type* x (new type (5, "foo")); + + try + { + inc_ref (x); + assert (false); + } + catch (not_shared const&) + { + } + + delete x; + } + + // + // shared_ptr + // + + // Non-polymorphic type. + // + { + shared_ptr x (new (shared) type (5, "foo")); + assert (x.count () == 1); + assert (x); + assert (x->x_ == 5); + assert ((*x).y_ == "foo"); + { + shared_ptr y (x); + assert (y.count () == 2); + } + { + shared_ptr y; + y = x; + assert (y.count () == 2); + } + assert (x.count () == 1); + shared_ptr y (x.release ()); + assert (y.count () == 1); + } + + // Polymorphic type. + // + { + shared_ptr x (new (shared) derived (5, "foo")); + assert (x.count () == 1); + { + shared_ptr y (x); + assert (y.count () == 2); + assert (y->y_ == "foo"); + } + { + shared_ptr y; + y = x; + assert (y.count () == 2); + } + assert (x.count () == 1); + } + + // Non-polymorphic type. + // + { + shared_ptr x (new (shared) shared_type (5, "foo")); + assert (x.count () == 1); + assert (x); + assert (x->x_ == 5); + assert ((*x).y_ == "foo"); + assert (x->_ref_count () == 1); + x->_inc_ref (); + assert (x.count () == 2); + x->_dec_ref (); + assert (x.count () == 1); + { + shared_ptr y (x); + assert (y.count () == 2); + } + { + shared_ptr y; + y = x; + assert (y.count () == 2); + } + assert (x.count () == 1); + shared_ptr y (x.release ()); + assert (y.count () == 1); + } +} diff --git a/libcutl/tests/shared-ptr/makefile b/libcutl/tests/shared-ptr/makefile new file mode 100644 index 0000000..2303d78 --- /dev/null +++ b/libcutl/tests/shared-ptr/makefile @@ -0,0 +1,69 @@ +# file : tests/shared-ptr/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/xml/makefile b/libcutl/tests/xml/makefile new file mode 100644 index 0000000..2073182 --- /dev/null +++ b/libcutl/tests/xml/makefile @@ -0,0 +1,17 @@ +# file : tests/xml/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +tests := parser serializer roundtrip + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/libcutl/tests/xml/parser/driver.cxx b/libcutl/tests/xml/parser/driver.cxx new file mode 100644 index 0000000..39d5994 --- /dev/null +++ b/libcutl/tests/xml/parser/driver.cxx @@ -0,0 +1,310 @@ +// file : tests/xml/parser/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include +#include + +#include + +using namespace std; +namespace xml = cutl::xml; +using namespace xml; + +int +main () +{ + // Test error handling. + // + try + { + istringstream is ("X"); + parser p (is, "test"); + + assert (p.next () == parser::start_element); + assert (p.next () == parser::start_element); + assert (p.next () == parser::characters && p.value () == "X"); + p.next (); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + try + { + istringstream is (""); + is.exceptions (ios_base::badbit | ios_base::failbit); + parser p (is, "test"); + + is.setstate (ios_base::badbit); + p.next (); + assert (false); + } + catch (const ios_base::failure& e) + { + } + + // Test the next_expect() functionality. + // + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + p.next_expect (parser::end_element); + } + + try + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::end_element); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + try + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::start_element, "root1"); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + // Test attribute maps. + // + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + + assert (p.attribute ("a") == "a"); + assert (p.attribute ("b", "B") == "b"); + assert (p.attribute ("c", "C") == "C"); + assert (p.attribute ("d") == 123); + assert (p.attribute ("t") == true); + assert (p.attribute ("f", false) == false); + + p.next_expect (parser::end_element); + } + + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + assert (p.attribute ("a") == "a"); + assert (p.peek () == parser::start_element && p.name () == "nested"); + assert (p.attribute ("a") == "a"); + p.next_expect (parser::start_element, "nested"); + assert (p.attribute ("a") == "A"); + p.next_expect (parser::start_element, "inner"); + assert (p.attribute ("a", "") == ""); + p.next_expect (parser::end_element); + assert (p.attribute ("a") == "A"); + assert (p.peek () == parser::end_element); + assert (p.attribute ("a") == "A"); // Still valid. + p.next_expect (parser::end_element); + assert (p.attribute ("a") == "a"); + p.next_expect (parser::end_element); + assert (p.attribute ("a", "") == ""); + } + + try + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + assert (p.attribute ("a") == "a"); + p.next_expect (parser::end_element); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + try + { + istringstream is (""); + parser p (is, "test"); + p.next_expect (parser::start_element, "root"); + p.attribute ("a"); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + // Test peeking and getting the current event. + // + { + istringstream is ("x"); + parser p (is, "peek", + parser::receive_default | parser::receive_attributes_event); + + assert (p.event () == parser::eof); + + assert (p.peek () == parser::start_element); + assert (p.next () == parser::start_element); + assert (p.event () == parser::start_element); + + assert (p.peek () == parser::start_attribute); + assert (p.event () == parser::start_attribute); + assert (p.next () == parser::start_attribute); + + assert (p.peek () == parser::characters && p.value () == "x"); + assert (p.next () == parser::characters && p.value () == "x"); + assert (p.event () == parser::characters && p.value () == "x"); + + assert (p.peek () == parser::end_attribute); + assert (p.event () == parser::end_attribute); + assert (p.next () == parser::end_attribute); + + assert (p.peek () == parser::characters && p.value () == "x"); + assert (p.next () == parser::characters && p.value () == "x"); + assert (p.event () == parser::characters && p.value () == "x"); + + assert (p.peek () == parser::start_element); + assert (p.next () == parser::start_element); + assert (p.event () == parser::start_element); + + assert (p.peek () == parser::end_element); + assert (p.next () == parser::end_element); + assert (p.event () == parser::end_element); + + assert (p.peek () == parser::end_element); + assert (p.next () == parser::end_element); + assert (p.event () == parser::end_element); + + assert (p.peek () == parser::eof); + assert (p.next () == parser::eof); + assert (p.event () == parser::eof); + } + + // Test content processing. + // + + // empty + // + { + istringstream is (" \n\t "); + parser p (is, "empty", + parser::receive_default | parser::receive_attributes_event); + + assert (p.next () == parser::start_element); + p.content (parser::empty); + assert (p.next () == parser::start_attribute); + assert (p.next () == parser::characters && p.value () == " x "); + assert (p.next () == parser::end_attribute); + assert (p.next () == parser::end_element); + assert (p.next () == parser::eof); + } + + try + { + istringstream is (" \n & X \t "); + parser p (is, "empty"); + + assert (p.next () == parser::start_element); + p.content (parser::empty); + p.next (); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + // simple + // + { + istringstream is (" X "); + parser p (is, "simple"); + + assert (p.next () == parser::start_element); + p.content (parser::simple); + assert (p.next () == parser::characters && p.value () == " X "); + assert (p.next () == parser::end_element); + assert (p.next () == parser::eof); + } + + try + { + istringstream is (" ? "); + parser p (is, "simple"); + + assert (p.next () == parser::start_element); + p.content (parser::simple); + assert (p.next () == parser::characters && p.value () == " ? "); + p.next (); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + // complex + // + { + istringstream is ("\n" + " \n" + " \n" + " X \n" + " \n" + "\n"); + parser p (is, "complex", + parser::receive_default | parser::receive_attributes_event); + + assert (p.next () == parser::start_element); // root + p.content (parser::complex); + + assert (p.next () == parser::start_attribute); + assert (p.next () == parser::characters && p.value () == " x "); + assert (p.next () == parser::end_attribute); + + assert (p.next () == parser::start_element); // nested + p.content (parser::complex); + + assert (p.next () == parser::start_element); // inner + p.content (parser::empty); + assert (p.next () == parser::end_element); // inner + + assert (p.next () == parser::start_element); // inner + p.content (parser::simple); + assert (p.next () == parser::characters && p.value () == " X "); + assert (p.next () == parser::end_element); // inner + + assert (p.next () == parser::end_element); // nested + assert (p.next () == parser::end_element); // root + assert (p.next () == parser::eof); + } + + try + { + istringstream is (" \n X X "); + parser p (is, "complex"); + + assert (p.next () == parser::start_element); + p.content (parser::complex); + assert (p.next () == parser::start_element); + assert (p.next () == parser::end_element); + p.next (); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } +} diff --git a/libcutl/tests/xml/parser/makefile b/libcutl/tests/xml/parser/makefile new file mode 100644 index 0000000..f654976 --- /dev/null +++ b/libcutl/tests/xml/parser/makefile @@ -0,0 +1,69 @@ +# file : tests/xml/parser/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/xml/roundtrip/attribute.xml b/libcutl/tests/xml/roundtrip/attribute.xml new file mode 100644 index 0000000..ca32460 --- /dev/null +++ b/libcutl/tests/xml/roundtrip/attribute.xml @@ -0,0 +1,3 @@ + + + diff --git a/libcutl/tests/xml/roundtrip/characters.xml b/libcutl/tests/xml/roundtrip/characters.xml new file mode 100644 index 0000000..fab909b --- /dev/null +++ b/libcutl/tests/xml/roundtrip/characters.xml @@ -0,0 +1,84 @@ + + +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + diff --git a/libcutl/tests/xml/roundtrip/driver.cxx b/libcutl/tests/xml/roundtrip/driver.cxx new file mode 100644 index 0000000..b0b6497 --- /dev/null +++ b/libcutl/tests/xml/roundtrip/driver.cxx @@ -0,0 +1,127 @@ +// file : tests/xml/roundtrip/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include +#include + +#include +#include + +using namespace std; +namespace xml = cutl::xml; +using namespace xml; + +const bool trace = false; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " " << endl; + return 1; + } + + try + { + ifstream ifs; + ifs.exceptions (ifstream::badbit | ifstream::failbit); + ifs.open (argv[1], ifstream::in | ifstream::binary); + + parser p (ifs, + argv[1], + parser::receive_default | + parser::receive_attributes_event | + parser::receive_namespace_decls); + + serializer s (cout, "out", 0); + + bool in_attr (false); + for (parser::event_type e (p.next ()); e != parser::eof; e = p.next ()) + { + switch (e) + { + case parser::start_element: + { + if (trace) + cerr << p.line () << ':' << p.column () << ": " << e << " " + << p.namespace_() << (p.namespace_().empty () ? "" : "#") + << p.prefix () << (p.prefix ().empty () ? "" : ":") + << p.name () << endl; + + s.start_element (p.qname ()); + break; + } + case parser::end_element: + { + if (trace) + cerr << p.line () << ':' << p.column () << ": " << e << " " + << p.namespace_() << (p.namespace_().empty () ? "" : "#") + << p.prefix () << (p.prefix ().empty () ? "" : ":") + << p.name () << endl; + + s.end_element (); + break; + } + case parser::start_namespace_decl: + { + if (trace) + cerr << " " << p.prefix () << "->" << p.namespace_ () << endl; + + s.namespace_decl (p.namespace_ (), p.prefix ()); + break; + } + case parser::end_namespace_decl: + { + if (trace) + cerr << " " << p.prefix () << "-x" << endl; + + break; + } + case parser::start_attribute: + { + if (trace) + cerr << " " << p.qname () << "="; + + s.start_attribute (p.qname ()); + in_attr = true; + break; + } + case parser::end_attribute: + { + s.end_attribute (); + in_attr = false; + break; + } + case parser::characters: + { + if (trace) + { + if (!in_attr) + cerr << p.line () << ':' << p.column () << ": " << e << " "; + + cerr << "'" << p.value () << "'" << endl; + } + + s.characters (p.value ()); + break; + } + default: + break; + } + } + } + catch (const ios_base::failure& e) + { + cerr << "io failure" << endl; + return 1; + } + catch (const xml::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/libcutl/tests/xml/roundtrip/followup-1.xml b/libcutl/tests/xml/roundtrip/followup-1.xml new file mode 100644 index 0000000..c2a3b22 --- /dev/null +++ b/libcutl/tests/xml/roundtrip/followup-1.xml @@ -0,0 +1,8 @@ + + + x + + + + foo&bar + diff --git a/libcutl/tests/xml/roundtrip/followup-2.xml b/libcutl/tests/xml/roundtrip/followup-2.xml new file mode 100644 index 0000000..70171eb --- /dev/null +++ b/libcutl/tests/xml/roundtrip/followup-2.xml @@ -0,0 +1 @@ + diff --git a/libcutl/tests/xml/roundtrip/makefile b/libcutl/tests/xml/roundtrip/makefile new file mode 100644 index 0000000..9769593 --- /dev/null +++ b/libcutl/tests/xml/roundtrip/makefile @@ -0,0 +1,74 @@ +# file : tests/xml/roundtrip/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): tests := attribute.xml namespace.xml followup-1.xml followup-2.xml \ +characters.xml + +$(test): test_body = $(call message,test $< $1,$< $(src_base)/$1 >$(out_base)/test.out)$(literal_newline)\ +$(literal_tab)$(call message,,diff -u $(src_base)/$1 $(out_base)/test.out)$(literal_newline)\ +$(literal_tab)$(call message,,rm -f $(out_base)/test.out)$(literal_newline) +$(test): $(driver) + $(foreach t,$(tests),$(call test_body,$t)) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/libcutl/tests/xml/roundtrip/namespace.xml b/libcutl/tests/xml/roundtrip/namespace.xml new file mode 100644 index 0000000..4a5642e --- /dev/null +++ b/libcutl/tests/xml/roundtrip/namespace.xml @@ -0,0 +1,6 @@ + + + X + + + diff --git a/libcutl/tests/xml/serializer/driver.cxx b/libcutl/tests/xml/serializer/driver.cxx new file mode 100644 index 0000000..869bb8e --- /dev/null +++ b/libcutl/tests/xml/serializer/driver.cxx @@ -0,0 +1,63 @@ +// file : tests/xml/serializer/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include +#include + +#include + +using namespace std; +namespace xml = cutl::xml; +using namespace xml; + +int +main () +{ + // Test error handling. + // + try + { + ostringstream os; + serializer s (os, "test"); + + s.attribute ("foo", "bar"); + assert (false); + } + catch (const xml::exception& e) + { + // cerr << e.what () << endl; + } + + try + { + ostringstream os; + os.exceptions (ios_base::badbit | ios_base::failbit); + serializer s (os, "test"); + + s.start_element ("root"); + s.characters ("one"); + os.setstate (ios_base::badbit); + s.characters ("two"); + assert (false); + } + catch (const ios_base::failure& e) + { + } + + // Test value serialization. + // + { + ostringstream os; + serializer s (os, "test", 0); + + s.start_element ("root"); + s.attribute ("version", 123); + s.characters (true); + s.end_element (); + + assert (os.str () == "true\n"); + } +} diff --git a/libcutl/tests/xml/serializer/makefile b/libcutl/tests/xml/serializer/makefile new file mode 100644 index 0000000..8bd1a4a --- /dev/null +++ b/libcutl/tests/xml/serializer/makefile @@ -0,0 +1,69 @@ +# file : tests/xml/serializer/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) -- cgit v1.2.3