]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4032] Added a message matching example
authorFrancis Dupont <fdupont@isc.org>
Mon, 7 Sep 2015 17:20:01 +0000 (19:20 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 7 Sep 2015 17:20:01 +0000 (19:20 +0200)
src/lib/exceptions/tests/exceptions_unittest.cc

index 4e93ce89550babb35a54667725e3644fdd327ad8..0f03d1d989a21218c0c0ac4adf66e8f15f091ad9 100644 (file)
@@ -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,21 @@ TEST_F(ExceptionTest, verbose) {
     }
 
 }
+
+// Test matching message.
+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.";
+    }
+}
+
 }