diff options
-rw-r--r-- | libdbpp/mockDatabase.cpp | 2 | ||||
-rw-r--r-- | libdbpp/unittests/Jamfile.jam | 14 | ||||
-rw-r--r-- | libdbpp/unittests/badMock.sql | 1 | ||||
-rw-r--r-- | libdbpp/unittests/testMock.cpp | 22 |
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); +} + |