From ca42db0da0d12b1dcdee1cc82dbbd171131cb628 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Jun 2010 16:57:53 +0200 Subject: Initial set of tests --- tracer/transaction/driver.cxx | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tracer/transaction/driver.cxx (limited to 'tracer/transaction/driver.cxx') diff --git a/tracer/transaction/driver.cxx b/tracer/transaction/driver.cxx new file mode 100644 index 0000000..164b9a0 --- /dev/null +++ b/tracer/transaction/driver.cxx @@ -0,0 +1,100 @@ +// file : tracer/transaction/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace odb; + +int +main () +{ + tracer::database db; + + assert (!transaction::has_current ()); + + // Current and db accessors. + // + cout << "test 001" << endl; + { + transaction t (db.begin_transaction ()); + assert (&t.database () == &db); + assert (transaction::has_current ()); + assert (&transaction::current () == &t); + } + + // Commit. + // + cout << "test 002" << endl; + { + transaction t (db.begin_transaction ()); + t.commit (); + } + + // Rollback. + // + cout << "test 003" << endl; + { + transaction t (db.begin_transaction ()); + t.rollback (); + } + + // Auto rollback. + // + cout << "test 004" << endl; + { + transaction t (db.begin_transaction ()); + } + + // Nested transaction. + // + cout << "test 005" << endl; + { + transaction t (db.begin_transaction ()); + try + { + transaction n (db.begin_transaction ()); + } + catch (const already_in_transaction&) + { + cout << "already_in_transaction" << endl; + } + } + + // Existing session via current. + // + cout << "test 006" << endl; + { + session s; + transaction t (db.begin_transaction ()); + assert (&t.session () == &s); + } + + // Existing session passed explicitly. + // + cout << "test 007" << endl; + { + session s; + transaction t (db.begin_transaction (s)); + assert (&t.session () == &s); + } + + // Concrete transaction type. + // + cout << "test 008" << endl; + { + assert (sizeof (tracer::transaction) == sizeof (transaction)); + + tracer::transaction t (db.begin_transaction ()); + tracer::transaction& r (tracer::transaction::current ()); + } +} -- cgit v1.1