From 261863a5037ba892ec33eb037d77736c8e599369 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 8 Feb 2013 12:22:04 +0200 Subject: Test change-tracking container and reuse inheritance --- common/inheritance/reuse/driver.cxx | 54 +++++++++++++++++++++++++++++++++++++ common/inheritance/reuse/test.hxx | 12 ++++++--- 2 files changed, 63 insertions(+), 3 deletions(-) (limited to 'common/inheritance') diff --git a/common/inheritance/reuse/driver.cxx b/common/inheritance/reuse/driver.cxx index 78c2703..89a1926 100644 --- a/common/inheritance/reuse/driver.cxx +++ b/common/inheritance/reuse/driver.cxx @@ -29,51 +29,73 @@ main (int argc, char* argv[]) base b; b.comp_.bools.push_back (true); + b.comp_.obools.push_back (true); b.comp_.num = 10; b.comp_.str = "comp bbb"; b.comp_.nums.push_back (101); b.comp_.nums.push_back (102); + b.comp_.onums.push_back (101); + b.comp_.onums.push_back (102); b.num_ = 0; b.str_ = "bbb"; b.strs_.push_back ("bbb one"); b.strs_.push_back ("bbb two"); + b.ostrs_.push_back ("bbb one"); + b.ostrs_.push_back ("bbb two"); object1 o1; o1.comp_.bools.push_back (false); + o1.comp_.obools.push_back (false); o1.comp_.num = 11; o1.comp_.str = "comp o1o1o1"; o1.comp_.nums.push_back (111); o1.comp_.nums.push_back (112); + o1.comp_.onums.push_back (111); + o1.comp_.onums.push_back (112); static_cast (o1).num_ = 1; o1.num1_ = 21; o1.str_ = "base o1o1o1"; o1.strs_.push_back ("base o1o1o1 one"); o1.strs_.push_back ("base o1o1o1 two"); + o1.ostrs_.push_back ("base o1o1o1 one"); + o1.ostrs_.push_back ("base o1o1o1 two"); object2 o2; o2.comp_.bools.push_back (true); o2.comp_.bools.push_back (false); + o2.comp_.obools.push_back (true); + o2.comp_.obools.push_back (false); o2.comp_.num = 12; o2.comp_.str = "comp o2o2o2"; o2.comp_.nums.push_back (121); o2.comp_.nums.push_back (122); + o2.comp_.onums.push_back (121); + o2.comp_.onums.push_back (122); o2.num_ = 2; static_cast (o2).str_ = "base o2o2o2"; o2.str_ = "o2o2o2"; o2.strs_.push_back ("base o2o2o2 one"); o2.strs_.push_back ("base o2o2o2 two"); + o2.ostrs_.push_back ("base o2o2o2 one"); + o2.ostrs_.push_back ("base o2o2o2 two"); object3 o3; o3.comp_.bools.push_back (false); o3.comp_.bools.push_back (false); + o3.comp_.obools.push_back (false); + o3.comp_.obools.push_back (false); o3.comp_.num = 13; o3.comp_.str = "comp o3o3o3"; o3.comp_.nums.push_back (131); o3.comp_.nums.push_back (132); + o3.comp_.onums.push_back (131); + o3.comp_.onums.push_back (132); o3.num_ = 3; o3.str_ = "base o3o3o3"; o3.strs_.push_back ("base o3o3o3 one"); o3.strs_.push_back ("base o3o3o3 two"); + o3.ostrs_.push_back ("base o3o3o3 one"); + o3.ostrs_.push_back ("base o3o3o3 two"); reference r; r.o1_ = &o1; @@ -81,14 +103,20 @@ main (int argc, char* argv[]) empty e; e.comp_.bools.push_back (true); e.comp_.bools.push_back (true); + e.comp_.obools.push_back (true); + e.comp_.obools.push_back (true); e.comp_.num = 14; e.comp_.str = "comp eee"; e.comp_.nums.push_back (141); e.comp_.nums.push_back (142); + e.comp_.onums.push_back (141); + e.comp_.onums.push_back (142); e.num_ = 4; e.str_ = "base eee"; e.strs_.push_back ("base eee one"); e.strs_.push_back ("base eee two"); + e.ostrs_.push_back ("base eee one"); + e.ostrs_.push_back ("base eee two"); // persist // @@ -125,6 +153,19 @@ main (int argc, char* argv[]) delete lr->o1_; } + // update + // + { + transaction t (db->begin ()); + db->update (b); + db->update (o1); + db->update (o2); + db->update (o3); + db->update (r); + db->update (e); + t.commit (); + } + // query // { @@ -173,6 +214,19 @@ main (int argc, char* argv[]) t.commit (); } + + // erase + // + { + transaction t (db->begin ()); + db->erase (b); + db->erase (o1); + db->erase (o2); + db->erase (o3); + db->erase (r); + db->erase (e); + t.commit (); + } } catch (const odb::exception& e) { diff --git a/common/inheritance/reuse/test.hxx b/common/inheritance/reuse/test.hxx index 8222f97..2b566ef 100644 --- a/common/inheritance/reuse/test.hxx +++ b/common/inheritance/reuse/test.hxx @@ -9,16 +9,18 @@ #include #include +#include #pragma db value struct comp_base { std::vector bools; + odb::vector obools; bool operator== (const comp_base& y) const { - return bools == y.bools; + return bools == y.bools && obools == y.obools; } }; @@ -29,6 +31,7 @@ struct comp: comp_base std::string str; std::vector nums; + odb::vector onums; bool operator== (const comp& y) const @@ -37,7 +40,8 @@ struct comp: comp_base static_cast (*this) == y && num == y.num && str == y.str && - nums == y.nums; + nums == y.nums && + onums == y.onums; } }; @@ -50,6 +54,7 @@ struct abstract_base std::string str_; std::vector strs_; + odb::vector ostrs_; bool operator== (const abstract_base& y) const @@ -58,7 +63,8 @@ struct abstract_base comp_ == y.comp_ && num_ == y.num_ && str_ == y.str_ && - strs_ == y.strs_; + strs_ == y.strs_ && + ostrs_ == y.ostrs_; } }; -- cgit v1.1