Commit 69ba9294 authored by Dr. Carsten Kemena's avatar Dr. Carsten Kemena
Browse files

improved SQLiteDB tests

parent a89681df
Pipeline #104959 passed with stages
in 1 minute and 10 seconds
......@@ -10,7 +10,7 @@ Requirements
------------
We try to keep the dependencies as little as possible. Current dependencies are:
- cmake (https://cmake.org)
- cmake 3.14 or greater (https://cmake.org)
- compiler supporting c++17
- boost modules (at least 1.59): system filesystem iostreams (http://www.boost.org/)
......@@ -20,6 +20,7 @@ Optional:
In most Linux distributions (e.g. Ubuntu, Arch Linux) it should be possible to install these dependencies using the package manager.
Installation
------------
......
......@@ -117,12 +117,12 @@ class SeqSetIOManager
if (inputStrategies_[i]->checkFormat(inF))
{
inputStrategies_[i]->read(seqSet, inF, extractNames, remove);
assert(seqSet.size() > 0);
return seqSet;
}
}
inF.close();
throw FormatException("Error: Format of file '" + fileName.string() + "' could not be identified or is not supported.\n");
assert(seqSet.size() > 0);
}
/**
......
......@@ -36,7 +36,7 @@ SQLiteDB::open(const fs::path &dbFile, int flags)
std::string errorMessage = sqlite3_errmsg(db_);
sqlite3_close(db_);
db_ = nullptr;
throw std::runtime_error("SQLite error: Can't open database: " + errorMessage + "\n");
throw std::runtime_error("SQLite error: " + errorMessage + ": " + dbFile.string());
}
}
......
......@@ -34,23 +34,43 @@
BOOST_AUTO_TEST_SUITE(SQLiteDB_Test)
BOOST_AUTO_TEST_CASE( DB_CREATE_Test)
bool correctMessage1(const std::runtime_error& ex)
{
BioSeqDataLib::SQLiteDB db;
db.open("test.db");
BOOST_CHECK_EQUAL(ex.what(), std::string("SQLite error: unable to open database file: /doesnotexist/test.db"));
return true;
}
db.createTable("COMPANY", "ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL");
bool correctMessage2(const std::runtime_error& ex)
{
BOOST_CHECK_EQUAL(ex.what(), std::string("SQLite error: no such table: X"));
return true;
}
BOOST_AUTO_TEST_CASE( DB_CREATE_ERROR_Test)
{
BOOST_CHECK_EXCEPTION( BioSeqDataLib::SQLiteDB db("/doesnotexist/test.db"), std::runtime_error, correctMessage1);
}
BOOST_AUTO_TEST_CASE( DB_CREATE_Test)
{
BioSeqDataLib::SQLiteDB db("test.db");
db.createTable("COMPANY", "ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL");
db.insert("COMPANY", "ID,NAME,AGE,ADDRESS,SALARY", {"1, 'Paul', 32, 'California', 20000.00", "2, 'Allen', 25, 'Texas', 15000.00",
"3, 'Teddy', 23, 'Norway', 20000.00","4, 'Mark', 25, 'Rich-Mond ', 65000.00"} );
std::string name;
auto getName = std::bind([](sqlite3_stmt *stmt, std::string &name){name=std::string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));}, std::placeholders::_1, std::ref(name));
db.exec("Select NAME from COMPANY where ID=3", getName);
//db.select("COMPANY", "*");
BOOST_CHECK_EXCEPTION(db.exec("Select NAME from X where ID=10", getName) , std::runtime_error, correctMessage2);
std::remove("test.db");
}
BOOST_AUTO_TEST_SUITE_END()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment