diff options
-rw-r--r-- | common/wrapper/driver.cxx | 64 | ||||
-rw-r--r-- | common/wrapper/test.hxx | 59 |
2 files changed, 70 insertions, 53 deletions
diff --git a/common/wrapper/driver.cxx b/common/wrapper/driver.cxx index d8985fa..b434dba 100644 --- a/common/wrapper/driver.cxx +++ b/common/wrapper/driver.cxx @@ -27,45 +27,55 @@ main (int argc, char* argv[]) { auto_ptr<database> db (create_database (argc, argv)); + // Test 1: simple values. // - // Simple values. - // - unsigned long id; { - object o; - o.num.reset (new int (123)); - o.nstrs.push_back (nullable_string ()); - o.nstrs.push_back (nullable_string ("123")); + using namespace test1; + + unsigned long id1, id2; + { + object1 o1; + object2 o2; + + o1.num.reset (new int (123)); + o1.nstrs.push_back (nullable_string ()); + o1.nstrs.push_back (nullable_string ("123")); + #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) - o.sstrs.push_back (str_sptr ()); - o.sstrs.push_back (str_sptr (new string ("123"))); + o2.sstrs.push_back (str_sptr ()); + o2.sstrs.push_back (str_sptr (new string ("123"))); #endif - transaction t (db->begin ()); - id = db->persist (o); - t.commit (); - } + transaction t (db->begin ()); + id1 = db->persist (o1); + id2 = db->persist (o2); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<object1> o1 (db->load<object1> (id1)); + auto_ptr<object2> o2 (db->load<object2> (id2)); + t.commit (); + + assert (*o1->num == 123); + assert (o1->str.get () == 0); + assert (o1->nstr.null ()); + assert (o1->nstrs[0].null ()); + assert (o1->nstrs[1].get () == "123"); - { - transaction t (db->begin ()); - auto_ptr<object> o (db->load<object> (id)); - t.commit (); - - assert (*o->num == 123); - assert (o->str.get () == 0); - assert (o->nstr.null ()); - assert (o->nstrs[0].null ()); - assert (o->nstrs[1].get () == "123"); #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) - assert (!o->sstr); - assert (!o->sstrs[0]); - assert (*o->sstrs[1] == "123"); + assert (!o2->sstr); + assert (!o2->sstrs[0]); + assert (*o2->sstrs[1] == "123"); #endif + } } // // Composite values. // + unsigned long id; { comp_object co; @@ -134,8 +144,6 @@ main (int argc, char* argv[]) { using namespace test5; - using test5::object; //@@ tmp - object o1, o2; o1.v.push_back (nullable<comp> ()); diff --git a/common/wrapper/test.hxx b/common/wrapper/test.hxx index 399073d..f308409 100644 --- a/common/wrapper/test.hxx +++ b/common/wrapper/test.hxx @@ -20,46 +20,55 @@ using odb::nullable; +// Test 1: simple values. // -// Simple values. -// - -typedef nullable<std::string> nullable_string; +#pragma db namespace table("t1_") +namespace test1 +{ + typedef nullable<std::string> nullable_string; #ifdef HAVE_CXX11 -typedef std::unique_ptr<int> num_uptr; -typedef std::unique_ptr<std::string> str_uptr; -typedef std::shared_ptr<std::string> str_sptr; + typedef std::unique_ptr<int> num_uptr; + typedef std::unique_ptr<std::string> str_uptr; + typedef std::shared_ptr<std::string> str_sptr; #else -typedef std::auto_ptr<int> num_uptr; -typedef std::auto_ptr<std::string> str_uptr; + typedef std::auto_ptr<int> num_uptr; + typedef std::auto_ptr<std::string> str_uptr; # ifdef HAVE_TR1_MEMORY -typedef std::tr1::shared_ptr<std::string> str_sptr; + typedef std::tr1::shared_ptr<std::string> str_sptr; # endif #endif -#pragma db object table("obj") -struct object -{ - #pragma db id auto - unsigned long id_; + #pragma db object table("obj1") + struct object1 + { + #pragma db id auto + unsigned long id_; + + num_uptr num; - num_uptr num; + #pragma db null + str_uptr str; - #pragma db null - str_uptr str; + nullable_string nstr; + std::vector<nullable_string> nstrs; + }; - nullable_string nstr; - std::vector<nullable_string> nstrs; + #pragma db object + struct object2 + { + #pragma db id auto + unsigned long id_; #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) - #pragma db null - str_sptr sstr; + #pragma db null + str_sptr sstr; - #pragma db value_null - std::vector<str_sptr> sstrs; + #pragma db value_null + std::vector<str_sptr> sstrs; #endif -}; + }; +} // // Composite values. |