aboutsummaryrefslogtreecommitdiff
path: root/common/query/array
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-06-21 10:39:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-06-21 10:39:59 +0200
commit6cd8b9f561b912f264ba4f723845935c40a3cb95 (patch)
tree5983e0af3d2ee621242ca6707a58c89b9914d8f0 /common/query/array
parent236cd9bb1dd022e64d690c9b0080d1a15c5f61c7 (diff)
Add support for running tests in dynamic multi-database mode
Only possible in the development build system at this stage.
Diffstat (limited to 'common/query/array')
-rw-r--r--common/query/array/driver.cxx34
-rw-r--r--common/query/array/makefile29
-rw-r--r--common/query/array/test.hxx3
3 files changed, 50 insertions, 16 deletions
diff --git a/common/query/array/driver.cxx b/common/query/array/driver.cxx
index c449566..5b0d378 100644
--- a/common/query/array/driver.cxx
+++ b/common/query/array/driver.cxx
@@ -32,6 +32,7 @@ const odb::pgsql::database_type_id bt = odb::pgsql::id_bytea;
const odb::oracle::database_type_id bt = odb::oracle::id_raw;
#elif defined(DATABASE_MSSQL)
const odb::mssql::database_type_id bt = odb::mssql::id_binary;
+#elif defined(DATABASE_COMMON)
#else
# error unknown database
#endif
@@ -66,57 +67,78 @@ main (int argc, char* argv[])
// string
//
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::s == "abc")) == 1);
assert (size (db->query<object> (query::s == query::_val ("bcd"))) == 1);
assert (size (db->query<object> ("s = " + query::_val ("bcd"))) == 1);
assert (size (db->query<object> ("s = " + query::_ref ("bcd"))) == 1);
+#endif
{
char a[] = "bcd";
char* ra = a;
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::s == a)) == 1);
assert (size (db->query<object> (query::s == query::_val (a))) == 1);
+#endif
assert (size (db->query<object> (query::s == query::_ref (ra))) == 1);
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("s = " + query::_val (a))) == 1);
assert (size (db->query<object> ("s = " + query::_ref (a))) == 1);
+#endif
}
{
const char a[] = "bcd";
const char* ra = a;
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::s == a)) == 1);
assert (size (db->query<object> (query::s == query::_val (a))) == 1);
+#endif
assert (size (db->query<object> (query::s == query::_ref (ra))) == 1);
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("s = " + query::_val (a))) == 1);
assert (size (db->query<object> ("s = " + query::_ref (a))) == 1);
+#endif
}
{
const char* p = "cde";
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::s == p)) == 1);
assert (size (db->query<object> (query::s == query::_val (p))) == 1);
+#endif
assert (size (db->query<object> (query::s == query::_ref (p))) == 1);
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("s = " + query::_val (p))) == 1);
assert (size (db->query<object> ("s = " + query::_ref (p))) == 1);
+#endif
}
{
char a[] = "cde";
char* p = a;
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::s == p)) == 1);
assert (size (db->query<object> (query::s == query::_val (p))) == 1);
+#endif
assert (size (db->query<object> (query::s == query::_ref (p))) == 1);
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("s = " + query::_val (p))) == 1);
assert (size (db->query<object> ("s = " + query::_ref (p))) == 1);
+#endif
}
+#ifndef DATABASE_COMMON
string s ("abc");
//assert (size (db->query<object> (query::s == s)) == 1);
assert (size (db->query<object> (query::s == s.c_str ())) == 1);
//assert (size (db->query<object> (query::s == query::_val (s))) == 1);
assert (size (db->query<object> (query::s == query::_val (s.c_str ()))) == 1);
+
assert (size (db->query<object> ("s = " + query::_val (s))) == 1);
assert (size (db->query<object> ("s = " + query::_ref (s))) == 1);
+#endif
assert (size (db->query<object> (query::s == query::s1)) == 3);
@@ -126,12 +148,16 @@ main (int argc, char* argv[])
array<char, 17> a;
strcpy (a.data (), "abc");
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::a == a)) == 1);
assert (size (db->query<object> (query::a == query::_val (a))) == 1);
+#endif
assert (size (db->query<object> (query::a == query::_ref (a))) == 1);
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("a = " + query::_val (a))) == 1);
assert (size (db->query<object> ("a = " + query::_ref (a))) == 1);
#endif
+#endif
// char
//
@@ -141,18 +167,26 @@ main (int argc, char* argv[])
assert (size (db->query<object> (query::c == query::_val (c))) == 1);
assert (size (db->query<object> (query::c == query::_ref (c))) == 1);
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("c = " + query::_val ('c'))) == 1);
assert (size (db->query<object> ("c = " + query::_ref (c))) == 1);
+#endif
assert (size (db->query<object> (query::c == query::c1)) == 3);
// buffer
//
+#ifndef DATABASE_COMMON
assert (size (db->query<object> (query::b == buf)) == 3);
assert (size (db->query<object> (query::b == query::_val (buf))) == 3);
+#endif
+
assert (size (db->query<object> (query::b == query::_ref (buf))) == 3);
+
+#ifndef DATABASE_COMMON
assert (size (db->query<object> ("b = " + query::_val<bt> (buf))) == 3);
assert (size (db->query<object> ("b = " + query::_ref<bt> (buf))) == 3);
+#endif
t.commit ();
}
diff --git a/common/query/array/makefile b/common/query/array/makefile
index 3708b9d..d8fa45b 100644
--- a/common/query/array/makefile
+++ b/common/query/array/makefile
@@ -6,17 +6,14 @@ 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))
+genf := $(call odb-gen,$(odb_hdr))
+gen := $(addprefix $(out_base)/,$(genf))
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) $(filter %.o,$(gen:.cxx=.o))
cxx_od := $(cxx_obj:.o=.o.d)
common.l := $(out_root)/libcommon/common/common.l
common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options
-driver := $(out_base)/driver
-dist := $(out_base)/.dist
-test := $(out_base)/.test
-clean := $(out_base)/.clean
-
# Import.
#
$(call import,\
@@ -29,9 +26,6 @@ $(driver): $(cxx_obj) $(common.l)
$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_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) $(dist): export odb_options += --generate-schema --generate-query \
@@ -39,7 +33,11 @@ $(gen) $(dist): export odb_options += --generate-schema --generate-query \
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
+ifneq ($(db_id),common)
$(gen): odb_options += --database $(db_id)
+else
+$(gen): odb_options += --multi-database dynamic
+endif
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
@@ -66,12 +64,11 @@ $(dist):
# Test.
#
-$(test): $(driver) $(src_base)/test.std
- $(call schema)
- $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options \
->$(out_base)/test.out)
- $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out)
- $(call message,,rm -f $(out_base)/test.out)
+ifneq ($(db_id),common)
+$(eval $(call test-rule))
+else
+$(foreach d,$(databases),$(eval $(call test-rule,$d)))
+endif
# Clean.
#
@@ -79,7 +76,7 @@ $(clean): \
$(driver).o.clean \
$(addsuffix .cxx.clean,$(cxx_obj)) \
$(addsuffix .cxx.clean,$(cxx_od)) \
- $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+ $(addsuffix .hxx.clean,$(filter %.cxx,$(gen)))
$(call message,,rm -f $(out_base)/test.out)
# Generated .gitignore.
diff --git a/common/query/array/test.hxx b/common/query/array/test.hxx
index e086a44..e9cbd15 100644
--- a/common/query/array/test.hxx
+++ b/common/query/array/test.hxx
@@ -46,6 +46,8 @@ struct object
# pragma db type("VARCHAR(16)")
# elif defined(ODB_DATABASE_SQLITE)
# pragma db type("TEXT")
+# elif defined(ODB_DATABASE_COMMON)
+# pragma db type("DYMMU") // Necessary to make it a value.
# else
# error unknown database
# endif
@@ -67,6 +69,7 @@ struct object
# pragma db type("RAW(16)")
# elif defined(ODB_DATABASE_MSSQL)
# pragma db type("BINARY(16)")
+# elif defined(ODB_DATABASE_COMMON)
# else
# error unknown database
# endif