aboutsummaryrefslogtreecommitdiff
path: root/tracer
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:57:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:57:53 +0200
commitca42db0da0d12b1dcdee1cc82dbbd171131cb628 (patch)
tree166fb9b3d51f686688da9ff86c5a51f3cc36a477 /tracer
parentbdb7fa4620c9950b16e8292c22424bbf15a25613 (diff)
Initial set of tests
Diffstat (limited to 'tracer')
-rw-r--r--tracer/makefile20
-rw-r--r--tracer/object/driver.cxx78
-rw-r--r--tracer/object/makefile81
-rw-r--r--tracer/object/test.hxx44
-rw-r--r--tracer/object/test.std32
-rw-r--r--tracer/transaction/driver.cxx100
-rw-r--r--tracer/transaction/makefile65
-rw-r--r--tracer/transaction/test.std25
8 files changed, 445 insertions, 0 deletions
diff --git a/tracer/makefile b/tracer/makefile
new file mode 100644
index 0000000..41368ea
--- /dev/null
+++ b/tracer/makefile
@@ -0,0 +1,20 @@
+# file : tracer/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : GNU GPL; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
+
+tests := \
+object \
+transaction
+
+default := $(out_base)/
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests)))
+$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests)))
+$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests)))
+
+$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile))
diff --git a/tracer/object/driver.cxx b/tracer/object/driver.cxx
new file mode 100644
index 0000000..8680b0a
--- /dev/null
+++ b/tracer/object/driver.cxx
@@ -0,0 +1,78 @@
+// file : tracer/object/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cassert>
+#include <iostream>
+
+#include <odb/transaction.hxx>
+#include <odb/tracer/database.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+using namespace std;
+using namespace odb;
+
+using odb::shared_ptr;
+
+int
+main ()
+{
+ tracer::database db;
+
+ // transient -> persistent in transaction
+ //
+ cout << "test 001" << endl;
+ {
+ shared_ptr<object1> o1 (new (shared) object1 (1));
+ transaction t (db.begin_transaction ());
+ cout << "s 1" << endl;
+ db.persist (o1);
+ cout << "s 2" << endl;
+ t.commit ();
+ cout << "s 3" << endl;
+ }
+
+ // persistent -> transient in transaction
+ //
+ cout << "test 002" << endl;
+ {
+ shared_ptr<object1> o1 (new (shared) object1 (1));
+ transaction t (db.begin_transaction ());
+ cout << "s 1" << endl;
+ db.persist (o1);
+ cout << "s 2" << endl;
+ db.erase (o1);
+ cout << "s 3" << endl;
+ t.commit ();
+ cout << "s 4" << endl;
+ }
+
+ // load in transaction
+ //
+ cout << "test 003" << endl;
+ {
+ transaction t (db.begin_transaction ());
+ cout << "s 1" << endl;
+ shared_ptr<object1> o1 (db.load<object1> (1));
+ cout << "s 2" << endl;
+ t.commit ();
+ cout << "s 3" << endl;
+ }
+
+ // persistent/clean -> persistent/dirty in transaction
+ //
+ cout << "test 004" << endl;
+ {
+ transaction t (db.begin_transaction ());
+ cout << "s 1" << endl;
+ shared_ptr<object1> o1 (db.load<object1> (1));
+ cout << "s 2" << endl;
+ db.modified (o1);
+ cout << "s 3" << endl;
+ t.commit ();
+ cout << "s 4" << endl;
+ }
+}
diff --git a/tracer/object/makefile b/tracer/object/makefile
new file mode 100644
index 0000000..ed7c562
--- /dev/null
+++ b/tracer/object/makefile
@@ -0,0 +1,81 @@
+# file : tracer/object/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 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)
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+$(call import,\
+ $(scf_root)/import/libodb/stub.make,\
+ l: odb.l,cpp-options: odb.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libodb-tracer/stub.make,\
+ l: odb_tracer.l,cpp-options: odb_tracer.l.cpp-options)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(odb_tracer.l) $(odb.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base)
+$(cxx_obj) $(cxx_od): $(odb_tracer.l.cpp-options) $(odb.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen): odb_options += --database tracer
+$(gen): cpp_options := -I$(out_base)
+$(gen): $(odb_tracer.l.cpp-options) $(odb.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Test.
+#
+$(test): $(driver) $(src_base)/test.std
+ $(call message,test $<,$< | diff -u $(src_base)/test.std -)
+
+# 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))
+
+# 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,$(odb_rules))
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
diff --git a/tracer/object/test.hxx b/tracer/object/test.hxx
new file mode 100644
index 0000000..a988411
--- /dev/null
+++ b/tracer/object/test.hxx
@@ -0,0 +1,44 @@
+// file : tracer/object/test.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <iostream>
+#include <odb/core.hxx>
+
+#pragma odb object
+struct object1
+{
+ object1 (unsigned long id)
+ : id_ (id)
+ {
+ }
+
+ object1 ()
+ {
+ }
+
+ #pragma odb id
+ unsigned long id_;
+};
+
+#pragma odb object
+struct object2
+{
+ object2 (const std::string& id)
+ : id_ (id)
+ {
+ }
+
+ object2 ()
+ {
+ }
+
+ #pragma odb id
+ std::string id_;
+};
+
+#endif // TEST_HXX
diff --git a/tracer/object/test.std b/tracer/object/test.std
new file mode 100644
index 0000000..c7e458c
--- /dev/null
+++ b/tracer/object/test.std
@@ -0,0 +1,32 @@
+test 001
+begin transaction
+s 1
+insert ::object1 id 1
+s 2
+commit transaction
+s 3
+test 002
+begin transaction
+s 1
+insert ::object1 id 1
+s 2
+s 3
+delete ::object1 id 1
+commit transaction
+s 4
+test 003
+begin transaction
+s 1
+select ::object1 id 1
+s 2
+commit transaction
+s 3
+test 004
+begin transaction
+s 1
+select ::object1 id 1
+s 2
+s 3
+update ::object1 id 1
+commit transaction
+s 4
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 <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cassert>
+#include <iostream>
+
+#include <odb/exceptions.hxx>
+#include <odb/session.hxx>
+#include <odb/transaction.hxx>
+#include <odb/tracer/database.hxx>
+#include <odb/tracer/transaction.hxx>
+
+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 ());
+ }
+}
diff --git a/tracer/transaction/makefile b/tracer/transaction/makefile
new file mode 100644
index 0000000..5919e6e
--- /dev/null
+++ b/tracer/transaction/makefile
@@ -0,0 +1,65 @@
+# file : tracer/transaction/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/libodb/stub.make,\
+ l: odb.l,cpp-options: odb.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libodb-tracer/stub.make,\
+ l: odb_tracer.l,cpp-options: odb_tracer.l.cpp-options)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(odb_tracer.l) $(odb.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base)
+$(cxx_obj) $(cxx_od): $(odb_tracer.l.cpp-options) $(odb.l.cpp-options)
+
+$(call include-dep,$(cxx_od))
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Test.
+#
+$(test): $(driver) $(src_base)/test.std
+ $(call message,test $<,$< | diff -u $(src_base)/test.std -)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od))
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
diff --git a/tracer/transaction/test.std b/tracer/transaction/test.std
new file mode 100644
index 0000000..8f962ef
--- /dev/null
+++ b/tracer/transaction/test.std
@@ -0,0 +1,25 @@
+test 001
+begin transaction
+rollback transaction
+test 002
+begin transaction
+commit transaction
+test 003
+begin transaction
+rollback transaction
+test 004
+begin transaction
+rollback transaction
+test 005
+begin transaction
+already_in_transaction
+rollback transaction
+test 006
+begin transaction
+rollback transaction
+test 007
+begin transaction
+rollback transaction
+test 008
+begin transaction
+rollback transaction