+/*
+ * 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()))));
+}