Fix critical bug in exceptions handling 39/45539/6
authorOskar Świtalski <o.switalski@samsung.com>
Fri, 7 Aug 2015 08:06:35 +0000 (10:06 +0200)
committerAleksander Zdyb <a.zdyb@samsung.com>
Tue, 1 Sep 2015 06:25:55 +0000 (23:25 -0700)
Exception classes must publicly inherit from std::exception,
to be catched by std::exception catch.

Change-Id: I406cce76c652f112f4acff79264c0a49496b767e

src/Utils/WithMessageException.h
tests/CMakeLists.txt
tests/Utils/with_message_exception.cpp [new file with mode: 0644]

index 1f05e4b..0d9a9b2 100644 (file)
@@ -27,7 +27,7 @@
 
 namespace Utils {
 
-class WithMessageException : std::exception {
+class WithMessageException : public std::exception {
 public:
     WithMessageException(const std::string &message) : m_message(message) {}
     virtual ~WithMessageException() = default;
index 45d6b6c..2da5db9 100644 (file)
@@ -46,6 +46,7 @@ SET(SOURCE_FILES
     Audit/syscall_rule_data.cpp
     Lad/audit_event_handler.cpp
     SecurityManager/data_provider.cpp
+    Utils/with_message_exception.cpp
 
     ${LAD_SRC_DIR}/Audit/Auditctl.cpp
     ${LAD_SRC_DIR}/Audit/Parser.cpp
diff --git a/tests/Utils/with_message_exception.cpp b/tests/Utils/with_message_exception.cpp
new file mode 100644 (file)
index 0000000..bc93331
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        tests/Utils/with_message_exception.cpp
+ * @author      Oskar Świtalski <o.switalski@samsung.com>
+ * @version     1.0
+ */
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <Utils/WithMessageException.h>
+
+/**
+ * @brief   WithMessageException should publicly inherit from std::exception
+ *
+ * Exception class must publicly inherit from another class, if child class is ought to be catched
+ * by parent class catch block.
+ *
+ * @test    Scenario:
+ * - throw WithMessageException
+ * - check if std::exception could be catched
+ */
+TEST(WithMessageException, inherit_publicly_from_std_exception) {
+    EXPECT_THROW(throw Utils::WithMessageException(""), std::exception);
+}