diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-08 14:47:57 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-08 14:47:57 +0200 |
commit | 6b76715e63d2c265a4c51c73f9019bc578f874cb (patch) | |
tree | c0b5f6a944abf6fe015742bbc08e5a393249cf6d | |
parent | dcee8530bb5c58710a22f50bb92ac7c3b19ddf84 (diff) |
Fix bug in transient inheritance handling
Also test that we can handle it for objects, composite values, and views.
-rw-r--r-- | common/inheritance/polymorphism/driver.cxx (renamed from common/polymorphism/driver.cxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/makefile (renamed from common/polymorphism/makefile) | 6 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test.std (renamed from common/polymorphism/test.std) | 0 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test1.hxx (renamed from common/polymorphism/test1.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test10.hxx (renamed from common/polymorphism/test10.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test11.hxx (renamed from common/polymorphism/test11.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test12.hxx (renamed from common/polymorphism/test12.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test2.hxx (renamed from common/polymorphism/test2.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test3.hxx (renamed from common/polymorphism/test3.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test4.hxx (renamed from common/polymorphism/test4.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test5.hxx (renamed from common/polymorphism/test5.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test6.hxx (renamed from common/polymorphism/test6.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test7.hxx (renamed from common/polymorphism/test7.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test8.hxx (renamed from common/polymorphism/test8.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test9.hxx (renamed from common/polymorphism/test9.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/reuse/driver.cxx (renamed from common/inheritance/driver.cxx) | 4 | ||||
-rw-r--r-- | common/inheritance/reuse/makefile (renamed from common/inheritance/makefile) | 6 | ||||
-rw-r--r-- | common/inheritance/reuse/test.hxx (renamed from common/inheritance/test.hxx) | 2 | ||||
-rw-r--r-- | common/inheritance/reuse/test.std (renamed from common/inheritance/test.std) | 0 | ||||
-rw-r--r-- | common/inheritance/transient/driver.cxx | 79 | ||||
-rw-r--r-- | common/inheritance/transient/makefile | 115 | ||||
-rw-r--r-- | common/inheritance/transient/test.hxx | 61 | ||||
-rw-r--r-- | common/inheritance/transient/test.std | 0 | ||||
-rw-r--r-- | common/makefile | 77 |
24 files changed, 316 insertions, 60 deletions
diff --git a/common/polymorphism/driver.cxx b/common/inheritance/polymorphism/driver.cxx index 1bd8a2f..20007e4 100644 --- a/common/polymorphism/driver.cxx +++ b/common/inheritance/polymorphism/driver.cxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/driver.cxx +// file : common/inheritance/polymorphism/driver.cxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/makefile b/common/inheritance/polymorphism/makefile index 6a8b72a..5796d49 100644 --- a/common/polymorphism/makefile +++ b/common/inheritance/polymorphism/makefile @@ -1,8 +1,8 @@ -# file : common/polymorphism/makefile +# file : common/inheritance/polymorphism/makefile # copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC # license : GNU GPL v2; see accompanying LICENSE file -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make cxx_tun := driver.cxx odb_hdr := test1.hxx test2.hxx test3.hxx test4.hxx test5.hxx test6.hxx \ @@ -36,7 +36,7 @@ gen := $(addprefix $(out_base)/,$(genf)) $(gen): $(odb) $(gen): odb := $(odb) $(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ ---generate-query --table-prefix poly_ +--generate-query --table-prefix inherit_p_ $(gen): cpp_options := -I$(src_base) $(gen): $(common.l.cpp-options) diff --git a/common/polymorphism/test.std b/common/inheritance/polymorphism/test.std index 5c18191..5c18191 100644 --- a/common/polymorphism/test.std +++ b/common/inheritance/polymorphism/test.std diff --git a/common/polymorphism/test1.hxx b/common/inheritance/polymorphism/test1.hxx index e6db3f4..f3015cd 100644 --- a/common/polymorphism/test1.hxx +++ b/common/inheritance/polymorphism/test1.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test1.hxx +// file : common/inheritance/polymorphism/test1.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test10.hxx b/common/inheritance/polymorphism/test10.hxx index be7d3c0..d534498 100644 --- a/common/polymorphism/test10.hxx +++ b/common/inheritance/polymorphism/test10.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test10.hxx +// file : common/inheritance/polymorphism/test10.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test11.hxx b/common/inheritance/polymorphism/test11.hxx index 58a4ff4..0622c37 100644 --- a/common/polymorphism/test11.hxx +++ b/common/inheritance/polymorphism/test11.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test11.hxx +// file : common/inheritance/polymorphism/test11.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test12.hxx b/common/inheritance/polymorphism/test12.hxx index 5feb2bb..94054ce 100644 --- a/common/polymorphism/test12.hxx +++ b/common/inheritance/polymorphism/test12.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test12.hxx +// file : common/inheritance/polymorphism/test12.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test2.hxx b/common/inheritance/polymorphism/test2.hxx index 1b81f41..a238190 100644 --- a/common/polymorphism/test2.hxx +++ b/common/inheritance/polymorphism/test2.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test2.hxx +// file : common/inheritance/polymorphism/test2.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test3.hxx b/common/inheritance/polymorphism/test3.hxx index 9a9a269..c219bfc 100644 --- a/common/polymorphism/test3.hxx +++ b/common/inheritance/polymorphism/test3.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test3.hxx +// file : common/inheritance/polymorphism/test3.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test4.hxx b/common/inheritance/polymorphism/test4.hxx index d9eba86..b268548 100644 --- a/common/polymorphism/test4.hxx +++ b/common/inheritance/polymorphism/test4.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test4.hxx +// file : common/inheritance/polymorphism/test4.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test5.hxx b/common/inheritance/polymorphism/test5.hxx index ede75a0..ecc92ad 100644 --- a/common/polymorphism/test5.hxx +++ b/common/inheritance/polymorphism/test5.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test5.hxx +// file : common/inheritance/polymorphism/test5.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test6.hxx b/common/inheritance/polymorphism/test6.hxx index 9ecef40..a40d8c1 100644 --- a/common/polymorphism/test6.hxx +++ b/common/inheritance/polymorphism/test6.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test6.hxx +// file : common/inheritance/polymorphism/test6.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test7.hxx b/common/inheritance/polymorphism/test7.hxx index 1d3a807..10f604f 100644 --- a/common/polymorphism/test7.hxx +++ b/common/inheritance/polymorphism/test7.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test7.hxx +// file : common/inheritance/polymorphism/test7.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test8.hxx b/common/inheritance/polymorphism/test8.hxx index adaafc2..ee5829a 100644 --- a/common/polymorphism/test8.hxx +++ b/common/inheritance/polymorphism/test8.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test8.hxx +// file : common/inheritance/polymorphism/test8.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/polymorphism/test9.hxx b/common/inheritance/polymorphism/test9.hxx index d1496c1..b059464 100644 --- a/common/polymorphism/test9.hxx +++ b/common/inheritance/polymorphism/test9.hxx @@ -1,4 +1,4 @@ -// file : common/polymorphism/test9.hxx +// file : common/inheritance/polymorphism/test9.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/inheritance/driver.cxx b/common/inheritance/reuse/driver.cxx index ba907ce..78c2703 100644 --- a/common/inheritance/driver.cxx +++ b/common/inheritance/reuse/driver.cxx @@ -1,8 +1,8 @@ -// file : common/inheritance/driver.cxx +// file : common/inheritance/reuse/driver.cxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -// Test object inheritance. +// Test reuse object inheritance. // #include <memory> // std::auto_ptr diff --git a/common/inheritance/makefile b/common/inheritance/reuse/makefile index df31c4f..1fc1142 100644 --- a/common/inheritance/makefile +++ b/common/inheritance/reuse/makefile @@ -1,8 +1,8 @@ -# file : common/inheritance/makefile +# file : common/inheritance/reuse/makefile # copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC # license : GNU GPL v2; see accompanying LICENSE file -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make cxx_tun := driver.cxx odb_hdr := test.hxx @@ -35,7 +35,7 @@ gen := $(addprefix $(out_base)/,$(genf)) $(gen): $(odb) $(gen): odb := $(odb) $(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ ---generate-query --table-prefix inherit_ +--generate-query --table-prefix inherit_r_ $(gen): cpp_options := -I$(src_base) $(gen): $(common.l.cpp-options) diff --git a/common/inheritance/test.hxx b/common/inheritance/reuse/test.hxx index 6059337..8222f97 100644 --- a/common/inheritance/test.hxx +++ b/common/inheritance/reuse/test.hxx @@ -1,4 +1,4 @@ -// file : common/inheritance/test.hxx +// file : common/inheritance/reuse/test.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/common/inheritance/test.std b/common/inheritance/reuse/test.std index e69de29..e69de29 100644 --- a/common/inheritance/test.std +++ b/common/inheritance/reuse/test.std diff --git a/common/inheritance/transient/driver.cxx b/common/inheritance/transient/driver.cxx new file mode 100644 index 0000000..099506b --- /dev/null +++ b/common/inheritance/transient/driver.cxx @@ -0,0 +1,79 @@ +// file : common/inheritance/transient/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test transient inheritance of objects, composite value types, and views. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/database.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 (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_database (argc, argv)); + + object o; + o.num = 1; + o.str = "abc"; + o.strs.push_back ("abc 1"); + o.strs.push_back ("abc 2"); + o.c.num = 11; + o.c.str = "comp abc"; + o.c.nums.push_back (111); + o.c.nums.push_back (112); + + // persist + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + auto_ptr<object> p (db->load<object> (o.id_)); + t.commit (); + + assert (*p == o); + } + + // view + // + { + typedef odb::query<view> query; + typedef odb::result<view> result; + + transaction t (db->begin ()); + + result r (db->query<view> (query::id == o.id_)); + result::iterator i (r.begin ()); + assert (i != r.end () && i->num == o.num && i->str == o.str); + assert (++i == r.end ()); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/common/inheritance/transient/makefile b/common/inheritance/transient/makefile new file mode 100644 index 0000000..ab5936a --- /dev/null +++ b/common/inheritance/transient/makefile @@ -0,0 +1,115 @@ +# file : common/inheritance/transient/makefile +# copyright : Copyright (c) 2009-2012 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) --generate-schema \ +--generate-query --table-prefix inherit_t_ +$(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)) $(call vc11projs,$(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)) + $(call meta-vc11projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(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/vc11proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(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/inheritance/transient/test.hxx b/common/inheritance/transient/test.hxx new file mode 100644 index 0000000..df5d0c1 --- /dev/null +++ b/common/inheritance/transient/test.hxx @@ -0,0 +1,61 @@ +// file : common/inheritance/transient/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <string> +#include <vector> + +#include <odb/core.hxx> + +struct object; + +struct base +{ + int n; + std::vector<std::string> v; + object* p; +}; + +#pragma db value +struct comp: base +{ + unsigned int num; + std::string str; + std::vector<unsigned int> nums; + + bool + operator== (const comp& y) const + { + return num == y.num && str == y.str && nums == y.nums; + } +}; + +#pragma db object +struct object: base +{ + #pragma db id auto + unsigned int id_; + + unsigned int num; + std::string str; + std::vector<std::string> strs; + comp c; + + bool + operator== (const object& y) const + { + return num == y.num && str == y.str && strs == y.strs && c == y.c; + } +}; + +#pragma db view object(object) +struct view: base +{ + unsigned int num; + std::string str; +}; + +#endif // TEST_HXX diff --git a/common/inheritance/transient/test.std b/common/inheritance/transient/test.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/common/inheritance/transient/test.std diff --git a/common/makefile b/common/makefile index 3988260..6f187fb 100644 --- a/common/makefile +++ b/common/makefile @@ -4,44 +4,45 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make -tests := \ -access \ -auto \ -blob \ -callback \ -circular/single \ -circular/multiple \ -composite \ -composite-id \ -const-object \ -const-member \ -container \ -ctor \ -default \ -definition \ -enum \ -erase-query \ -include \ -index \ -inheritance \ -inverse \ -lazy-ptr \ -lifecycle \ -no-id \ -optimistic \ -polymorphism \ -pragma \ -query \ -readonly \ -relationship \ -relationship-query \ -schema \ -session \ -template \ -transaction \ -types \ -view \ -virtual \ +tests := \ +access \ +auto \ +blob \ +callback \ +circular/single \ +circular/multiple \ +composite \ +composite-id \ +const-object \ +const-member \ +container \ +ctor \ +default \ +definition \ +enum \ +erase-query \ +include \ +index \ +inheritance/polymorphism \ +inheritance/reuse \ +inheritance/transient \ +inverse \ +lazy-ptr \ +lifecycle \ +no-id \ +optimistic \ +pragma \ +query \ +readonly \ +relationship \ +relationship-query \ +schema \ +session \ +template \ +transaction \ +types \ +view \ +virtual \ wrapper thread_tests := threads |