From b9161e6e332cb0279ef8616dbbce4c90b60bce15 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 3 Aug 2010 14:12:48 +0200 Subject: New tests --- mysql/truncation/driver.cxx | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 mysql/truncation/driver.cxx (limited to 'mysql/truncation/driver.cxx') diff --git a/mysql/truncation/driver.cxx b/mysql/truncation/driver.cxx new file mode 100644 index 0000000..f94205e --- /dev/null +++ b/mysql/truncation/driver.cxx @@ -0,0 +1,102 @@ +// file : mysql/truncation/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test insufficient buffer/truncation handling. +// + +#include // std::auto_ptr +#include +#include + +#include +#include + +#include + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb; + +using odb::shared_ptr; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // The default pre-allocated buffer is 512 bytes long. + // + string long_str (640, 'c'); // This will get the buffer to 1024 + string longer_str (1025, 'b'); + + // Run persist/load so that the initial bindings are established + // (version == 0). + // + { + object1 o (1); + o.str_ = "test string"; + + transaction t (db->begin_transaction ()); + db->persist (o); + db->load (1, o); + t.commit (); + } + + { + object2 o (2); + o.str_ = "test string"; + + transaction t (db->begin_transaction ()); + db->persist (o); + db->load (2, o); + t.commit (); + } + + // Store/load the long string which should trigger buffer growth. + // + { + object1 o (3); + o.str_ = long_str; + + transaction t (db->begin_transaction ()); + db->persist (o); + t.commit (); + } + + { + transaction t (db->begin_transaction ()); + auto_ptr o (db->load (3)); + assert (o->str_ == long_str); + t.commit (); + } + + // Store/load longer string. + // + { + object1 o (3); + o.str_ = longer_str; + + transaction t (db->begin_transaction ()); + db->store (o); + t.commit (); + } + + { + transaction t (db->begin_transaction ()); + auto_ptr o (db->load (3)); + assert (o->str_ == longer_str); + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} -- cgit v1.1