summaryrefslogtreecommitdiff
path: root/libdbpp/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'libdbpp/unittests')
m---------libdbpp/unittests/libdbpp-mysql0
m---------libdbpp/unittests/libdbpp-odbc0
m---------libdbpp/unittests/libdbpp-postgresql0
m---------libdbpp/unittests/libdbpp-sqlite0
-rw-r--r--libdbpp/unittests/mockdb.cpp6
-rw-r--r--libdbpp/unittests/mockdb.h35
-rw-r--r--libdbpp/unittests/testConnection.cpp41
-rw-r--r--libdbpp/unittests/testConnectionPool.cpp18
-rw-r--r--libdbpp/unittests/testMock.cpp37
-rw-r--r--libdbpp/unittests/testParse.cpp107
-rw-r--r--libdbpp/unittests/testPatch.cpp124
-rw-r--r--libdbpp/unittests/testUtils.cpp109
12 files changed, 236 insertions, 241 deletions
diff --git a/libdbpp/unittests/libdbpp-mysql b/libdbpp/unittests/libdbpp-mysql
-Subproject ef7a2108654dd8afb18fd27f0f84f152f7f796c
+Subproject d77f801dc01c5e30c0d96e907c8ac14f23d7b63
diff --git a/libdbpp/unittests/libdbpp-odbc b/libdbpp/unittests/libdbpp-odbc
-Subproject e5c210fcbddcbb73ca387cf0eb3c5a6f91b2f4a
+Subproject 22e0839fd6912b888b7c3c790573aef1f5df393
diff --git a/libdbpp/unittests/libdbpp-postgresql b/libdbpp/unittests/libdbpp-postgresql
-Subproject 448720848b383639c37f5f0487efdf8c0f0ed43
+Subproject 3bfa3dafe335479aade55507719071f7dceb0d8
diff --git a/libdbpp/unittests/libdbpp-sqlite b/libdbpp/unittests/libdbpp-sqlite
-Subproject f571f6b2bf1370b0757c29162988a40e02a82f9
+Subproject 0af57e2595922c9ee59d7cd489daf37a3550496
diff --git a/libdbpp/unittests/mockdb.cpp b/libdbpp/unittests/mockdb.cpp
index 54c1e3a..722592a 100644
--- a/libdbpp/unittests/mockdb.cpp
+++ b/libdbpp/unittests/mockdb.cpp
@@ -2,9 +2,7 @@
// LCOV_EXCL_START
-MockDb::MockDb(const std::string &)
-{
-}
+MockDb::MockDb(const std::string &) { }
void
MockDb::beginTxInt()
@@ -22,7 +20,6 @@ MockDb::rollbackTxInt()
void
MockDb::ping() const
{
-
}
DB::BulkDeleteStyle
@@ -85,4 +82,3 @@ FACTORY(MockMock, DB::MockDatabaseFactory);
FACTORY(MockDb, DB::ConnectionFactory);
// LCOV_EXCL_STOP
-
diff --git a/libdbpp/unittests/mockdb.h b/libdbpp/unittests/mockdb.h
index 379d076..f291487 100644
--- a/libdbpp/unittests/mockdb.h
+++ b/libdbpp/unittests/mockdb.h
@@ -5,30 +5,29 @@
#include "../mockDatabase.h"
class MockDb : public DB::Connection {
- public:
- MockDb(const std::string &);
+public:
+ MockDb(const std::string &);
- void beginTxInt() override;
- void commitTxInt() override;
- void rollbackTxInt() override;
- void ping() const override;
- DB::BulkDeleteStyle bulkDeleteStyle() const override;
- DB::BulkUpdateStyle bulkUpdateStyle() const override;
+ void beginTxInt() override;
+ void commitTxInt() override;
+ void rollbackTxInt() override;
+ void ping() const override;
+ DB::BulkDeleteStyle bulkDeleteStyle() const override;
+ DB::BulkUpdateStyle bulkUpdateStyle() const override;
- void execute(const std::string & sql, const DB::CommandOptionsCPtr &) override;
- DB::SelectCommandPtr select(const std::string &, const DB::CommandOptionsCPtr &) override;
- DB::ModifyCommandPtr modify(const std::string &, const DB::CommandOptionsCPtr &) override;
+ void execute(const std::string & sql, const DB::CommandOptionsCPtr &) override;
+ DB::SelectCommandPtr select(const std::string &, const DB::CommandOptionsCPtr &) override;
+ DB::ModifyCommandPtr modify(const std::string &, const DB::CommandOptionsCPtr &) override;
- mutable std::vector<std::string> executed;
+ mutable std::vector<std::string> executed;
};
class MockMock : public DB::MockDatabase {
- public:
- MockMock(const std::string &, const std::string &, const std::vector<std::filesystem::path> &);
- DB::ConnectionPtr openConnection() const override;
- void CreateNewDatabase() const override;
- void DropDatabase() const override;
+public:
+ MockMock(const std::string &, const std::string &, const std::vector<std::filesystem::path> &);
+ DB::ConnectionPtr openConnection() const override;
+ void CreateNewDatabase() const override;
+ void DropDatabase() const override;
};
#endif
-
diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp
index 491c236..46a8e6a 100644
--- a/libdbpp/unittests/testConnection.cpp
+++ b/libdbpp/unittests/testConnection.cpp
@@ -1,17 +1,17 @@
#define BOOST_TEST_MODULE DbConnection
#include <boost/test/unit_test.hpp>
-#include <factory.h>
+#include "mockdb.h"
#include <connection.h>
-#include <pq-command.h>
#include <definedDirs.h>
-#include <fstream>
-#include <vector>
#include <error.h>
+#include <factory.h>
+#include <fstream>
+#include <pq-command.h>
#include <sqlParse.h>
-#include "mockdb.h"
+#include <vector>
-BOOST_AUTO_TEST_CASE( create )
+BOOST_AUTO_TEST_CASE(create)
{
auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
BOOST_REQUIRE(mock);
@@ -20,17 +20,16 @@ BOOST_AUTO_TEST_CASE( create )
BOOST_REQUIRE(!mock->select(""));
}
-BOOST_AUTO_TEST_CASE( resolve )
+BOOST_AUTO_TEST_CASE(resolve)
{
auto libname = DB::Connection::resolvePlugin(typeid(DB::Connection), "postgresql");
BOOST_REQUIRE(libname);
BOOST_REQUIRE_EQUAL("libdbpp-postgresql.so", *libname);
BOOST_REQUIRE_THROW(
- (void)DB::ConnectionFactory::createNew("otherdb", "doesn't matter"),
- AdHoc::LoadLibraryException);
+ (void)DB::ConnectionFactory::createNew("otherdb", "doesn't matter"), AdHoc::LoadLibraryException);
}
-BOOST_AUTO_TEST_CASE( finish )
+BOOST_AUTO_TEST_CASE(finish)
{
auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
BOOST_REQUIRE(mock);
@@ -45,7 +44,7 @@ BOOST_AUTO_TEST_CASE( finish )
mock->finish();
}
-BOOST_AUTO_TEST_CASE( tx )
+BOOST_AUTO_TEST_CASE(tx)
{
auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
BOOST_REQUIRE(mock);
@@ -64,7 +63,7 @@ BOOST_AUTO_TEST_CASE( tx )
BOOST_REQUIRE_EQUAL(false, mock->inTx());
}
-BOOST_AUTO_TEST_CASE( txscope )
+BOOST_AUTO_TEST_CASE(txscope)
{
auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
BOOST_REQUIRE(mock);
@@ -84,7 +83,7 @@ BOOST_AUTO_TEST_CASE( txscope )
}
}
-BOOST_AUTO_TEST_CASE( savepoints )
+BOOST_AUTO_TEST_CASE(savepoints)
{
auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
auto mockdb = std::dynamic_pointer_cast<MockDb>(mock);
@@ -101,7 +100,7 @@ BOOST_AUTO_TEST_CASE( savepoints )
BOOST_REQUIRE_EQUAL("ROLLBACK TO SAVEPOINT sp1", *mockdb->executed.rbegin());
}
-BOOST_AUTO_TEST_CASE( commandOptions )
+BOOST_AUTO_TEST_CASE(commandOptions)
{
auto optsDefault = DB::CommandOptionsFactory::createNew("", 1234, {});
BOOST_REQUIRE(optsDefault);
@@ -109,12 +108,9 @@ BOOST_AUTO_TEST_CASE( commandOptions )
BOOST_REQUIRE_EQUAL(1234, *optsDefault->hash);
}
-BOOST_AUTO_TEST_CASE( commandOptionsPq1 )
+BOOST_AUTO_TEST_CASE(commandOptionsPq1)
{
- auto optsBase = DB::CommandOptionsFactory::createNew("postgresql", 12345, {
- {"no-cursor", ""},
- {"page-size", "5"}
- });
+ auto optsBase = DB::CommandOptionsFactory::createNew("postgresql", 12345, {{"no-cursor", ""}, {"page-size", "5"}});
BOOST_REQUIRE(optsBase);
auto optsPq = std::dynamic_pointer_cast<PQ::CommandOptions>(optsBase);
BOOST_REQUIRE(optsPq);
@@ -124,11 +120,9 @@ BOOST_AUTO_TEST_CASE( commandOptionsPq1 )
BOOST_REQUIRE_EQUAL(5, optsPq->fetchTuples);
}
-BOOST_AUTO_TEST_CASE( commandOptionsPq2 )
+BOOST_AUTO_TEST_CASE(commandOptionsPq2)
{
- auto optsBase = DB::CommandOptionsFactory::createNew("postgresql", 123456, {
- {"page-size", "50"}
- });
+ auto optsBase = DB::CommandOptionsFactory::createNew("postgresql", 123456, {{"page-size", "50"}});
BOOST_REQUIRE(optsBase);
auto optsPq = std::dynamic_pointer_cast<PQ::CommandOptions>(optsBase);
BOOST_REQUIRE(optsPq);
@@ -137,4 +131,3 @@ BOOST_AUTO_TEST_CASE( commandOptionsPq2 )
BOOST_REQUIRE(optsPq->useCursor);
BOOST_REQUIRE_EQUAL(50, optsPq->fetchTuples);
}
-
diff --git a/libdbpp/unittests/testConnectionPool.cpp b/libdbpp/unittests/testConnectionPool.cpp
index de3de79..7ef6586 100644
--- a/libdbpp/unittests/testConnectionPool.cpp
+++ b/libdbpp/unittests/testConnectionPool.cpp
@@ -1,20 +1,21 @@
#define BOOST_TEST_MODULE DbConnectionPool
#include <boost/test/unit_test.hpp>
+#include <buffer.h>
#include <connectionPool.h>
#include <pq-mock.h>
-#include <buffer.h>
class MockPool : public DB::PluginMock<PQ::Mock>, public DB::ConnectionPool {
- public:
- MockPool() :
- PluginMock<PQ::Mock>("pqmock", { }, "user=postgres dbname=postgres"),
- DB::ConnectionPool(4, 2, "postgresql", stringbf("user=postgres dbname=%s", databaseName()))
- {
- }
+public:
+ MockPool() :
+ PluginMock<PQ::Mock>("pqmock", {}, "user=postgres dbname=postgres"), DB::ConnectionPool(4, 2, "postgresql",
+ stringbf("user=postgres dbname=%s",
+ databaseName()))
+ {
+ }
};
-BOOST_AUTO_TEST_CASE( basic )
+BOOST_AUTO_TEST_CASE(basic)
{
MockPool pool;
DB::Connection * cr;
@@ -38,4 +39,3 @@ BOOST_AUTO_TEST_CASE( basic )
BOOST_REQUIRE_EQUAL(0, pool.inUseCount());
BOOST_REQUIRE_EQUAL(2, pool.availableCount());
}
-
diff --git a/libdbpp/unittests/testMock.cpp b/libdbpp/unittests/testMock.cpp
index 43b757d..41c640d 100644
--- a/libdbpp/unittests/testMock.cpp
+++ b/libdbpp/unittests/testMock.cpp
@@ -1,20 +1,18 @@
#define BOOST_TEST_MODULE DbMock
#include <boost/test/unit_test.hpp>
-#include <definedDirs.h>
-#include <fstream>
#include "../error.h"
#include "../mockDatabase.h"
#include "mockdb.h"
+#include <definedDirs.h>
+#include <fstream>
-BOOST_AUTO_TEST_CASE( noFactory )
+BOOST_AUTO_TEST_CASE(noFactory)
{
- BOOST_REQUIRE_THROW({
- (void)DB::MockDatabaseFactory::get("not-found");
- }, AdHoc::LoadLibraryException);
+ BOOST_REQUIRE_THROW({ (void)DB::MockDatabaseFactory::get("not-found"); }, AdHoc::LoadLibraryException);
}
-BOOST_AUTO_TEST_CASE( mockFactory )
+BOOST_AUTO_TEST_CASE(mockFactory)
{
auto f = DB::MockDatabaseFactory::get("MockMock");
BOOST_REQUIRE(f);
@@ -26,19 +24,22 @@ BOOST_AUTO_TEST_CASE( mockFactory )
BOOST_REQUIRE_EQUAL(typeid(MockDb), typeid(cr));
}
-BOOST_AUTO_TEST_CASE( missingMock )
+BOOST_AUTO_TEST_CASE(missingMock)
{
- BOOST_REQUIRE_THROW({
- (void)DB::MockDatabaseFactory::createNew("MockMock",
- "user=postgres dbname=postgres", typeid(this).name(), { rootDir / "missing.sql" });
- }, std::fstream::failure);
+ BOOST_REQUIRE_THROW(
+ {
+ (void)DB::MockDatabaseFactory::createNew(
+ "MockMock", "user=postgres dbname=postgres", typeid(this).name(), {rootDir / "missing.sql"});
+ },
+ std::fstream::failure);
}
-BOOST_AUTO_TEST_CASE( failingMock )
+BOOST_AUTO_TEST_CASE(failingMock)
{
- BOOST_REQUIRE_THROW({
- (void)DB::MockDatabaseFactory::createNew("MockMock",
- "user=postgres dbname=postgres", typeid(this).name(), { rootDir / "badMock.sql" });
- }, DB::Error);
+ BOOST_REQUIRE_THROW(
+ {
+ (void)DB::MockDatabaseFactory::createNew(
+ "MockMock", "user=postgres dbname=postgres", typeid(this).name(), {rootDir / "badMock.sql"});
+ },
+ DB::Error);
}
-
diff --git a/libdbpp/unittests/testParse.cpp b/libdbpp/unittests/testParse.cpp
index 3764f43..6991242 100644
--- a/libdbpp/unittests/testParse.cpp
+++ b/libdbpp/unittests/testParse.cpp
@@ -1,92 +1,94 @@
#define BOOST_TEST_MODULE DbConnection
#include <boost/test/unit_test.hpp>
-#include <factory.h>
#include <connection.h>
#include <definedDirs.h>
-#include <fstream>
-#include <vector>
#include <error.h>
+#include <factory.h>
+#include <fstream>
#include <sqlParse.h>
+#include <vector>
using SQLs = std::vector<std::string>;
BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(SQLs);
class RecordingParser : std::fstream, public DB::SqlParse {
- public:
- explicit RecordingParser(const std::filesystem::path & p) :
- std::fstream(p),
- DB::SqlParse(*this, p.parent_path())
- {
- }
-
- void Comment(const std::string & c) const override
- {
- comments.push_back(c);
- }
-
- void Statement(const std::string & s) const override
- {
- executed.push_back(s);
- }
-
- mutable SQLs comments;
- mutable SQLs executed;
+public:
+ explicit RecordingParser(const std::filesystem::path & p) :
+ std::fstream(p), DB::SqlParse(*this, p.parent_path()) { }
+
+ void
+ Comment(const std::string & c) const override
+ {
+ comments.push_back(c);
+ }
+
+ void
+ Statement(const std::string & s) const override
+ {
+ executed.push_back(s);
+ }
+
+ mutable SQLs comments;
+ mutable SQLs executed;
};
template<typename E = DB::SqlParseException>
-void assertFail(const std::filesystem::path & p)
+void
+assertFail(const std::filesystem::path & p)
{
BOOST_TEST_CONTEXT(p) {
- BOOST_REQUIRE_THROW({
- RecordingParser s(p);
- s.Execute();
- }, E);
+ BOOST_REQUIRE_THROW(
+ {
+ RecordingParser s(p);
+ s.Execute();
+ },
+ E);
}
}
-BOOST_AUTO_TEST_CASE( parseBad )
+BOOST_AUTO_TEST_CASE(parseBad)
{
assertFail("/bad");
}
-BOOST_AUTO_TEST_CASE( parse )
+BOOST_AUTO_TEST_CASE(parse)
{
RecordingParser p(rootDir / "parseTest.sql");
p.Execute();
BOOST_REQUIRE_EQUAL(p.executed.size(), 3);
BOOST_REQUIRE_EQUAL(p.executed[1], "INSERT INTO name(t, i) VALUES('string', 3)");
auto cs = {
- "Single line comment",
- "",
- "",
- "",
- "",
- "Comment",
- "",
- "",
- "",
- "Multi line\n\t comment",
- "! Stupid MySQL terminates",
- "! comments with a ;",
- "! Because reasons",
+ "Single line comment",
+ "",
+ "",
+ "",
+ "",
+ "Comment",
+ "",
+ "",
+ "",
+ "Multi line\n\t comment",
+ "! Stupid MySQL terminates",
+ "! comments with a ;",
+ "! Because reasons",
};
BOOST_CHECK_EQUAL_COLLECTIONS(p.comments.begin(), p.comments.end(), cs.begin(), cs.end());
}
-BOOST_AUTO_TEST_CASE( parseDollarQuote )
+BOOST_AUTO_TEST_CASE(parseDollarQuote)
{
RecordingParser p(rootDir / "dollarQuote.sql");
p.Execute();
}
-BOOST_AUTO_TEST_CASE( parseScriptDir )
+BOOST_AUTO_TEST_CASE(parseScriptDir)
{
RecordingParser p(rootDir / "scriptDir.sql");
p.Execute();
}
-BOOST_AUTO_TEST_CASE( parseStringParse )
+BOOST_AUTO_TEST_CASE(parseStringParse)
{
RecordingParser p(rootDir / "stringParse.sql");
p.Execute();
@@ -94,7 +96,7 @@ BOOST_AUTO_TEST_CASE( parseStringParse )
BOOST_REQUIRE_EQUAL("INSERT INTO name(t, i) VALUES('fancy string '' \\' \\r \\n', 7)", p.executed[1]);
}
-BOOST_AUTO_TEST_CASE( indentedStatement )
+BOOST_AUTO_TEST_CASE(indentedStatement)
{
RecordingParser p(rootDir / "indentedStatement.sql");
p.Execute();
@@ -103,7 +105,7 @@ BOOST_AUTO_TEST_CASE( indentedStatement )
BOOST_REQUIRE(p.comments.empty());
}
-BOOST_AUTO_TEST_CASE( indentedOneLineComment )
+BOOST_AUTO_TEST_CASE(indentedOneLineComment)
{
RecordingParser p(rootDir / "indentedOneLineComment.sql");
p.Execute();
@@ -112,7 +114,7 @@ BOOST_AUTO_TEST_CASE( indentedOneLineComment )
BOOST_REQUIRE(p.executed.empty());
}
-BOOST_AUTO_TEST_CASE( indentedBlockComment )
+BOOST_AUTO_TEST_CASE(indentedBlockComment)
{
RecordingParser p(rootDir / "indentedBlockComment.sql");
p.Execute();
@@ -121,7 +123,7 @@ BOOST_AUTO_TEST_CASE( indentedBlockComment )
BOOST_REQUIRE(p.executed.empty());
}
-BOOST_AUTO_TEST_CASE( commentsMixedIn )
+BOOST_AUTO_TEST_CASE(commentsMixedIn)
{
RecordingParser p(rootDir / "commentsMixedIn.sql");
p.Execute();
@@ -133,18 +135,17 @@ BOOST_AUTO_TEST_CASE( commentsMixedIn )
BOOST_REQUIRE_EQUAL("And a timestamp", p.comments[2]);
}
-BOOST_AUTO_TEST_CASE( parseUnterminateComment )
+BOOST_AUTO_TEST_CASE(parseUnterminateComment)
{
assertFail(rootDir / "unterminatedComment.sql");
}
-BOOST_AUTO_TEST_CASE( parseUnterminateDollarQuote )
+BOOST_AUTO_TEST_CASE(parseUnterminateDollarQuote)
{
assertFail(rootDir / "unterminatedDollarQuote.sql");
}
-BOOST_AUTO_TEST_CASE( parseUnterminateString )
+BOOST_AUTO_TEST_CASE(parseUnterminateString)
{
assertFail(rootDir / "unterminatedString.sql");
}
-
diff --git a/libdbpp/unittests/testPatch.cpp b/libdbpp/unittests/testPatch.cpp
index 53fb49e..e81f9d7 100644
--- a/libdbpp/unittests/testPatch.cpp
+++ b/libdbpp/unittests/testPatch.cpp
@@ -1,55 +1,56 @@
#define BOOST_TEST_MODULE DbTablePatch
#include <boost/test/unit_test.hpp>
+#include <buffer.h>
+#include <command.h>
#include <connection.h>
#include <definedDirs.h>
#include <pq-mock.h>
-#include <command.h>
-#include <tablepatch.h>
-#include <sqlWriter.h>
-#include <buffer.h>
#include <selectcommandUtil.impl.h>
+#include <sqlWriter.h>
+#include <tablepatch.h>
class Mock : public DB::PluginMock<PQ::Mock> {
- public:
- Mock() :
- DB::PluginMock<PQ::Mock>("pqmock", { rootDir / "patch.sql" }, "user=postgres dbname=postgres")
- {
- }
+public:
+ Mock() : DB::PluginMock<PQ::Mock>("pqmock", {rootDir / "patch.sql"}, "user=postgres dbname=postgres") { }
};
class OrderByA : public DB::StaticSqlWriter {
- public:
- OrderByA() : DB::StaticSqlWriter("a") { }
+public:
+ OrderByA() : DB::StaticSqlWriter("a") { }
};
class WhereAequals1 : public DB::SqlWriter {
- public:
- void writeSql(AdHoc::Buffer & b) override
- {
- b.append("a.a = ?");
- }
- void bindParams(DB::Command * cmd, unsigned int & o) override
- {
- cmd->bindParamI(o++, 1);
- }
+public:
+ void
+ writeSql(AdHoc::Buffer & b) override
+ {
+ b.append("a.a = ?");
+ }
+ void
+ bindParams(DB::Command * cmd, unsigned int & o) override
+ {
+ cmd->bindParamI(o++, 1);
+ }
};
class MarkDeleted : public DB::SqlWriter {
- public:
- void writeSql(AdHoc::Buffer & b) override
- {
- b.append("deleted = ?");
- }
- void bindParams(DB::Command * cmd, unsigned int & o) override
- {
- cmd->bindParamB(o++, true);
- }
+public:
+ void
+ writeSql(AdHoc::Buffer & b) override
+ {
+ b.append("deleted = ?");
+ }
+ void
+ bindParams(DB::Command * cmd, unsigned int & o) override
+ {
+ cmd->bindParamB(o++, true);
+ }
};
BOOST_FIXTURE_TEST_SUITE(mock, Mock);
-BOOST_AUTO_TEST_CASE( sanityFail )
+BOOST_AUTO_TEST_CASE(sanityFail)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
BOOST_REQUIRE(db);
@@ -60,7 +61,7 @@ BOOST_AUTO_TEST_CASE( sanityFail )
BOOST_REQUIRE_THROW(db->patchTable(&tp), DB::PatchCheckFailure);
}
-BOOST_AUTO_TEST_CASE( noTx )
+BOOST_AUTO_TEST_CASE(noTx)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
BOOST_REQUIRE(db);
@@ -74,7 +75,7 @@ BOOST_AUTO_TEST_CASE( noTx )
BOOST_AUTO_TEST_SUITE_END();
-BOOST_AUTO_TEST_CASE( testBasic )
+BOOST_AUTO_TEST_CASE(testBasic)
{
Mock mock;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -98,7 +99,7 @@ BOOST_AUTO_TEST_CASE( testBasic )
BOOST_REQUIRE_EQUAL(0, r2.updates);
}
-BOOST_AUTO_TEST_CASE( allKeys )
+BOOST_AUTO_TEST_CASE(allKeys)
{
Mock mock;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -116,7 +117,7 @@ BOOST_AUTO_TEST_CASE( allKeys )
BOOST_REQUIRE_EQUAL(0, r.updates);
}
-BOOST_AUTO_TEST_CASE( testOrder )
+BOOST_AUTO_TEST_CASE(testOrder)
{
Mock mock;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -129,20 +130,21 @@ BOOST_AUTO_TEST_CASE( testOrder )
tp.pk = {"a", "b"};
tp.order = &order;
tp.beforeDelete = [](const DB::SelectCommandPtr & i) {
- i->forEachRow<int64_t, int64_t, std::string, std::string>([](auto a, auto b, auto c, auto d) {
- fprintf(stderr, "<< %ld %ld %s %s\n", a, b, c.c_str(), d.c_str());
- });
- };
+ i->forEachRow<int64_t, int64_t, std::string, std::string>([](auto a, auto b, auto c, auto d) {
+ fprintf(stderr, "<< %ld %ld %s %s\n", a, b, c.c_str(), d.c_str());
+ });
+ };
tp.beforeUpdate = [](const DB::SelectCommandPtr & i) {
- i->forEachRow<int64_t, int64_t, std::string, std::string, std::string, std::string>([](auto a, auto b, auto c1, auto d1, auto c2, auto d2) {
- fprintf(stderr, "== %ld %ld %s->%s %s->%s\n", a, b, c1.c_str(), c2.c_str(), d1.c_str(), d2.c_str());
- });
- };
+ i->forEachRow<int64_t, int64_t, std::string, std::string, std::string, std::string>(
+ [](auto a, auto b, auto c1, auto d1, auto c2, auto d2) {
+ fprintf(stderr, "== %ld %ld %s->%s %s->%s\n", a, b, c1.c_str(), c2.c_str(), d1.c_str(), d2.c_str());
+ });
+ };
tp.beforeInsert = [](const DB::SelectCommandPtr & i) {
- i->forEachRow<int64_t, int64_t, std::string, std::string>([](auto a, auto b, auto c, auto d) {
- fprintf(stderr, ">> %ld %ld %s %s\n", a, b, c.c_str(), d.c_str());
- });
- };
+ i->forEachRow<int64_t, int64_t, std::string, std::string>([](auto a, auto b, auto c, auto d) {
+ fprintf(stderr, ">> %ld %ld %s %s\n", a, b, c.c_str(), d.c_str());
+ });
+ };
db->beginTx();
auto r = db->patchTable(&tp);
db->commitTx();
@@ -151,7 +153,7 @@ BOOST_AUTO_TEST_CASE( testOrder )
BOOST_REQUIRE_EQUAL(1, r.updates);
}
-BOOST_AUTO_TEST_CASE( testWhere )
+BOOST_AUTO_TEST_CASE(testWhere)
{
Mock mock;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -171,7 +173,7 @@ BOOST_AUTO_TEST_CASE( testWhere )
BOOST_REQUIRE_EQUAL(1, r.updates);
}
-BOOST_AUTO_TEST_CASE( testInstead )
+BOOST_AUTO_TEST_CASE(testInstead)
{
Mock mock;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -191,7 +193,7 @@ BOOST_AUTO_TEST_CASE( testInstead )
BOOST_REQUIRE_EQUAL(1, r.updates);
}
-BOOST_AUTO_TEST_CASE( testSrcExprTable )
+BOOST_AUTO_TEST_CASE(testSrcExprTable)
{
Mock mock;
DB::StaticSqlWriter s("source");
@@ -210,7 +212,7 @@ BOOST_AUTO_TEST_CASE( testSrcExprTable )
BOOST_REQUIRE_EQUAL(1, r.updates);
}
-BOOST_AUTO_TEST_CASE( testSrcExprSelectTable )
+BOOST_AUTO_TEST_CASE(testSrcExprSelectTable)
{
Mock mock;
DB::StaticSqlWriter s("(SELECT * FROM source)");
@@ -230,22 +232,19 @@ BOOST_AUTO_TEST_CASE( testSrcExprSelectTable )
}
class BindInt : public DB::StaticSqlWriter {
- public:
- BindInt(const std::string & s, int i) :
- DB::StaticSqlWriter(s),
- myInt(i)
- {
- }
+public:
+ BindInt(const std::string & s, int i) : DB::StaticSqlWriter(s), myInt(i) { }
- void bindParams(DB::Command * c, unsigned int & offset) override
- {
- c->bindParamI(offset++, myInt);
- }
+ void
+ bindParams(DB::Command * c, unsigned int & offset) override
+ {
+ c->bindParamI(offset++, myInt);
+ }
- int myInt;
+ int myInt;
};
-BOOST_AUTO_TEST_CASE( testSrcExprSelectFilteredTable )
+BOOST_AUTO_TEST_CASE(testSrcExprSelectFilteredTable)
{
Mock mock;
BindInt s("(SELECT s.* FROM source s WHERE s.a = ?)", 1);
@@ -263,4 +262,3 @@ BOOST_AUTO_TEST_CASE( testSrcExprSelectFilteredTable )
BOOST_REQUIRE_EQUAL(1, r.inserts);
BOOST_REQUIRE_EQUAL(1, r.updates);
}
-
diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp
index 9ceef54..4d1adbe 100644
--- a/libdbpp/unittests/testUtils.cpp
+++ b/libdbpp/unittests/testUtils.cpp
@@ -1,29 +1,28 @@
#define BOOST_TEST_MODULE DbUtil
#include <boost/test/unit_test.hpp>
+#include <IceUtil/Exception.h>
+#include <IceUtil/Optional.h>
+#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <connection.h>
-#include <selectcommand.h>
-#include <modifycommand.h>
-#include <selectcommandUtil.impl.h>
#include <definedDirs.h>
#include <fstream>
+#include <modifycommand.h>
#include <pq-mock.h>
-#include <boost/date_time/posix_time/posix_time_io.hpp>
-#include <IceUtil/Exception.h>
-#include <IceUtil/Optional.h>
+#include <selectcommand.h>
+#include <selectcommandUtil.impl.h>
#include <testCore.h>
class StandardMockDatabase : public DB::PluginMock<PQ::Mock> {
- public:
- StandardMockDatabase() : DB::PluginMock<PQ::Mock>("pqmock", {
- rootDir / "util.sql" }, "user=postgres dbname=postgres")
- {
- }
+public:
+ StandardMockDatabase() : DB::PluginMock<PQ::Mock>("pqmock", {rootDir / "util.sql"}, "user=postgres dbname=postgres")
+ {
+ }
};
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
-BOOST_AUTO_TEST_CASE( forEachRow )
+BOOST_AUTO_TEST_CASE(forEachRow)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
auto sel = db->select("SELECT a, b, c, d, e, f FROM forEachRow ORDER BY a LIMIT 1");
@@ -32,17 +31,18 @@ BOOST_AUTO_TEST_CASE( forEachRow )
BOOST_REQUIRE_EQUAL(1, a);
BOOST_REQUIRE_CLOSE(4.3, b, 0.001);
BOOST_REQUIRE_EQUAL("Some text", c);
- BOOST_REQUIRE_EQUAL(boost::posix_time::ptime_from_tm({ 17, 39, 13, 7, 10, 115, 0, 0, 0, 0, nullptr}), d);
+ BOOST_REQUIRE_EQUAL(boost::posix_time::ptime_from_tm({17, 39, 13, 7, 10, 115, 0, 0, 0, 0, nullptr}), d);
BOOST_REQUIRE_EQUAL(boost::posix_time::time_duration(4, 3, 2), e);
BOOST_REQUIRE_EQUAL(true, f);
});
}
-BOOST_AUTO_TEST_CASE( forEachRowNulls )
+BOOST_AUTO_TEST_CASE(forEachRowNulls)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
auto sel = db->select("SELECT a, b, c, d, e, f FROM forEachRow ORDER BY a DESC LIMIT 1");
- sel->forEachRow<int64_t, std::optional<double>, std::string, std::optional<boost::posix_time::ptime>, std::optional<boost::posix_time::time_duration>, bool>(
+ sel->forEachRow<int64_t, std::optional<double>, std::string, std::optional<boost::posix_time::ptime>,
+ std::optional<boost::posix_time::time_duration>, bool>(
[](auto && a, auto b, auto c, auto d, auto && e, auto f) {
BOOST_REQUIRE_EQUAL(2, a);
BOOST_REQUIRE(b);
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE( forEachRowNulls )
});
}
-BOOST_AUTO_TEST_CASE( stdforOverRows )
+BOOST_AUTO_TEST_CASE(stdforOverRows)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
unsigned int count = 0;
@@ -75,14 +75,14 @@ BOOST_AUTO_TEST_CASE( stdforOverRows )
BOOST_REQUIRE_EQUAL(totalOfc, "Some textSome text");
}
-BOOST_AUTO_TEST_CASE( stdforOverRowsStructuredBinding )
+BOOST_AUTO_TEST_CASE(stdforOverRowsStructuredBinding)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
unsigned int count = 0;
int64_t totalOfa = 0;
std::string totalOfc;
auto sel = db->select("SELECT a, c FROM forEachRow ORDER BY a DESC");
- for (const auto [ a, c ] : sel->as<int64_t, std::string_view>()) {
+ for (const auto [a, c] : sel->as<int64_t, std::string_view>()) {
count += 1;
totalOfa += a;
totalOfc += c;
@@ -92,14 +92,14 @@ BOOST_AUTO_TEST_CASE( stdforOverRowsStructuredBinding )
BOOST_REQUIRE_EQUAL(totalOfc, "Some textSome text");
}
-BOOST_AUTO_TEST_CASE( stdforOverRowsStructuredBindingOptional )
+BOOST_AUTO_TEST_CASE(stdforOverRowsStructuredBindingOptional)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
unsigned int count = 0;
int64_t totalOfa = 0;
std::string totalOfc;
auto sel = db->select("SELECT a, c FROM forEachRow ORDER BY a DESC");
- for (const auto [ a, c ] : sel->as<std::optional<int64_t>, std::optional<std::string>>()) {
+ for (const auto [a, c] : sel->as<std::optional<int64_t>, std::optional<std::string>>()) {
count += 1;
BOOST_REQUIRE(a);
totalOfa += *a;
@@ -111,13 +111,13 @@ BOOST_AUTO_TEST_CASE( stdforOverRowsStructuredBindingOptional )
BOOST_REQUIRE_EQUAL(totalOfc, "Some textSome text");
}
-BOOST_AUTO_TEST_CASE( execute )
+BOOST_AUTO_TEST_CASE(execute)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
db->execute("UPDATE forEachRow SET a = 2");
}
-BOOST_AUTO_TEST_CASE( columns )
+BOOST_AUTO_TEST_CASE(columns)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
auto sel = db->select("SELECT a, b, c, d, e FROM forEachRow ORDER BY a LIMIT 1");
@@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE( columns )
BOOST_REQUIRE_THROW((void)(*sel)[""], DB::ColumnDoesNotExist);
}
-BOOST_AUTO_TEST_CASE( extract )
+BOOST_AUTO_TEST_CASE(extract)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
auto sel = db->select("SELECT a, b, c FROM forEachRow WHERE f");
@@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE( extract )
BOOST_REQUIRE(!sel->fetch());
}
-BOOST_AUTO_TEST_CASE( bulkLoadStream )
+BOOST_AUTO_TEST_CASE(bulkLoadStream)
{
std::ifstream in(rootDir / "source.dat");
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -172,11 +172,11 @@ BOOST_AUTO_TEST_CASE( bulkLoadStream )
BOOST_REQUIRE_EQUAL(56, db->bulkUploadData(in));
db->endBulkUpload(nullptr);
db->select("SELECT COUNT(*) FROM bulk1")->forEachRow<int64_t>([](auto n) {
- BOOST_REQUIRE_EQUAL(4, n);
- });
+ BOOST_REQUIRE_EQUAL(4, n);
+ });
}
-BOOST_AUTO_TEST_CASE( bulkLoadFile )
+BOOST_AUTO_TEST_CASE(bulkLoadFile)
{
auto f = fopen((rootDir / "source.dat").c_str(), "r");
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -185,12 +185,12 @@ BOOST_AUTO_TEST_CASE( bulkLoadFile )
db->endBulkUpload(nullptr);
fclose(f);
db->select("SELECT COUNT(*) FROM bulk2")->forEachRow<int64_t>([](auto n) {
- BOOST_REQUIRE_EQUAL(4, n);
- });
+ BOOST_REQUIRE_EQUAL(4, n);
+ });
}
using StringTypes = boost::mpl::list<std::string, std::string_view, Glib::ustring>;
-BOOST_AUTO_TEST_CASE_TEMPLATE( nullBind, Str, StringTypes )
+BOOST_AUTO_TEST_CASE_TEMPLATE(nullBind, Str, StringTypes)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
db->execute("DELETE FROM forEachRow");
@@ -202,7 +202,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( nullBind, Str, StringTypes )
ins->bindParamT(4, std::optional<boost::posix_time::time_duration>());
ins->bindParamB(5, std::optional<bool>());
ins->execute();
- auto sel = db->select("SELECT a, b, c, d, e, f FROM forEachRow WHERE a IS NULL AND b IS NULL AND c IS NULL AND d IS NULL AND e IS NULL AND f IS NULL");
+ auto sel = db->select("SELECT a, b, c, d, e, f FROM forEachRow WHERE a IS NULL AND b IS NULL AND c IS NULL AND d "
+ "IS NULL AND e IS NULL AND f IS NULL");
unsigned int count = 0;
for (const auto & row : sel->as<int, std::optional<double>, Str>()) {
count += 1;
@@ -214,7 +215,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( nullBind, Str, StringTypes )
BOOST_REQUIRE_EQUAL(1, count);
}
-BOOST_AUTO_TEST_CASE( iceNullBind )
+BOOST_AUTO_TEST_CASE(iceNullBind)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
auto ins = db->modify("INSERT INTO forEachRow VALUES(?, ?, ?, ?, ?, ?)");
@@ -225,7 +226,8 @@ BOOST_AUTO_TEST_CASE( iceNullBind )
ins->bindParamT(4, IceUtil::Optional<boost::posix_time::time_duration>());
ins->bindParamB(5, IceUtil::Optional<bool>());
ins->execute();
- auto sel = db->select("SELECT a, b, c, d, e, f FROM forEachRow WHERE a IS NULL AND b IS NULL AND c IS NULL AND d IS NULL AND e IS NULL AND f IS NULL");
+ auto sel = db->select("SELECT a, b, c, d, e, f FROM forEachRow WHERE a IS NULL AND b IS NULL AND c IS NULL AND d "
+ "IS NULL AND e IS NULL AND f IS NULL");
unsigned int count = 0;
for (const auto & row : sel->as<>()) {
(void)row;
@@ -234,7 +236,7 @@ BOOST_AUTO_TEST_CASE( iceNullBind )
BOOST_REQUIRE_EQUAL(2, count);
}
-BOOST_AUTO_TEST_CASE( charStarBindNull )
+BOOST_AUTO_TEST_CASE(charStarBindNull)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
db->modify("DELETE FROM forEachRow")->execute();
@@ -261,7 +263,7 @@ BOOST_AUTO_TEST_CASE( charStarBindNull )
}
}
-BOOST_AUTO_TEST_CASE( bind )
+BOOST_AUTO_TEST_CASE(bind)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
auto m = db->modify("doesn't matter, only testing compile");
@@ -270,7 +272,7 @@ BOOST_AUTO_TEST_CASE( bind )
m->bindParamI(0, (time_t)1);
}
-BOOST_AUTO_TEST_CASE( bindIntPtr )
+BOOST_AUTO_TEST_CASE(bindIntPtr)
{
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
db->modify("DELETE FROM forEachRow")->execute();
@@ -301,7 +303,7 @@ BOOST_AUTO_TEST_CASE( bindIntPtr )
BOOST_REQUIRE_EQUAL(159, total);
}
-BOOST_FIXTURE_TEST_CASE( traits_bind, DB::TestCore )
+BOOST_FIXTURE_TEST_CASE(traits_bind, DB::TestCore)
{
using namespace std::literals;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
@@ -356,14 +358,14 @@ BOOST_FIXTURE_TEST_CASE( traits_bind, DB::TestCore )
check(__LINE__, std::optional<DB::Blob>(testBlob), false, testBlob, cmd2);
}
-BOOST_AUTO_TEST_CASE( testBlobRaw )
+BOOST_AUTO_TEST_CASE(testBlobRaw)
{
DB::Blob ptr(this, 1);
BOOST_REQUIRE_EQUAL(ptr.data, this);
BOOST_REQUIRE_EQUAL(ptr.len, 1);
}
-BOOST_AUTO_TEST_CASE( testBlobObject )
+BOOST_AUTO_TEST_CASE(testBlobObject)
{
int32_t x = 20;
DB::Blob obj(&x);
@@ -371,7 +373,7 @@ BOOST_AUTO_TEST_CASE( testBlobObject )
BOOST_REQUIRE_EQUAL(obj.len, 4);
}
-BOOST_AUTO_TEST_CASE( testBlobVec )
+BOOST_AUTO_TEST_CASE(testBlobVec)
{
std::vector<uint8_t> buf(20, 0);
DB::Blob vec(buf);
@@ -385,15 +387,15 @@ struct S {
};
BOOST_STATIC_ASSERT(sizeof(S) == 16);
-BOOST_AUTO_TEST_CASE( testBlobStruct )
+BOOST_AUTO_TEST_CASE(testBlobStruct)
{
- S s = { 8, 4 };
+ S s = {8, 4};
DB::Blob str(&s);
BOOST_REQUIRE_EQUAL(str.data, &s);
BOOST_REQUIRE_EQUAL(str.len, 16);
}
-BOOST_AUTO_TEST_CASE( testBlobVecStruct )
+BOOST_AUTO_TEST_CASE(testBlobVecStruct)
{
std::vector<S> buf(20, {4, 8});
DB::Blob vec(buf);
@@ -401,7 +403,7 @@ BOOST_AUTO_TEST_CASE( testBlobVecStruct )
BOOST_REQUIRE_EQUAL(vec.len, 20 * 16);
}
-BOOST_AUTO_TEST_CASE( testBlobCompare )
+BOOST_AUTO_TEST_CASE(testBlobCompare)
{
std::vector<S> buf1(20, {4, 8});
DB::Blob vec1(buf1);
@@ -422,17 +424,21 @@ BOOST_AUTO_TEST_CASE( testBlobCompare )
// These just compile time support, actual data extraction should be tested by the implementing connector.
template<typename T>
auto
-testExtractT(DB::Row<T> row) {
+testExtractT(DB::Row<T> row)
+{
return row.template value<0>();
}
template<typename T>
void
-testExtractT(const DB::SelectCommandPtr & sel) {
+testExtractT(const DB::SelectCommandPtr & sel)
+{
// test default construct
T test;
(void)test;
- for (const auto & row : sel->as<T>()) { testExtractT(row); }
+ for (const auto & row : sel->as<T>()) {
+ testExtractT(row);
+ }
#ifdef __clang__
// Clang cannot compile this for reasons largely todo with ambiguousness in the spec
// Fixed when we move to std::chrono
@@ -440,11 +446,13 @@ testExtractT(const DB::SelectCommandPtr & sel) {
#else
if constexpr (true) {
#endif
- for (const auto & row : sel->as<std::optional<T>>()) { testExtractT(row); }
+ for (const auto & row : sel->as<std::optional<T>>()) {
+ testExtractT(row);
+ }
}
}
-BOOST_AUTO_TEST_CASE( testExtractTypes )
+BOOST_AUTO_TEST_CASE(testExtractTypes)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
auto sel = db->select("SELECT 1 FROM forEachRow LIMIT 0");
@@ -462,4 +470,3 @@ BOOST_AUTO_TEST_CASE( testExtractTypes )
testExtractT<boost::posix_time::time_duration>(sel);
testExtractT<DB::Blob>(sel);
}
-