diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-08 12:36:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-08 15:47:26 +0200 |
commit | 35662787f479b93b3205310934574132609461cc (patch) | |
tree | 3a53faca30dde0ecfe7c66bfc667c915ee1bfe9b /common | |
parent | 20c2f6cde170e1a8703858e17530fcf68e4efbe4 (diff) |
Get rid of special tracer database
The include, types, and pragma tests have been moved to the common/
directory while the object test has been merged into common/lifecycle.
The transaction test will be re-implemented as common/ test as soon
as SQL statement tracing support is merged.
Diffstat (limited to 'common')
-rw-r--r-- | common/include/driver.cxx | 42 | ||||
-rw-r--r-- | common/include/makefile | 91 | ||||
-rw-r--r-- | common/include/obj1.hxx | 27 | ||||
-rw-r--r-- | common/include/obj2.hxx | 27 | ||||
-rw-r--r-- | common/include/obj3.hxx | 27 | ||||
-rw-r--r-- | common/include/objs1.hxx | 15 | ||||
-rw-r--r-- | common/include/objs2.hxx | 15 | ||||
-rw-r--r-- | common/include/objs3.hxx | 13 | ||||
-rw-r--r-- | common/include/objs4.hxx | 13 | ||||
-rw-r--r-- | common/include/test.std | 0 | ||||
-rw-r--r-- | common/include/test1.hxx | 18 | ||||
-rw-r--r-- | common/include/test2.hxx | 17 | ||||
-rw-r--r-- | common/include/test3.hxx | 14 | ||||
-rw-r--r-- | common/include/test4.hxx | 14 | ||||
-rw-r--r-- | common/lifecycle/driver.cxx | 124 | ||||
-rw-r--r-- | common/makefile | 3 | ||||
-rw-r--r-- | common/pragma/driver.cxx | 27 | ||||
-rw-r--r-- | common/pragma/makefile | 108 | ||||
-rw-r--r-- | common/pragma/test.hxx | 42 | ||||
-rw-r--r-- | common/pragma/test.std | 0 | ||||
-rw-r--r-- | common/types/driver.cxx | 37 | ||||
-rw-r--r-- | common/types/makefile | 107 | ||||
-rw-r--r-- | common/types/test.hxx | 57 | ||||
-rw-r--r-- | common/types/test.std | 0 |
24 files changed, 838 insertions, 0 deletions
diff --git a/common/include/driver.cxx b/common/include/driver.cxx new file mode 100644 index 0000000..d588a62 --- /dev/null +++ b/common/include/driver.cxx @@ -0,0 +1,42 @@ +// file : common/include/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test inclusion of -odb files (compilation test). +// +// The setup of this test is as follows: the ODB compiler has two +// additional include directories in its search path: .. and ../.. +// while the C++ compiler has only ../.. . This way, if a ..-based +// path is used in the generated code, the C++ compilation will +// fail. +// + +#include <memory> +#include <cassert> +#include <iostream> + +#include <odb/exceptions.hxx> +#include <odb/transaction.hxx> + +#include <common/common.hxx> + +#include "test1.hxx" +#include "test1-odb.hxx" + +#include "test2.hxx" +#include "test2-odb.hxx" + +#include "test3.hxx" +#include "test3-odb.hxx" + +#include "test4.hxx" +#include "test4-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main () +{ +} diff --git a/common/include/makefile b/common/include/makefile new file mode 100644 index 0000000..7053d75 --- /dev/null +++ b/common/include/makefile @@ -0,0 +1,91 @@ +# file : common/include/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := obj1.hxx obj2.hxx obj3.hxx test1.hxx test2.hxx test3.hxx test4.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(driver): $(cxx_obj) $(common.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) \ +-I$(out_base)/../.. -I$(src_base)/../.. +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) + +genf := $(foreach f,$(odb_hdr:.hxx=-odb),$(addprefix $f,.hxx .ixx .cxx)) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) \ +--table-prefix include_ +$(gen): cpp_options := -I$(out_base) -I$(src_base)/.. -I$(src_base)/../.. +$(gen): $(common.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist: not supported. +# +$(dist): + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(odb_rules)) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/include/obj1.hxx b/common/include/obj1.hxx new file mode 100644 index 0000000..cdf6a66 --- /dev/null +++ b/common/include/obj1.hxx @@ -0,0 +1,27 @@ +// file : common/include/obj1.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJ1_HXX +#define OBJ1_HXX + +#include <odb/core.hxx> + +#pragma db object +struct object1 +{ + object1 (unsigned long id) + : id_ (id) + { + } + + object1 () + { + } + + #pragma db id + unsigned long id_; +}; + +#endif // OBJ1_HXX diff --git a/common/include/obj2.hxx b/common/include/obj2.hxx new file mode 100644 index 0000000..4c98d7d --- /dev/null +++ b/common/include/obj2.hxx @@ -0,0 +1,27 @@ +// file : common/include/obj2.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJ2_HXX +#define OBJ2_HXX + +#include <odb/core.hxx> + +#pragma db object +struct object2 +{ + object2 (unsigned long id) + : id_ (id) + { + } + + object2 () + { + } + + #pragma db id + unsigned long id_; +}; + +#endif // OBJ2_HXX diff --git a/common/include/obj3.hxx b/common/include/obj3.hxx new file mode 100644 index 0000000..b73673a --- /dev/null +++ b/common/include/obj3.hxx @@ -0,0 +1,27 @@ +// file : common/include/obj3.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJ3_HXX +#define OBJ3_HXX + +#include <odb/core.hxx> + +#pragma db object +struct object3 +{ + object3 (unsigned long id) + : id_ (id) + { + } + + object3 () + { + } + + #pragma db id + unsigned long id_; +}; + +#endif // OBJ3_HXX diff --git a/common/include/objs1.hxx b/common/include/objs1.hxx new file mode 100644 index 0000000..5e592a4 --- /dev/null +++ b/common/include/objs1.hxx @@ -0,0 +1,15 @@ +// file : common/include/objs1.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJS1_HXX +#define OBJS1_HXX + +#ifdef ODB_COMPILER +# include <include/obj1.hxx> +# include <include/obj2.hxx> +# include <include/obj3.hxx> +#endif + +#endif // OBJS1_HXX diff --git a/common/include/objs2.hxx b/common/include/objs2.hxx new file mode 100644 index 0000000..f2cfee0 --- /dev/null +++ b/common/include/objs2.hxx @@ -0,0 +1,15 @@ +// file : common/include/objs2.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJS2_HXX +#define OBJS2_HXX + +#ifdef ODB_COMPILER +# include "include/obj1.hxx" +# include "include/obj2.hxx" +# include "include/obj3.hxx" +#endif + +#endif // OBJS2_HXX diff --git a/common/include/objs3.hxx b/common/include/objs3.hxx new file mode 100644 index 0000000..d9bc01a --- /dev/null +++ b/common/include/objs3.hxx @@ -0,0 +1,13 @@ +// file : common/include/objs3.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJS3_HXX +#define OBJS3_HXX + +#include "../include/obj1.hxx" +#include "../include/obj2.hxx" +#include "../include/obj3.hxx" + +#endif // OBJS3_HXX diff --git a/common/include/objs4.hxx b/common/include/objs4.hxx new file mode 100644 index 0000000..fc5f1de --- /dev/null +++ b/common/include/objs4.hxx @@ -0,0 +1,13 @@ +// file : common/include/objs1.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef OBJS4_HXX +#define OBJS4_HXX + +#include <common/include/obj1.hxx> +#include <common/include/obj2.hxx> +#include <common/include/obj3.hxx> + +#endif // OBJS4_HXX diff --git a/common/include/test.std b/common/include/test.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/common/include/test.std diff --git a/common/include/test1.hxx b/common/include/test1.hxx new file mode 100644 index 0000000..15972c1 --- /dev/null +++ b/common/include/test1.hxx @@ -0,0 +1,18 @@ +// file : common/include/test1.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST1_HXX +#define TEST1_HXX + +// Test include directive parsing. +// +#include"obj1.hxx" + + # include \ + <common/include/obj2.hxx> + +/*comment*/ # /*comment*/ include /* comment */ "obj3.hxx" // comment + +#endif // TEST1_HXX diff --git a/common/include/test2.hxx b/common/include/test2.hxx new file mode 100644 index 0000000..ee26994 --- /dev/null +++ b/common/include/test2.hxx @@ -0,0 +1,17 @@ +// file : common/include/test2.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST2_HXX +#define TEST2_HXX + +// Test preference of includes from the main file. +// +#include "objs1.hxx" + +#include "obj1.hxx" +#include "obj2.hxx" +#include "obj3.hxx" + +#endif // TEST2_HXX diff --git a/common/include/test3.hxx b/common/include/test3.hxx new file mode 100644 index 0000000..a2b2096 --- /dev/null +++ b/common/include/test3.hxx @@ -0,0 +1,14 @@ +// file : common/include/test3.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST3_HXX +#define TEST3_HXX + +// Test preference of longer (more qualified) paths. +// +#include "objs2.hxx" +#include "objs3.hxx" + +#endif // TEST3_HXX diff --git a/common/include/test4.hxx b/common/include/test4.hxx new file mode 100644 index 0000000..49180bc --- /dev/null +++ b/common/include/test4.hxx @@ -0,0 +1,14 @@ +// file : common/include/test3.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST3_HXX +#define TEST3_HXX + +// Test preference of <> over "". +// +#include "objs2.hxx" +#include "objs4.hxx" + +#endif // TEST3_HXX diff --git a/common/lifecycle/driver.cxx b/common/lifecycle/driver.cxx index 46d145b..8323694 100644 --- a/common/lifecycle/driver.cxx +++ b/common/lifecycle/driver.cxx @@ -28,6 +28,18 @@ main (int argc, char* argv[]) { auto_ptr<database> db (create_database (argc, argv)); + // Database operation out of transaction. + // + try + { + object o (1); + db->persist (o); + assert (false); + } + catch (const not_in_transaction&) + { + } + // Transient. // try @@ -63,11 +75,100 @@ main (int argc, char* argv[]) } } + // Find. + // + { + transaction t (db->begin ()); + + auto_ptr<object> o1 (db->find<object> (1)); + assert (o1.get () != 0 && o1->str_ == "value 1"); + + auto_ptr<object> o2 (db->find<object> (2)); + assert (o2.get () == 0); + + t.commit (); + } + + // Find (into existing). + // + { + object o; + + transaction t (db->begin ()); + + assert (db->find (1, o)); + assert (o.str_ == "value 1"); + + assert (!db->find (2, o)); + + t.commit (); + } + + // Load. + // { transaction t (db->begin ()); auto_ptr<object> o (db->load<object> (1)); assert (o->str_ == "value 1"); t.commit (); + + try + { + transaction t (db->begin ()); + auto_ptr<object> o (db->load<object> (2)); + assert (false); + t.commit (); + } + catch (const object_not_persistent&) + { + } + } + + // Load (into existing). + // + { + object o; + + transaction t (db->begin ()); + db->load (1, o); + assert (o.str_ == "value 1"); + t.commit (); + + try + { + transaction t (db->begin ()); + db->load (2, o); + assert (false); + t.commit (); + } + catch (const object_not_persistent&) + { + } + } + + // Reload. + // + { + object o; + + transaction t (db->begin ()); + db->load (1, o); + o.str_ = "junk"; + db->reload (o); + assert (o.str_ == "value 1"); + t.commit (); + + try + { + transaction t (db->begin ()); + o.id_ = 2; + db->reload (o); + assert (false); + t.commit (); + } + catch (const object_not_persistent&) + { + } } // Modified. @@ -78,6 +179,18 @@ main (int argc, char* argv[]) o->str_ = "value 2"; db->update (*o); t.commit (); + + try + { + transaction t (db->begin ()); + o->id_ = 2; + db->update (*o); + assert (false); + t.commit (); + } + catch (const object_not_persistent&) + { + } } { @@ -103,6 +216,17 @@ main (int argc, char* argv[]) auto_ptr<object> o (db->load<object> (1)); db->erase (*o); t.commit (); + + try + { + transaction t (db->begin ()); + db->erase<object> (1); + assert (false); + t.commit (); + } + catch (const object_not_persistent&) + { + } } try diff --git a/common/makefile b/common/makefile index 37d50d3..c75ea56 100644 --- a/common/makefile +++ b/common/makefile @@ -17,18 +17,21 @@ ctor \ default \ enum \ erase-query \ +include \ inheritance \ inverse \ lazy-ptr \ lifecycle \ no-id \ optimistic \ +pragma \ query \ readonly \ relationship \ relationship-query \ schema \ template \ +types \ view \ wrapper diff --git a/common/pragma/driver.cxx b/common/pragma/driver.cxx new file mode 100644 index 0000000..65b384d --- /dev/null +++ b/common/pragma/driver.cxx @@ -0,0 +1,27 @@ +// file : common/pragma/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test #pragma db parsing. +// + +#include <memory> +#include <cassert> +#include <iostream> + +#include <odb/exceptions.hxx> +#include <odb/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main () +{ +} diff --git a/common/pragma/makefile b/common/pragma/makefile new file mode 100644 index 0000000..449fcaf --- /dev/null +++ b/common/pragma/makefile @@ -0,0 +1,108 @@ +# file : common/pragma/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(driver): $(cxx_obj) $(common.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) \ +--table-prefix pragma_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../template/Makefile.am) + $(call meta-vc9projs,../template/template,$(name)) + $(call meta-vc10projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(odb_rules)) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/pragma/test.hxx b/common/pragma/test.hxx new file mode 100644 index 0000000..d7f21b0 --- /dev/null +++ b/common/pragma/test.hxx @@ -0,0 +1,42 @@ +// file : common/template/test.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <odb/core.hxx> + +#pragma db value(bool) type ("INTEGER") + +struct x {int i;}; +#pragma db value (x) + +namespace N +{ + #pragma db object + struct object1 + { + object1 () {} + + #pragma db id + unsigned long id_; + + #pragma db member type ("INTEGER") + bool b_; + }; + + struct object2 + { + object2 () {} + + unsigned long id_; + }; + + #pragma db object (object2) +} + +PRAGMA_DB (member (N::object2::id_) id auto); + +#endif // TEST_HXX diff --git a/common/pragma/test.std b/common/pragma/test.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/common/pragma/test.std diff --git a/common/types/driver.cxx b/common/types/driver.cxx new file mode 100644 index 0000000..11e15d7 --- /dev/null +++ b/common/types/driver.cxx @@ -0,0 +1,37 @@ +// file : common/types/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test C++ type handling (anonymous types, aliasing). +// + +#include <memory> +#include <cassert> +#include <iostream> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +template <typename T1, typename T2> +struct same_p +{ + static const bool result = false; +}; + +template <typename T> +struct same_p<T, T> +{ + static const bool result = true; +}; + +int +main () +{ + assert ((same_p<odb::object_traits<object2>::id_type, int>::result)); +} diff --git a/common/types/makefile b/common/types/makefile new file mode 100644 index 0000000..4081ee8 --- /dev/null +++ b/common/types/makefile @@ -0,0 +1,107 @@ +# file : common/types/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(driver): $(cxx_obj) $(common.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) --table-prefix types_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../template/Makefile.am) + $(call meta-vc9projs,../template/template,$(name)) + $(call meta-vc10projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(odb_rules)) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/types/test.hxx b/common/types/test.hxx new file mode 100644 index 0000000..858f403 --- /dev/null +++ b/common/types/test.hxx @@ -0,0 +1,57 @@ +// file : common/types/test.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#ifdef ODB_COMPILER +typedef int int_t; +typedef short num_t; +#else +typedef int num_t; +#endif + +typedef num_t num_type; + +#pragma db object +struct object1 +{ + typedef int int_type; + + #pragma db id + int_type id_; +}; + +#pragma db object +struct object2 +{ + #pragma db id + num_type num_; +}; + +// Template-id with "inner" name (compilation test). +// +template <typename X> +struct num_wrap +{ +#ifdef ODB_COMPILER + typedef num_wrap this_type; // Name that we should not use. +#endif + + num_wrap () {} + num_wrap (X v): v_ (v) {} + operator X () const {return v_;} + + X v_; +}; + +#pragma db object +struct object3 +{ + #pragma db id type("INTEGER") + num_wrap<int> num_; +}; + +#endif // TEST_HXX diff --git a/common/types/test.std b/common/types/test.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/common/types/test.std |