From b7b07d16c144a1c1e699091d0913d3568c6d8b46 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Nov 2015 14:33:50 +0000 Subject: Add tests over parser error handling and more complex cases --- libdbpp/unittests/Jamfile.jam | 6 +++++ libdbpp/unittests/dollarQuote.sql | 1 + libdbpp/unittests/scriptDir.sql | 1 + libdbpp/unittests/stringParse.sql | 1 + libdbpp/unittests/testConnection.cpp | 37 +++++++++++++++++++++++++++ libdbpp/unittests/unterminatedComment.sql | 4 +++ libdbpp/unittests/unterminatedDollarQuote.sql | 1 + libdbpp/unittests/unterminatedString.sql | 1 + 8 files changed, 52 insertions(+) create mode 100644 libdbpp/unittests/dollarQuote.sql create mode 100644 libdbpp/unittests/scriptDir.sql create mode 100644 libdbpp/unittests/stringParse.sql create mode 100644 libdbpp/unittests/unterminatedComment.sql create mode 100644 libdbpp/unittests/unterminatedDollarQuote.sql create mode 100644 libdbpp/unittests/unterminatedString.sql diff --git a/libdbpp/unittests/Jamfile.jam b/libdbpp/unittests/Jamfile.jam index cee679f..b7b2170 100644 --- a/libdbpp/unittests/Jamfile.jam +++ b/libdbpp/unittests/Jamfile.jam @@ -13,6 +13,12 @@ run ..//adhocutil boost_utf parseTest.sql + unterminatedComment.sql + unterminatedString.sql + unterminatedDollarQuote.sql + dollarQuote.sql + scriptDir.sql + stringParse.sql : testConnection ; diff --git a/libdbpp/unittests/dollarQuote.sql b/libdbpp/unittests/dollarQuote.sql new file mode 100644 index 0000000..5b52274 --- /dev/null +++ b/libdbpp/unittests/dollarQuote.sql @@ -0,0 +1 @@ +CREATE TABLE $a$dollarQuotes$a$( a text ); diff --git a/libdbpp/unittests/scriptDir.sql b/libdbpp/unittests/scriptDir.sql new file mode 100644 index 0000000..4d3e461 --- /dev/null +++ b/libdbpp/unittests/scriptDir.sql @@ -0,0 +1 @@ +INSERT INTO dollarQuotes(a) VALUES('$SCRIPTDIR'); diff --git a/libdbpp/unittests/stringParse.sql b/libdbpp/unittests/stringParse.sql new file mode 100644 index 0000000..e764da9 --- /dev/null +++ b/libdbpp/unittests/stringParse.sql @@ -0,0 +1 @@ +INSERT INTO dollarQuotes(a) VALUES('apos''trophe'); diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index 6d9cd05..ed727de 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -78,6 +78,43 @@ BOOST_AUTO_TEST_CASE( parse ) delete mock; } +BOOST_AUTO_TEST_CASE( parse2 ) +{ + auto mock = DB::ConnectionPtr(DB::ConnectionFactory::createNew("MockDb", "doesn't matter")); + std::fstream s; + + s.open((rootDir / "dollarQuote.sql").string()); + mock->executeScript(s, rootDir); + s.close(); + + s.open((rootDir / "scriptDir.sql").string()); + mock->executeScript(s, rootDir); + s.close(); + + s.open((rootDir / "stringParse.sql").string()); + mock->executeScript(s, rootDir); + s.close(); + + BOOST_REQUIRE_THROW({ + s.open((rootDir / "unterminatedComment.sql").string()); + mock->executeScript(s, rootDir); + }, std::runtime_error); + s.close(); + + BOOST_REQUIRE_THROW({ + s.open((rootDir / "unterminatedDollarQuote.sql").string()); + mock->executeScript(s, rootDir); + }, std::runtime_error); + s.close(); + + BOOST_REQUIRE_THROW({ + s.open((rootDir / "unterminatedString.sql").string()); + mock->executeScript(s, rootDir); + }, std::runtime_error); + s.close(); +} + + BOOST_AUTO_TEST_CASE( savepoints ) { auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter"); diff --git a/libdbpp/unittests/unterminatedComment.sql b/libdbpp/unittests/unterminatedComment.sql new file mode 100644 index 0000000..299e639 --- /dev/null +++ b/libdbpp/unittests/unterminatedComment.sql @@ -0,0 +1,4 @@ +/* + * I + * don't + * end diff --git a/libdbpp/unittests/unterminatedDollarQuote.sql b/libdbpp/unittests/unterminatedDollarQuote.sql new file mode 100644 index 0000000..06fe430 --- /dev/null +++ b/libdbpp/unittests/unterminatedDollarQuote.sql @@ -0,0 +1 @@ +CREATE TABLE $a$dollarQuote diff --git a/libdbpp/unittests/unterminatedString.sql b/libdbpp/unittests/unterminatedString.sql new file mode 100644 index 0000000..cdd4b49 --- /dev/null +++ b/libdbpp/unittests/unterminatedString.sql @@ -0,0 +1 @@ +INSERT INTO dollarQuotes(a) VALUES('i don''t end -- cgit v1.2.3