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>
28 std::list<std::string> split_string(std::string str, std::string delimiter)
32 std::list<std::string> stringList;
33 while ((pos = str.find(delimiter)) != std::string::npos) {
34 token = str.substr(0, pos);
35 stringList.push_back(token);
36 str.erase(0, pos + delimiter.length());
38 if(str.length() != 0){
39 stringList.push_back(token);
45 #define RUNNER_MULTIPROCESS_TEST_EXPECT(name, messages) \
46 static void testExpectFunction##name(); \
51 DPL::Test::RunMultiProc(&testExpectFunction##name); \
53 Catch(DPL::Test::TestRunner::TestFailed) \
55 std::string eMsg = messages; \
56 std::list<std::string> eMessages = split_string(eMsg, "|"); \
57 std::string rMessage = _rethrown_exception.GetMessage(); \
58 if(eMsg.length() == 0 && rMessage.length() != 0) { \
59 RUNNER_ASSERT_MSG(false, rMessage); \
61 bool failedFound = false; \
62 for(std::list<std::string>::iterator it = eMessages.begin(); \
63 it != eMessages.end(); \
66 if (!(*it).compare("TEST_FAILED")) { \
70 RUNNER_ASSERT_MSG(rMessage.find(*it)!=std::string::npos, \
71 "Key word " << *it << " not found in " << rMessage); \
74 rMessage.find("Reading pipe error")==std::string::npos, \
75 "Reading pipe error"); \
77 rMessage.find("Timeout error")==std::string::npos, \
79 RUNNER_ASSERT_MSG(failedFound, "No TEST_FAILED found"); \
81 Catch(DPL::Test::TestRunner::Ignored) \
83 std::string eMsg = messages; \
84 std::list<std::string> eMessages = split_string(eMsg, "|"); \
85 std::string rMessage = _rethrown_exception.GetMessage(); \
86 if(eMsg.length() == 0 && rMessage.length() != 0) { \
87 RUNNER_ASSERT_MSG(false, rMessage); \
89 bool ignoredFound = false; \
90 for(std::list<std::string>::iterator it = eMessages.begin(); \
91 it != eMessages.end(); \
94 if (!(*it).compare("TEST_IGNORED")) { \
95 ignoredFound = true; \
98 RUNNER_ASSERT_MSG(rMessage.find(*it)!=std::string::npos, \
99 "Key word " << *it << " not found in " << rMessage); \
102 rMessage.find("Reading pipe error")==std::string::npos, \
103 "Reading pipe error"); \
105 rMessage.find("Timeout error")==std::string::npos, \
107 RUNNER_ASSERT_MSG(ignoredFound, "No TEST_IGNORED found"); \
110 void testExpectFunction##name() \
112 RUNNER_TEST_GROUP_INIT(DPL_TESTS_TEST_MULTIPROCESS)
114 RUNNER_MULTIPROCESS_TEST_EXPECT(tm00_pass, "")
116 RUNNER_ASSERT_MSG(1, "This test should pass");
119 RUNNER_MULTIPROCESS_TEST_EXPECT(tm01_pass, "")
124 RUNNER_ASSERT_MSG(1, "This test should pass");
126 RUNNER_ASSERT_MSG(1, "This test should pass");
128 RUNNER_ASSERT_MSG(1, "This test should pass");
131 RUNNER_MULTIPROCESS_TEST_EXPECT(tm02_pass, "")
135 RUNNER_ASSERT_MSG(1, "This test should pass");
138 RUNNER_ASSERT_MSG(1, "This test should pass");
140 RUNNER_ASSERT_MSG(1, "This test should pass");
143 RUNNER_MULTIPROCESS_TEST_EXPECT(tm03_pass, "")
162 RUNNER_MULTIPROCESS_TEST_EXPECT(tm04_fail, "TEST_FAILED|"
163 "This test should fail")
165 RUNNER_ASSERT_MSG(0, "This test should fail");
168 RUNNER_MULTIPROCESS_TEST_EXPECT(tm05_fail,"TEST_FAILED|"
178 RUNNER_ASSERT_MSG(0, "Test failed 1");
180 RUNNER_ASSERT_MSG(0, "Test failed 2");
185 RUNNER_ASSERT_MSG(0, "Test failed 3");
187 RUNNER_ASSERT_MSG(0, "Test failed 4");
192 RUNNER_MULTIPROCESS_TEST_EXPECT(tm06_fail, "TEST_FAILED|"
203 RUNNER_ASSERT_MSG(0, "Test failed 1");
205 RUNNER_ASSERT_MSG(0, "Test failed 2");
210 RUNNER_ASSERT_MSG(0, "Test failed 3");
212 RUNNER_ASSERT_MSG(0, "Test failed 4");
217 RUNNER_MULTIPROCESS_TEST_EXPECT(tm07_fail, "TEST_FAILED|"
227 RUNNER_ASSERT_MSG(0, "Test failed 1");
229 RUNNER_ASSERT_MSG(0, "Test failed 2");
235 RUNNER_ASSERT_MSG(0, "Test failed 3");
237 RUNNER_ASSERT_MSG(0, "Test failed 4");
242 RUNNER_MULTIPROCESS_TEST_EXPECT(tm08_fail_unknown_exception, "TEST_FAILED|"
248 RUNNER_MULTIPROCESS_TEST_EXPECT(tm09_fail_unknown_exception, "TEST_FAILED|"
254 RUNNER_MULTIPROCESS_TEST_EXPECT(tm10_ignore, "TEST_IGNORED|"
257 RUNNER_IGNORED_MSG("Test ignored");
260 RUNNER_MULTIPROCESS_TEST_EXPECT(tm11_ignore, "TEST_IGNORED|"
270 RUNNER_IGNORED_MSG("Test ignored 1");
272 RUNNER_IGNORED_MSG("Test ignored 2");
278 RUNNER_IGNORED_MSG("Test ignored 3");
280 RUNNER_IGNORED_MSG("Test ignored 4");
285 RUNNER_MULTIPROCESS_TEST_EXPECT(tm12_fail, "TEST_FAILED|"
295 RUNNER_ASSERT_MSG(0, "Test failed 1");
297 RUNNER_IGNORED_MSG("Test ignored 2");
303 RUNNER_IGNORED_MSG("Test ignored 3");
305 RUNNER_IGNORED_MSG("Test ignored 4");