Add inner tests for deferred macros 08/35608/7
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Tue, 3 Feb 2015 18:21:11 +0000 (19:21 +0100)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 20 Mar 2015 10:58:25 +0000 (11:58 +0100)
Added 11 test cases cover all possible nestings
of deferred macros.

Change-Id: I35898876f7b2dca740836463a5744fe96972f609

tests/CMakeLists.txt
tests/framework/test_cases_deferred.cpp [new file with mode: 0644]

index 045b578..b1b4d87 100644 (file)
@@ -27,6 +27,7 @@ PKG_CHECK_MODULES(INNER_TARGET_DEP
 SET(INNER_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/inner-test.cpp
     ${PROJECT_SOURCE_DIR}/tests/common/test_cases_timeout.cpp
+    ${PROJECT_SOURCE_DIR}/tests/framework/test_cases_deferred.cpp
     )
 
 #header directories
diff --git a/tests/framework/test_cases_deferred.cpp b/tests/framework/test_cases_deferred.cpp
new file mode 100644 (file)
index 0000000..036bc0f
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * 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        test_cases_deferred.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Inner tests for defer macros mechanism
+ */
+
+#include <dpl/test/test_exception.h>
+#include <dpl/test/test_runner.h>
+
+#define EXPECT_EXCEPTION(expectedCatch, F) {                           \
+    bool catched = false;                                              \
+    try {                                                              \
+        F;                                                             \
+    } catch (const DPL::Test::TestException & ex) {                    \
+        catched = true;                                                \
+    }                                                                  \
+    RUNNER_ASSERT_MSG(catched == expectedCatch,                        \
+                         "Exception catched = " << catched             \
+                         << " while expected is = " << expectedCatch); \
+}
+
+#define FILTER(F) { \
+    try {           \
+        F;          \
+    } catch (...) { \
+    }               \
+}
+
+#define TRYCATCH(F) {      \
+    RUNNER_DEFER_TRYCATCH( \
+        F;                 \
+    );                     \
+}
+
+#define SCOPE(F) {      \
+    RUNNER_DEFER_SCOPE( \
+        F;              \
+    );                  \
+}
+
+void fail(void)
+{
+    RUNNER_FAIL_MSG("Oops!");
+}
+
+void pass(void)
+{
+}
+
+RUNNER_TEST_GROUP_INIT(DEFERRED)
+
+RUNNER_TEST(id01_simple_fail)
+{
+    EXPECT_EXCEPTION(true, fail());
+}
+
+RUNNER_TEST(id02_filtred_fail)
+{
+    EXPECT_EXCEPTION(false, FILTER(fail()));
+}
+
+RUNNER_TEST(id03_saved_filtred_rethrown_fail)
+{
+    EXPECT_EXCEPTION(true, SCOPE(FILTER(TRYCATCH(fail()))));
+}
+
+RUNNER_TEST(id04_saved_filtred_fail)
+{
+    EXPECT_EXCEPTION(false, FILTER(TRYCATCH(fail())));
+}
+
+RUNNER_TEST(id05_filtred_rethrown_fail)
+{
+    EXPECT_EXCEPTION(false, SCOPE(FILTER(fail())));
+}
+
+RUNNER_TEST(id06_saved_rethrown_fail)
+{
+    EXPECT_EXCEPTION(true, SCOPE(TRYCATCH(fail())));
+}
+
+RUNNER_TEST(id07_saved_fail)
+{
+    EXPECT_EXCEPTION(true, TRYCATCH(fail()));
+}
+
+RUNNER_TEST(id08_rethrown_fail)
+{
+    EXPECT_EXCEPTION(true, SCOPE(fail()));
+}
+
+RUNNER_TEST(id09_nested_scope)
+{
+    EXPECT_EXCEPTION(true, SCOPE(SCOPE(SCOPE(FILTER(TRYCATCH(fail()))))));
+}
+
+RUNNER_TEST(id10_nested_scope2)
+{
+    EXPECT_EXCEPTION(true, SCOPE(SCOPE(FILTER(SCOPE(TRYCATCH(fail()))))));
+}
+
+RUNNER_TEST(id11_saved_filtred_rethrown_pass)
+{
+    EXPECT_EXCEPTION(false, SCOPE(FILTER(TRYCATCH(pass()))));
+}