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()
40 TestResultsCollectorBase* ConsoleCollector::Constructor()
42 return new ConsoleCollector();
45 void ConsoleCollector::CollectCurrentTestGroupName(const std::string& name)
47 printf("Starting group %s\n", name.c_str());
48 m_currentGroup = name;
51 void ConsoleCollector::Finish()
53 using namespace DPL::Colors::Text;
56 for (auto &group : m_groupsStats) {
57 PrintStats(group.first, group.second);
59 PrintStats("All tests together", m_stats);
62 void ConsoleCollector::CollectResult(const std::string& id,
63 const std::string& /*description*/,
64 const FailStatus::Type status,
65 const std::string& reason,
66 const bool& isPerformanceTest,
67 const std::chrono::system_clock::duration& performanceTime,
68 const std::chrono::system_clock::duration& performanceMaxTime)
70 using namespace DPL::Colors::Text;
71 std::string tmp = "'" + id + "' ...";
73 printf("Running test case %-60s", tmp.c_str());
75 case TestResultsCollectorBase::FailStatus::NONE:
76 if (isPerformanceTest) {
77 if (performanceMaxTime <= std::chrono::microseconds::zero()) {
78 printf(GREEN_RESULT_OK_TIME,
79 get_milliseconds(performanceTime));
83 if (performanceTime > performanceMaxTime)
84 printf(GREEN_RESULT_OK_TIME_TOO_LONG(
85 get_milliseconds(performanceTime),
86 get_milliseconds(performanceMaxTime)));
88 printf(GREEN_RESULT_OK_TIME_MAX(
89 get_milliseconds(performanceTime),
90 get_milliseconds(performanceMaxTime)));
94 printf(GREEN_RESULT_OK);
96 case TestResultsCollectorBase::FailStatus::FAILED:
97 PrintfErrorMessage(" FAILED ", reason, true);
99 case TestResultsCollectorBase::FailStatus::IGNORED:
100 PrintfIgnoredMessage("Ignored ", reason, true);
102 case TestResultsCollectorBase::FailStatus::INTERNAL:
103 PrintfErrorMessage("INTERNAL", reason, true);
106 Assert(false && "Bad status");
108 m_stats.AddTest(status);
109 m_groupsStats[m_currentGroup].AddTest(status);
112 void ConsoleCollector::PrintfErrorMessage(const char* type,
113 const std::string& message,
116 using namespace DPL::Colors::Text;
118 printf("[%s%s%s] %s%s%s\n",
133 void ConsoleCollector::PrintfIgnoredMessage(const char* type,
134 const std::string& message,
137 using namespace DPL::Colors::Text;
139 printf("[%s%s%s] %s%s%s\n",
154 void ConsoleCollector::PrintStats(const std::string& title, const Statistic& stats)
156 using namespace DPL::Colors::Text;
157 printf("\n%sResults [%s]: %s\n", BOLD_GREEN_BEGIN,
158 title.c_str(), BOLD_GREEN_END);
159 printf("%s%s%3zu%s\n",
164 printf(" %s%s%3zu%s\n",
169 printf(" %s%s%3zu%s\n",
174 printf(" %s%s%3zu%s\n",