Skip to content

Commit c80ccba

Browse files
committed
Improve and complete unit tests of Exception
1 parent ae01dfb commit c80ccba

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/Transaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void Transaction::commit()
5252
}
5353
else
5454
{
55-
throw SQLite::Exception("Transaction already commited.");
55+
throw SQLite::Exception("Transaction already committed.");
5656
}
5757
}
5858

tests/Exception_test.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ TEST(Exception, copy)
2828
// an assignment operator is expected to be avaiable
2929
TEST(Exception, assignment)
3030
{
31-
const SQLite::Exception ex1("some error", 2);
32-
SQLite::Exception ex2("some error2", 3);
31+
const char message[] = "some error";
32+
const SQLite::Exception ex1(message, 1);
33+
SQLite::Exception ex2("another error", 2);
3334

3435
ex2 = ex1;
3536

36-
EXPECT_STREQ(ex1.what(), ex2.what());
37-
EXPECT_EQ(ex1.getErrorCode(), ex2.getErrorCode());
38-
EXPECT_EQ(ex1.getExtendedErrorCode(), ex2.getExtendedErrorCode());
37+
EXPECT_STREQ(ex2.what(), message);
38+
EXPECT_EQ(ex2.getErrorCode(), 1);
39+
EXPECT_EQ(ex2.getExtendedErrorCode(), -1);
40+
EXPECT_STREQ(ex2.getErrorStr(), "SQL logic error");
3941
}
4042

4143
TEST(Exception, throw_catch)
@@ -58,16 +60,16 @@ TEST(Exception, constructor)
5860
std::string msg2 = msg1;
5961
{
6062
const SQLite::Exception ex1(msg1);
61-
const SQLite::Exception ex2(msg2);
62-
EXPECT_STREQ(ex1.what(), ex2.what());
63-
EXPECT_EQ(ex1.getErrorCode(), ex2.getErrorCode());
64-
EXPECT_EQ(ex1.getExtendedErrorCode(), ex2.getExtendedErrorCode());
63+
EXPECT_STREQ(ex1.what(), msg1);
64+
EXPECT_EQ(ex1.getErrorCode(), -1);
65+
EXPECT_EQ(ex1.getExtendedErrorCode(), -1);
66+
EXPECT_STREQ("unknown error", ex1.getErrorStr());
6567
}
6668
{
6769
const SQLite::Exception ex1(msg1, 1);
68-
const SQLite::Exception ex2(msg2, 1);
69-
EXPECT_STREQ(ex1.what(), ex2.what());
70-
EXPECT_EQ(ex1.getErrorCode(), ex2.getErrorCode());
71-
EXPECT_EQ(ex1.getExtendedErrorCode(), ex2.getExtendedErrorCode());
70+
EXPECT_STREQ(ex1.what(), msg1);
71+
EXPECT_EQ(ex1.getErrorCode(), 1);
72+
EXPECT_EQ(ex1.getExtendedErrorCode(), -1);
73+
EXPECT_STREQ(ex1.getErrorStr(), "SQL logic error");
7274
}
7375
}

0 commit comments

Comments
 (0)