Merging tizen into ckm. Stage 1.
[platform/core/test/security-tests.git] / tests / framework / src / test_results_collector.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        test_results_collector.h
18  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @version     1.0
20  * @brief       Implementation file some concrete TestResulstsCollector
21  */
22 #include <dpl/test/statistic.h>
23 #include <dpl/test/test_results_collector.h>
24 #include <dpl/test/test_results_collector_console.h>
25 #include <dpl/test/test_results_collector_html.h>
26 #include <dpl/test/test_results_collector_summary.h>
27 #include <dpl/test/test_results_collector_xml.h>
28
29 namespace DPL {
30 namespace Test {
31
32 void TestResultsCollectorBase::RegisterCollectorConstructor(
33     const std::string& name,
34     TestResultsCollectorBase::CollectorConstructorFunc func)
35 {
36     Assert(m_constructorsMap.find(name) == m_constructorsMap.end());
37     m_constructorsMap[name] = func;
38 }
39
40 TestResultsCollectorBase* TestResultsCollectorBase::Create(
41     const std::string& name)
42 {
43     ConstructorsMap::iterator found = m_constructorsMap.find(name);
44     if (found != m_constructorsMap.end()) {
45         return found->second();
46     } else {
47         return nullptr;
48     }
49 }
50
51 std::vector<std::string> TestResultsCollectorBase::GetCollectorsNames()
52 {
53     std::vector<std::string> list;
54     for (auto &constructor : m_constructorsMap)
55     {
56         list.push_back(constructor.first);
57     }
58     return list;
59 }
60
61 TestResultsCollectorBase::ConstructorsMap TestResultsCollectorBase::
62     m_constructorsMap;
63
64 namespace {
65 static int RegisterCollectorConstructors();
66 static const int RegisterHelperVariable = RegisterCollectorConstructors();
67 int RegisterCollectorConstructors()
68 {
69     (void)RegisterHelperVariable;
70
71     TestResultsCollectorBase::RegisterCollectorConstructor(
72         "text",
73         &ConsoleCollector::Constructor);
74     TestResultsCollectorBase::RegisterCollectorConstructor(
75         "html",
76         &HtmlCollector::Constructor);
77     TestResultsCollectorBase::RegisterCollectorConstructor(
78         "summary",
79         &SummaryCollector::Constructor);
80     TestResultsCollectorBase::RegisterCollectorConstructor(
81         "xml",
82         &XmlCollector::Constructor);
83
84     return 0;
85 }
86 }
87 }
88 }