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"
37 const std::string NO_VERBOSE_ARG = "--no-verbose";
41 ConsoleCollector::ConsoleCollector()
46 TestResultsCollectorBase* ConsoleCollector::Constructor()
48 return new ConsoleCollector();
51 bool ConsoleCollector::ParseCollectorSpecificArg(const std::string& arg)
53 if (arg != NO_VERBOSE_ARG)
59 std::string ConsoleCollector::CollectorSpecificHelp() const
61 return NO_VERBOSE_ARG + " - turns off verbosity\n" +
62 std::string(NO_VERBOSE_ARG.size(), ' ') + " verbosity turned on by default\n";
65 void ConsoleCollector::CollectCurrentTestGroupName(const std::string& name)
67 printf("Starting group %s\n", name.c_str());
68 m_currentGroup = name;
71 void ConsoleCollector::Finish()
73 using namespace DPL::Colors::Text;
76 for (auto &group : m_groupsStats) {
77 PrintStats(group.first, group.second);
79 PrintStats("All tests together", m_stats);
82 void ConsoleCollector::CollectResult(const std::string& id,
83 const FailStatus status,
84 const std::string& reason,
85 const bool& isPerformanceTest,
86 const std::chrono::system_clock::duration& performanceTime,
87 const std::chrono::system_clock::duration& performanceMaxTime)
89 using namespace DPL::Colors::Text;
90 std::string tmp = "'" + id + "' ...";
92 printf("Running test case %-60s", tmp.c_str());
94 case FailStatus::NONE:
95 if (isPerformanceTest) {
96 if (performanceMaxTime <= std::chrono::microseconds::zero()) {
97 printf(GREEN_RESULT_OK_TIME,
98 get_milliseconds(performanceTime));
102 if (performanceTime > performanceMaxTime)
103 printf(GREEN_RESULT_OK_TIME_TOO_LONG(
104 get_milliseconds(performanceTime),
105 get_milliseconds(performanceMaxTime)));
107 printf(GREEN_RESULT_OK_TIME_MAX(
108 get_milliseconds(performanceTime),
109 get_milliseconds(performanceMaxTime)));
113 printf(GREEN_RESULT_OK);
115 case FailStatus::FAILED:
116 PrintfErrorMessage(" FAILED ", reason);
118 case FailStatus::IGNORED:
119 PrintfIgnoredMessage("Ignored ", reason);
122 Assert(false && "Bad status");
124 m_stats.AddTest(status);
125 m_groupsStats[m_currentGroup].AddTest(status);
128 void ConsoleCollector::PrintfErrorMessage(const char* type, const std::string& message)
130 using namespace DPL::Colors::Text;
144 void ConsoleCollector::PrintfIgnoredMessage(const char* type, const std::string& message)
146 using namespace DPL::Colors::Text;
160 void ConsoleCollector::PrintStats(const std::string& title, const Statistic& stats)
162 using namespace DPL::Colors::Text;
163 printf("\n%sResults [%s]: %s\n", BOLD_GREEN_BEGIN,
164 title.c_str(), BOLD_GREEN_END);
165 printf("%s%s%3zu%s\n",
170 printf(" %s%s%3zu%s\n",
175 printf(" %s%s%3zu%s\n",
180 printf(" %s%s%3zu%s\n",