2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file widget_version.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Implementation file for test cases for engine internal tests
22 #include <dpl/test/test_runner_child.h>
25 #include <sys/types.h>
40 #define RUNNER_CHILD_TEST_EXPECT(name, result, message) \
41 static void testExpectFunction##name(); \
44 TestResult eResult = result; \
45 TestResult rResult = TestResult::UNKNOWN; \
46 std::string eMessage = message; \
49 DPL::Test::RunChildProc(&testExpectFunction##name); \
51 Catch(DPL::Test::TestRunner::TestFailed) \
53 std::string rMessage = _rethrown_exception.GetMessage(); \
54 size_t pos = rMessage.find(")"); \
55 if(pos != std::string::npos && pos+2 <= rMessage.length()) \
57 rMessage = rMessage.substr(pos+2); \
59 if(rMessage == "Timeout") \
61 rResult = TestResult::TIMEOUT; \
63 else if(rMessage == "Ignored") \
65 rResult = TestResult::IGNORED; \
67 else if(rMessage == eMessage) \
69 rResult = TestResult::FAIL; \
73 RUNNER_ASSERT_MSG(false, "Fail message do not matches"); \
76 if(rResult == TestResult::UNKNOWN) \
78 rResult = TestResult::PASS; \
80 RUNNER_ASSERT_MSG(eResult == rResult, "Expected other result"); \
82 void testExpectFunction##name() \
85 RUNNER_TEST_GROUP_INIT(DPL_TESTS_TEST_CHILD)
87 RUNNER_CHILD_TEST_EXPECT(t00_pass, TestResult::PASS, "")
89 RUNNER_ASSERT_MSG(1, "This test should pass");
92 RUNNER_CHILD_TEST_EXPECT(t01_pass, TestResult::PASS, "")
94 RUNNER_ASSERT_MSG(1, "This test should pass");
97 RUNNER_CHILD_TEST_EXPECT(t02_fail, TestResult::FAIL, "This test should fail")
99 RUNNER_ASSERT_MSG(0, "This test should fail");
102 RUNNER_CHILD_TEST_EXPECT(t03_fail_timeout, TestResult::TIMEOUT, "")
105 RUNNER_ASSERT_MSG(1, "This test should fail");
108 RUNNER_CHILD_TEST_EXPECT(t04_fail, TestResult::FAIL, "This test should fail")
110 RUNNER_ASSERT_MSG(1, "This test should fail");
111 RUNNER_ASSERT_MSG(1, "This test should fail");
112 RUNNER_ASSERT_MSG(1, "This test should fail");
113 RUNNER_ASSERT_MSG(1, "This test should fail");
114 RUNNER_ASSERT_MSG(0, "This test should fail");
117 RUNNER_CHILD_TEST_EXPECT(t05_fail_child_died, TestResult::FAIL, "Reading pipe error")
119 kill(getpid(), SIGKILL);
120 RUNNER_ASSERT_MSG(1, "This test should fail");
123 RUNNER_CHILD_TEST_EXPECT(t06_pass_8_second_test, TestResult::PASS, "")
126 RUNNER_ASSERT_MSG(1, "This test should pass");
129 RUNNER_CHILD_TEST_EXPECT(t07_fail_unknown_exception, TestResult::FAIL, "unhandled exeception")
134 RUNNER_CHILD_TEST_EXPECT(t08_fail_unknown_exception, TestResult::FAIL, "unhandled exeception")
139 RUNNER_CHILD_TEST_EXPECT(t09_fail_you_should_see_text_normal_assert, TestResult::FAIL, "Normal assert")
141 RUNNER_ASSERT_MSG(0, "Normal assert");
144 RUNNER_CHILD_TEST_EXPECT(t10_pass, TestResult::PASS, "")
146 RUNNER_ASSERT_MSG(1, "Normal assert");
149 RUNNER_CHILD_TEST_EXPECT(t11_ignore, TestResult::IGNORED, "Test ignored")
151 RUNNER_IGNORED_MSG("Test ignored");