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 runner_multiprocess.cpp
18 * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
20 * @brief Implementation file for test cases for engine internal tests
23 #include <dpl/test/test_runner_multiprocess.h>
24 #include <dpl/test/test_runner.h>
25 #include <dpl/log/log.h>
29 std::list<std::string> split_string(std::string str, std::string delimiter)
33 std::list<std::string> stringList;
34 while ((pos = str.find(delimiter)) != std::string::npos) {
35 token = str.substr(0, pos);
36 stringList.push_back(token);
37 str.erase(0, pos + delimiter.length());
39 if(str.length() != 0){
40 stringList.push_back(token);
46 #define RUNNER_MULTIPROCESS_TEST_EXPECT(name, messages) \
47 static void testExpectFunction##name(); \
52 DPL::Test::RunMultiProc(&testExpectFunction##name); \
54 Catch(DPL::Test::TestRunner::TestFailed) \
56 std::string eMsg = messages; \
57 std::list<std::string> eMessages = split_string(eMsg, "|"); \
58 std::string rMessage = _rethrown_exception.GetMessage(); \
59 if(eMsg.length() == 0 && rMessage.length() != 0) { \
60 RUNNER_ASSERT_MSG(false, rMessage); \
62 bool failedFound = false; \
63 for(std::list<std::string>::iterator it = eMessages.begin(); \
64 it != eMessages.end(); \
67 if (!(*it).compare("TEST_FAILED")) { \
71 RUNNER_ASSERT_MSG(rMessage.find(*it)!=std::string::npos, \
72 "Key word " << *it << " not found in " << rMessage); \
75 rMessage.find("Reading pipe error")==std::string::npos, \
76 "Reading pipe error"); \
78 rMessage.find("Timeout error")==std::string::npos, \
80 RUNNER_ASSERT_MSG(failedFound, "No TEST_FAILED found"); \
82 Catch(DPL::Test::TestRunner::Ignored) \
84 std::string eMsg = messages; \
85 std::list<std::string> eMessages = split_string(eMsg, "|"); \
86 std::string rMessage = _rethrown_exception.GetMessage(); \
87 if(eMsg.length() == 0 && rMessage.length() != 0) { \
88 RUNNER_ASSERT_MSG(false, rMessage); \
90 bool ignoredFound = false; \
91 for(std::list<std::string>::iterator it = eMessages.begin(); \
92 it != eMessages.end(); \
95 if (!(*it).compare("TEST_IGNORED")) { \
96 ignoredFound = true; \
99 RUNNER_ASSERT_MSG(rMessage.find(*it)!=std::string::npos, \
100 "Key word " << *it << " not found in " << rMessage); \
103 rMessage.find("Reading pipe error")==std::string::npos, \
104 "Reading pipe error"); \
106 rMessage.find("Timeout error")==std::string::npos, \
108 RUNNER_ASSERT_MSG(ignoredFound, "No TEST_IGNORED found"); \
111 void testExpectFunction##name() \
113 RUNNER_TEST_GROUP_INIT(DPL_TESTS_TEST_MULTIPROCESS)
115 RUNNER_MULTIPROCESS_TEST_EXPECT(tm00_pass, "")
117 RUNNER_ASSERT_MSG(1, "This test should pass");
120 RUNNER_MULTIPROCESS_TEST_EXPECT(tm01_pass, "")
125 RUNNER_ASSERT_MSG(1, "This test should pass");
127 RUNNER_ASSERT_MSG(1, "This test should pass");
129 RUNNER_ASSERT_MSG(1, "This test should pass");
132 RUNNER_MULTIPROCESS_TEST_EXPECT(tm02_pass, "")
136 RUNNER_ASSERT_MSG(1, "This test should pass");
139 RUNNER_ASSERT_MSG(1, "This test should pass");
141 RUNNER_ASSERT_MSG(1, "This test should pass");
144 RUNNER_MULTIPROCESS_TEST_EXPECT(tm03_pass, "")
163 RUNNER_MULTIPROCESS_TEST_EXPECT(tm04_fail, "TEST_FAILED|"
164 "This test should fail")
166 RUNNER_ASSERT_MSG(0, "This test should fail");
169 RUNNER_MULTIPROCESS_TEST_EXPECT(tm05_fail,"TEST_FAILED|"
179 RUNNER_ASSERT_MSG(0, "Test failed 1");
181 RUNNER_ASSERT_MSG(0, "Test failed 2");
186 RUNNER_ASSERT_MSG(0, "Test failed 3");
188 RUNNER_ASSERT_MSG(0, "Test failed 4");
193 RUNNER_MULTIPROCESS_TEST_EXPECT(tm06_fail, "TEST_FAILED|"
204 RUNNER_ASSERT_MSG(0, "Test failed 1");
206 RUNNER_ASSERT_MSG(0, "Test failed 2");
211 RUNNER_ASSERT_MSG(0, "Test failed 3");
213 RUNNER_ASSERT_MSG(0, "Test failed 4");
218 RUNNER_MULTIPROCESS_TEST_EXPECT(tm07_fail, "TEST_FAILED|"
228 RUNNER_ASSERT_MSG(0, "Test failed 1");
230 RUNNER_ASSERT_MSG(0, "Test failed 2");
236 RUNNER_ASSERT_MSG(0, "Test failed 3");
238 RUNNER_ASSERT_MSG(0, "Test failed 4");
243 RUNNER_MULTIPROCESS_TEST_EXPECT(tm08_fail_unknown_exception, "TEST_FAILED|"
249 RUNNER_MULTIPROCESS_TEST_EXPECT(tm09_fail_unknown_exception, "TEST_FAILED|"
255 RUNNER_MULTIPROCESS_TEST_EXPECT(tm10_ignore, "TEST_IGNORED|"
258 RUNNER_IGNORED_MSG("Test ignored");
261 RUNNER_MULTIPROCESS_TEST_EXPECT(tm11_ignore, "TEST_IGNORED|"
271 RUNNER_IGNORED_MSG("Test ignored 1");
273 RUNNER_IGNORED_MSG("Test ignored 2");
279 RUNNER_IGNORED_MSG("Test ignored 3");
281 RUNNER_IGNORED_MSG("Test ignored 4");
286 RUNNER_MULTIPROCESS_TEST_EXPECT(tm12_fail, "TEST_FAILED|"
296 RUNNER_ASSERT_MSG(0, "Test failed 1");
298 RUNNER_IGNORED_MSG("Test ignored 2");
304 RUNNER_IGNORED_MSG("Test ignored 3");
306 RUNNER_IGNORED_MSG("Test ignored 4");