diff --git a/src/Transaction.cpp b/src/Transaction.cpp index eec5103..388cabb 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -52,7 +52,7 @@ void Transaction::commit() } else { - throw SQLite::Exception("Transaction already commited."); + throw SQLite::Exception("Transaction already committed."); } } diff --git a/tests/Exception_test.cpp b/tests/Exception_test.cpp index e1a6df5..14e3a18 100644 --- a/tests/Exception_test.cpp +++ b/tests/Exception_test.cpp @@ -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"); } }