summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-11-08 02:26:19 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-11-08 02:26:19 +0000
commitd2747d7d3ccacd6f9f0923c4b67a29927489661f (patch)
treee61b68db3399a932c0db3b6ad3c549b0a2675afa
parentRemove unneeded includes (diff)
downloadlibdbpp-d2747d7d3ccacd6f9f0923c4b67a29927489661f.tar.bz2
libdbpp-d2747d7d3ccacd6f9f0923c4b67a29927489661f.tar.xz
libdbpp-d2747d7d3ccacd6f9f0923c4b67a29927489661f.zip
Test error handling in mock setup
-rw-r--r--libdbpp/mockDatabase.cpp2
-rw-r--r--libdbpp/unittests/Jamfile.jam14
-rw-r--r--libdbpp/unittests/badMock.sql1
-rw-r--r--libdbpp/unittests/testMock.cpp22
4 files changed, 38 insertions, 1 deletions
diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp
index a0ae7e5..9cb916f 100644
--- a/libdbpp/mockDatabase.cpp
+++ b/libdbpp/mockDatabase.cpp
@@ -67,7 +67,7 @@ MockDatabase::PlaySchemaScript(DB::Connection * conn, const boost::filesystem::p
std::ifstream f;
f.open(s.string());
if (!f.good()) {
- throw std::runtime_error("Failed to open mock script: " + s.string());
+ throw std::fstream::failure("Failed to open mock script: " + s.string());
}
conn->executeScript(f, s.parent_path());
f.close();
diff --git a/libdbpp/unittests/Jamfile.jam b/libdbpp/unittests/Jamfile.jam
index ad90ec6..cee679f 100644
--- a/libdbpp/unittests/Jamfile.jam
+++ b/libdbpp/unittests/Jamfile.jam
@@ -31,3 +31,17 @@ run
testUtils
;
+run
+ testMock.cpp
+ : : :
+ <define>ROOT=\"$(me)\"
+ <define>BOOST_TEST_DYN_LINK
+ <library>..//dbppcore
+ <library>..//adhocutil
+ <library>../../libpqpp//dbpp-postgresql
+ <library>boost_utf
+ <dependency>badMock.sql
+ :
+ testMock
+ ;
+
diff --git a/libdbpp/unittests/badMock.sql b/libdbpp/unittests/badMock.sql
new file mode 100644
index 0000000..e1405cc
--- /dev/null
+++ b/libdbpp/unittests/badMock.sql
@@ -0,0 +1 @@
+Not good Sql ;-)
diff --git a/libdbpp/unittests/testMock.cpp b/libdbpp/unittests/testMock.cpp
new file mode 100644
index 0000000..4340886
--- /dev/null
+++ b/libdbpp/unittests/testMock.cpp
@@ -0,0 +1,22 @@
+#define BOOST_TEST_MODULE DbMock
+#include <boost/test/unit_test.hpp>
+
+#include <definedDirs.h>
+#include <fstream>
+#include <mock.h>
+#include "error.h"
+
+BOOST_AUTO_TEST_CASE( missingMock )
+{
+ BOOST_REQUIRE_THROW({
+ PQ::Mock m ("user=postgres dbname=postgres", "pqmock", { rootDir / "missing.sql" });
+ }, std::fstream::failure);
+}
+
+BOOST_AUTO_TEST_CASE( failingMock )
+{
+ BOOST_REQUIRE_THROW({
+ PQ::Mock m ("user=postgres dbname=postgres", "pqmock", { rootDir / "badMock.sql" });
+ }, DB::Error);
+}
+