aboutsummaryrefslogtreecommitdiff
path: root/common/schema
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 /common/schema
parentbdb7fa4620c9950b16e8292c22424bbf15a25613 (diff)
Initial set of tests
Diffstat (limited to 'common/schema')
-rw-r--r--common/schema/driver.cxx43
-rw-r--r--common/schema/makefile82
-rw-r--r--common/schema/test.hxx58
-rw-r--r--common/schema/test.std1
4 files changed, 184 insertions, 0 deletions
diff --git a/common/schema/driver.cxx b/common/schema/driver.cxx
new file mode 100644
index 0000000..4d27e81
--- /dev/null
+++ b/common/schema/driver.cxx
@@ -0,0 +1,43 @@
+// file : common/schema/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 <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+
+#include <common.hxx>
+
+#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<database> db (create_database (argc, argv));
+
+ //
+ //
+ cout << "test 001" << endl;
+ {
+ transaction t (db->begin_transaction ());
+ t.commit ();
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/common/schema/makefile b/common/schema/makefile
new file mode 100644
index 0000000..29cca5f
--- /dev/null
+++ b/common/schema/makefile
@@ -0,0 +1,82 @@
+# file : common/schema/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)
+
+common.l := $(out_root)/libcommon/common.l
+common.l.cpp-options := $(out_root)/libcommon/common.l.cpp-options
+
+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)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(common.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base)
+$(cxx_obj) $(cxx_od): $(common.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen): odb_options += --database $(db_id) --generate-schema
+$(gen): cpp_options := -I$(out_base)
+$(gen): $(common.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,sql $$1,$(dcf_root)/db-driver $$1, $(src_base)/test.sql)
+ $(call message,test $<,$< --options-file $(dcf_root)/db.options \
+| 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)
+
+# Dependencies.
+#
+$(call import,$(src_root)/libcommon/makefile)
diff --git a/common/schema/test.hxx b/common/schema/test.hxx
new file mode 100644
index 0000000..471d27b
--- /dev/null
+++ b/common/schema/test.hxx
@@ -0,0 +1,58 @@
+// file : common/schema/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 <string>
+#include <odb/core.hxx>
+
+// Table names.
+//
+#pragma odb object table ("TABLE_EXPLICIT")
+struct table_explicit
+{
+ #pragma odb id
+ unsigned long id_;
+};
+
+#pragma odb object
+struct table_implicit
+{
+ #pragma odb id
+ unsigned long id_;
+};
+
+// Column names.
+//
+#pragma odb object
+struct column
+{
+ #pragma odb id
+ int m1;
+
+ #pragma odb column ("foo")
+ int m2;
+
+ int m_m3;
+ int _m4;
+ int m5_;
+ int m_;
+ int m__;
+};
+
+// Column types.
+//
+#pragma odb object
+struct type
+{
+ #pragma odb id
+ int id;
+
+ #pragma odb type ("INTEGER")
+ bool m1;
+};
+
+#endif // TEST_HXX
diff --git a/common/schema/test.std b/common/schema/test.std
new file mode 100644
index 0000000..af8d8e7
--- /dev/null
+++ b/common/schema/test.std
@@ -0,0 +1 @@
+test 001