Skip to content

Commit f9cd39b

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

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/Transaction.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 33 additions & 17 deletions
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)
@@ -54,20 +56,34 @@ TEST(Exception, throw_catch)
5456

5557
TEST(Exception, constructor)
5658
{
57-
const char msg1[] = "error msg";
58-
std::string msg2 = msg1;
59+
const char msg1[] = "some error";
60+
std::string msg2 = "another error";
61+
{
62+
const SQLite::Exception ex(msg1);
63+
EXPECT_STREQ(ex.what(), msg1);
64+
EXPECT_EQ(ex.getErrorCode(), -1);
65+
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
66+
EXPECT_STREQ("unknown error", ex.getErrorStr());
67+
}
68+
{
69+
const SQLite::Exception ex(msg2);
70+
EXPECT_STREQ(ex.what(), msg2.c_str());
71+
EXPECT_EQ(ex.getErrorCode(), -1);
72+
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
73+
EXPECT_STREQ("unknown error", ex.getErrorStr());
74+
}
5975
{
60-
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());
76+
const SQLite::Exception ex(msg1, 1);
77+
EXPECT_STREQ(ex.what(), msg1);
78+
EXPECT_EQ(ex.getErrorCode(), 1);
79+
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
80+
EXPECT_STREQ(ex.getErrorStr(), "SQL logic error");
6581
}
6682
{
67-
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());
83+
const SQLite::Exception ex(msg2, 2);
84+
EXPECT_STREQ(ex.what(), msg2.c_str());
85+
EXPECT_EQ(ex.getErrorCode(), 2);
86+
EXPECT_EQ(ex.getExtendedErrorCode(), -1);
87+
EXPECT_STREQ(ex.getErrorStr(), "unknown error");
7288
}
7389
}

0 commit comments

Comments
 (0)