2 * Copyright (c) 2014-2015 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, const TestResult &result)
75 using namespace DPL::Colors::Text;
76 std::string tmp = "'" + id + "' ...";
78 printf("Running test case %-60s", tmp.c_str());
80 ConstPerformanceResultPtr performanceResult;
81 switch (result.GetFailStatus()) {
82 case TestResult::FailStatus::NONE:
83 performanceResult = result.GetPerformanceResult();
84 if (!performanceResult) {
85 printf(GREEN_RESULT_OK);
88 if (!performanceResult->IsMaxDuration()) {
89 printf(GREEN_RESULT_OK_TIME,
90 get_milliseconds(performanceResult->GetDuration()));
93 if (!performanceResult->IsDurationOk()) {
94 printf(GREEN_RESULT_OK_TIME_TOO_LONG(
95 get_milliseconds(performanceResult->GetDuration()),
96 get_milliseconds(performanceResult->GetMaxDuration())));
99 printf(GREEN_RESULT_OK_TIME_MAX(
100 get_milliseconds(performanceResult->GetDuration()),
101 get_milliseconds(performanceResult->GetMaxDuration())));
103 case TestResult::FailStatus::FAILED:
104 PrintfErrorMessage(" FAILED ", result.GetReason());
106 case TestResult::FailStatus::IGNORED:
107 PrintfIgnoredMessage("Ignored ", result.GetReason());
110 Assert(false && "Bad status");
112 m_stats.AddTest(result.GetFailStatus());
113 m_groupsStats[m_currentGroup].AddTest(result.GetFailStatus());
116 void ConsoleCollector::PrintfErrorMessage(const char* type, const std::string& message)
118 using namespace DPL::Colors::Text;
132 void ConsoleCollector::PrintfIgnoredMessage(const char* type, const std::string& message)
134 using namespace DPL::Colors::Text;
148 void ConsoleCollector::PrintStats(const std::string& title, const Statistic& stats)
150 using namespace DPL::Colors::Text;
151 printf("\n%sResults [%s]: %s\n", BOLD_GREEN_BEGIN,
152 title.c_str(), BOLD_GREEN_END);
153 printf("%s%s%3zu%s\n",
158 printf(" %s%s%3zu%s\n",
163 printf(" %s%s%3zu%s\n",
168 printf(" %s%s%3zu%s\n",