summaryrefslogtreecommitdiffstats
path: root/src/lib/exceptions
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2015-09-23 13:22:48 +0200
committerFrancis Dupont <fdupont@isc.org>2015-09-23 13:22:48 +0200
commitc1df754fbd6a2f264911c2eef6ba60b48ab56896 (patch)
treea2b92c939b06c5eb6d428a3e884e339c19c9adb9 /src/lib/exceptions
parent[master] ChangeLog updated after #3982 merge. (diff)
parent[4032] Improved message unit test comment (diff)
downloadkea-c1df754fbd6a2f264911c2eef6ba60b48ab56896.tar.xz
kea-c1df754fbd6a2f264911c2eef6ba60b48ab56896.zip
[master] Merged trac4032 (improve unit tests for exceptions)
Diffstat (limited to 'src/lib/exceptions')
-rw-r--r--src/lib/exceptions/tests/exceptions_unittest.cc24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/exceptions/tests/exceptions_unittest.cc b/src/lib/exceptions/tests/exceptions_unittest.cc
index 4e93ce8955..977d393ae3 100644
--- a/src/lib/exceptions/tests/exceptions_unittest.cc
+++ b/src/lib/exceptions/tests/exceptions_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -30,6 +30,10 @@ protected:
const char* teststring;
};
+void raise_foobar() {
+ isc_throw(isc::BadValue, "foobar");
+}
+
TEST_F(ExceptionTest, basicMethods) {
try {
isc_throw(Exception, teststring);
@@ -68,4 +72,22 @@ TEST_F(ExceptionTest, verbose) {
}
}
+
+// A full example of how to check both the exception (e.g., EXPECT_THROW)
+// and its associated message (something no gtest macros do).
+TEST_F(ExceptionTest, message) {
+ try {
+ raise_foobar();
+ ADD_FAILURE() << "Expected " "raise_foobar()" \
+ " throws an exception of type " "BadValue" \
+ ".\n Actual: it throws nothing.";
+ } catch (const isc::BadValue& ex) {
+ EXPECT_EQ(std::string(ex.getMessage()), "foobar");
+ } catch (...) {
+ ADD_FAILURE() << "Expected " "raise_foobar()" \
+ " throws an exception of type " "BadValue" \
+ ".\n Actual: it throws a different type.";
+ }
+}
+
}