mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Improve and complete unit tests of Exception
This commit is contained in:
parent
ae01dfb895
commit
f9cd39b278
@ -52,7 +52,7 @@ void Transaction::commit()
|
||||
}
|
||||
else
|
||||
{
|
||||
throw SQLite::Exception("Transaction already commited.");
|
||||
throw SQLite::Exception("Transaction already committed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user