2 * Copyright (c) 2014 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 test_results_collector_console.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
19 * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
21 * @brief Source file containing ConsoleCollector class definition
27 #include <dpl/assert.h>
28 #include <dpl/colors.h>
29 #include <dpl/test/test_results_collector_commons.h>
31 #include "dpl/test/test_results_collector_console.h"
36 ConsoleCollector::ConsoleCollector()
41 TestResultsCollectorBase* ConsoleCollector::Constructor()
43 return new ConsoleCollector();
46 bool ConsoleCollector::ParseCollectorSpecificArg(const std::string& arg)
48 return ParseCollectorNoVerboseArg(arg, m_verbosity);
51 std::string ConsoleCollector::CollectorSpecificHelp() const
53 return COLLECTOR_NO_VERBOSE_HELP;
56 void ConsoleCollector::CollectCurrentTestGroupName(const std::string& name)
58 printf("Starting group %s\n", name.c_str());
59 m_currentGroup = name;
62 void ConsoleCollector::Finish()
64 using namespace DPL::Colors::Text;
67 for (auto &group : m_groupsStats) {
68 PrintStats(group.first, group.second);
70 PrintStats("All tests together", m_stats);
73 void ConsoleCollector::CollectResult(const std::string& id,
74 const FailStatus status,
75 const std::string& reason,
76 const bool& isPerformanceTest,
77 const std::chrono::system_clock::duration& performanceTime,
78 const std::chrono::system_clock::duration& performanceMaxTime)
80 using namespace DPL::Colors::Text;
81 std::string tmp = "'" + id + "' ...";
83 printf("Running test case %-60s", tmp.c_str());
85 case FailStatus::NONE:
86 if (isPerformanceTest) {
87 if (performanceMaxTime <= std::chrono::microseconds::zero()) {
88 printf(GREEN_RESULT_OK_TIME,
89 get_milliseconds(performanceTime));
93 if (performanceTime > performanceMaxTime)
94 printf(GREEN_RESULT_OK_TIME_TOO_LONG(
95 get_milliseconds(performanceTime),
96 get_milliseconds(performanceMaxTime)));
98 printf(GREEN_RESULT_OK_TIME_MAX(
99 get_milliseconds(performanceTime),
100 get_milliseconds(performanceMaxTime)));
104 printf(GREEN_RESULT_OK);
106 case FailStatus::FAILED:
107 PrintfErrorMessage(" FAILED ", reason);
109 case FailStatus::IGNORED:
110 PrintfIgnoredMessage("Ignored ", reason);
113 Assert(false && "Bad status");
115 m_stats.AddTest(status);
116 m_groupsStats[m_currentGroup].AddTest(status);
119 void ConsoleCollector::PrintfErrorMessage(const char* type, const std::string& message)
121 using namespace DPL::Colors::Text;
135 void ConsoleCollector::PrintfIgnoredMessage(const char* type, const std::string& message)
137 using namespace DPL::Colors::Text;
151 void ConsoleCollector::PrintStats(const std::string& title, const Statistic& stats)
153 using namespace DPL::Colors::Text;
154 printf("\n%sResults [%s]: %s\n", BOLD_GREEN_BEGIN,
155 title.c_str(), BOLD_GREEN_END);
156 printf("%s%s%3zu%s\n",
161 printf(" %s%s%3zu%s\n",
166 printf(" %s%s%3zu%s\n",
171 printf(" %s%s%3zu%s\n",