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>
23 #include <dpl/log/log.h>
26 #include <sys/types.h>
41 #define RUNNER_CHILD_TEST_EXPECT(name, result, message) \
42 static void testExpectFunction##name(); \
45 TestResult eResult = result; \
46 TestResult rResult = TestResult::UNKNOWN; \
47 std::string eMessage = message; \
50 DPL::Test::RunChildProc(&testExpectFunction##name); \
52 Catch(DPL::Test::TestRunner::TestFailed) \
54 std::string rMessage = _rethrown_exception.GetMessage(); \
55 size_t pos = rMessage.find(")"); \
56 if(pos != std::string::npos && pos+2 <= rMessage.length()) \
58 rMessage = rMessage.substr(pos+2); \
60 if(rMessage == "Timeout") \
62 rResult = TestResult::TIMEOUT; \
64 else if(rMessage == "Ignored") \
66 rResult = TestResult::IGNORED; \
68 else if(rMessage == eMessage) \
70 rResult = TestResult::FAIL; \
74 RUNNER_ASSERT_MSG(false, "Fail message do not matches"); \
77 if(rResult == TestResult::UNKNOWN) \
79 rResult = TestResult::PASS; \
81 RUNNER_ASSERT_MSG(eResult == rResult, "Expected other result"); \
83 void testExpectFunction##name() \
86 RUNNER_TEST_GROUP_INIT(DPL_TESTS_TEST_CHILD)
88 RUNNER_CHILD_TEST_EXPECT(t00_pass, TestResult::PASS, "")
90 RUNNER_ASSERT_MSG(1, "This test should pass");
93 RUNNER_CHILD_TEST_EXPECT(t01_pass, TestResult::PASS, "")
95 RUNNER_ASSERT_MSG(1, "This test should pass");
98 RUNNER_CHILD_TEST_EXPECT(t02_fail, TestResult::FAIL, "This test should fail")
100 RUNNER_ASSERT_MSG(0, "This test should fail");
103 RUNNER_CHILD_TEST_EXPECT(t03_fail_timeout, TestResult::TIMEOUT, "")
106 RUNNER_ASSERT_MSG(1, "This test should fail");
109 RUNNER_CHILD_TEST_EXPECT(t04_fail, TestResult::FAIL, "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(1, "This test should fail");
115 RUNNER_ASSERT_MSG(0, "This test should fail");
118 RUNNER_CHILD_TEST_EXPECT(t05_fail_child_died, TestResult::FAIL, "Reading pipe error")
120 kill(getpid(), SIGKILL);
121 RUNNER_ASSERT_MSG(1, "This test should fail");
124 RUNNER_CHILD_TEST_EXPECT(t06_pass_8_second_test, TestResult::PASS, "")
127 RUNNER_ASSERT_MSG(1, "This test should pass");
130 RUNNER_CHILD_TEST_EXPECT(t07_fail_unknown_exception, TestResult::FAIL, "unhandled exeception")
135 RUNNER_CHILD_TEST_EXPECT(t08_fail_unknown_exception, TestResult::FAIL, "unhandled exeception")
140 RUNNER_CHILD_TEST_EXPECT(t09_fail_you_should_see_text_normal_assert, TestResult::FAIL, "Normal assert")
142 RUNNER_ASSERT_MSG(0, "Normal assert");
145 RUNNER_CHILD_TEST_EXPECT(t10_pass, TestResult::PASS, "")
147 RUNNER_ASSERT_MSG(1, "Normal assert");
150 RUNNER_CHILD_TEST_EXPECT(t11_ignore, TestResult::IGNORED, "Test ignored")
152 RUNNER_IGNORED_MSG("Test ignored");