2 * Copyright (c) 2011 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.
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
21 * @brief This file is the header file of test runner
23 #ifndef DPL_TEST_RUNNER_H
24 #define DPL_TEST_RUNNER_H
26 #include <dpl/singleton.h>
27 #include <dpl/unused.h>
28 #include <dpl/atomic.h>
29 #include <dpl/test/test_results_collector.h>
42 TestResultsCollectorBasePtr m_collector;
43 std::string m_collectorName;
44 std::string m_startTestId;
47 typedef void (*TestCase)();
55 bool operator <(const TestCaseStruct &other) const
57 return name < other.name;
60 bool operator ==(const TestCaseStruct &other) const
62 return name == other.name;
65 TestCaseStruct(const std::string &n, TestCase p)
72 typedef std::list<TestCaseStruct> TestCaseStructList;
73 typedef std::map<std::string, TestCaseStructList> TestCaseGroupMap;
74 TestCaseGroupMap m_testGroups;
76 typedef std::set<std::string> SelectedTestNameSet;
77 SelectedTestNameSet m_selectedTestNamesSet;
78 typedef std::set<std::string> SelectedTestGroupSet;
79 SelectedTestGroupSet m_selectedTestGroupSet;
80 std::string m_currentGroup;
82 DPL::Atomic m_totalAssertions;
88 enum Status { FAILED, TODO, IGNORED, PASS };
90 Status RunTestCase(const TestCaseStruct& testCase);
98 std::string m_message;
105 //! \brief Failed test message creator
107 //! \param[in] aTest string for tested expression
108 //! \param[in] aFile source file name
109 //! \param[in] aLine source file line
110 //! \param[in] aMessage error message
111 TestFailed(const char* aTest, const char* aFile, int aLine, const std::string &aMessage);
113 std::string GetMessage() const
122 std::string m_message;
129 ToDo(const std::string &message)
134 std::string GetMessage() const
143 std::string m_message;
150 Ignored(const std::string &message)
155 std::string GetMessage() const
161 void MarkAssertion();
163 void RegisterTest(const char *testName, TestCase proc);
164 void InitGroup(const char* name);
166 int ExecTestRunner(int argc, char *argv[]);
167 typedef std::vector<std::string> ArgsList;
168 int ExecTestRunner(const ArgsList& args);
171 typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
176 #define RUNNER_TEST_GROUP_INIT(GroupName) \
177 static int Static##GroupName##Init() \
179 DPL::Test::TestRunnerSingleton::Instance().InitGroup(#GroupName);\
182 const int DPL_UNUSED Static##GroupName##InitVar = \
183 Static##GroupName##Init();
185 #define RUNNER_TEST(Proc) \
187 static int Static##Proc##Init() \
189 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
192 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
195 //! \brief Returns base name for path
197 #define RUNNER_ASSERT_MSG(test, message) \
200 DPL::Test::TestRunnerSingleton::Instance().MarkAssertion(); \
204 std::ostringstream assertMsg; \
205 assertMsg << message; \
206 throw DPL::Test::TestRunner::TestFailed(#test, __FILE__, __LINE__, assertMsg.str()); \
210 #define RUNNER_ASSERT(test) RUNNER_ASSERT_MSG(test, "")
212 #define RUNNER_FAIL RUNNER_ASSERT(false)
214 #define RUNNER_TODO_MSG(message) do { std::ostringstream assertMsg; assertMsg << message; throw DPL::Test::TestRunner::ToDo(assertMsg.str()); } while (0)
216 #define RUNNER_IGNORED_MSG(message) do { std::ostringstream assertMsg; assertMsg << message; throw DPL::Test::TestRunner::Ignored(assertMsg.str()); } while (0)
218 #endif // DPL_TEST_RUNNER_H