Improve and complete unit tests of Exception

This commit is contained in:
Sébastien Rombauts 2019-12-29 22:39:47 +01:00
parent ae01dfb895
commit f9cd39b278
2 changed files with 34 additions and 18 deletions

View File

@ -52,7 +52,7 @@ void Transaction::commit()
}
else
{
throw SQLite::Exception("Transaction already commited.");
throw SQLite::Exception("Transaction already committed.");
}
}

View File

@ -28,14 +28,16 @@ TEST(Exception, copy)
// an assignment operator is expected to be avaiable
TEST(Exception, assignment)
{
const SQLite::Exception ex1("some error", 2);
SQLite::Exception ex2("some error2", 3);
const char message[] = "some error";
const SQLite::Exception ex1(message, 1);
SQLite::Exception ex2("another error", 2);
ex2 = ex1;
EXPECT_STREQ(ex1.what(), ex2.what());
EXPECT_EQ(ex1.getErrorCode(), ex2.getErrorCode());
EXPECT_EQ(ex1.getExtendedErrorCode(), ex2.getExtendedErrorCode());
EXPECT_STREQ(ex2.what(), message);
EXPECT_EQ(ex2.getErrorCode(), 1);
EXPECT_EQ(ex2.getExtendedErrorCode(), -1);
EXPECT_STREQ(ex2.getErrorStr(), "SQL logic error");
}
TEST(Exception, throw_catch)
@ -54,20 +56,34 @@ TEST(Exception, throw_catch)
TEST(Exception, constructor)
{
const char msg1[] = "error msg";
std::string msg2 = msg1;
const char msg1[] = "some error";
std::string msg2 = "another error";
{
const SQLite::Exception ex1(msg1);
const SQLite::Exception ex2(msg2);
EXPECT_STREQ(ex1.what(), ex2.what());
EXPECT_EQ(ex1.getErrorCode(), ex2.getErrorCode());
EXPECT_EQ(ex1.getExtendedErrorCode(), ex2.getExtendedErrorCode());
const SQLite::Exception ex(msg1);
EXPECT_STREQ(ex.what(), msg1);
EXPECT_EQ(ex.getErrorCode(), -1);
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
EXPECT_STREQ("unknown error", ex.getErrorStr());
}
{
const SQLite::Exception ex1(msg1, 1);
const SQLite::Exception ex2(msg2, 1);
EXPECT_STREQ(ex1.what(), ex2.what());
EXPECT_EQ(ex1.getErrorCode(), ex2.getErrorCode());
EXPECT_EQ(ex1.getExtendedErrorCode(), ex2.getExtendedErrorCode());
const SQLite::Exception ex(msg2);
EXPECT_STREQ(ex.what(), msg2.c_str());
EXPECT_EQ(ex.getErrorCode(), -1);
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
EXPECT_STREQ("unknown error", ex.getErrorStr());
}
{
const SQLite::Exception ex(msg1, 1);
EXPECT_STREQ(ex.what(), msg1);
EXPECT_EQ(ex.getErrorCode(), 1);
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
EXPECT_STREQ(ex.getErrorStr(), "SQL logic error");
}
{
const SQLite::Exception ex(msg2, 2);
EXPECT_STREQ(ex.what(), msg2.c_str());
EXPECT_EQ(ex.getErrorCode(), 2);
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
EXPECT_STREQ(ex.getErrorStr(), "unknown error");
}
}