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 FailStatus status,
64 const std::string& reason,
65 const bool& isPerformanceTest,
66 const std::chrono::system_clock::duration& performanceTime,
67 const std::chrono::system_clock::duration& performanceMaxTime)
69 using namespace DPL::Colors::Text;
70 std::string tmp = "'" + id + "' ...";
72 printf("Running test case %-60s", tmp.c_str());
74 case FailStatus::NONE:
75 if (isPerformanceTest) {
76 if (performanceMaxTime <= std::chrono::microseconds::zero()) {
77 printf(GREEN_RESULT_OK_TIME,
78 get_milliseconds(performanceTime));
82 if (performanceTime > performanceMaxTime)
83 printf(GREEN_RESULT_OK_TIME_TOO_LONG(
84 get_milliseconds(performanceTime),
85 get_milliseconds(performanceMaxTime)));
87 printf(GREEN_RESULT_OK_TIME_MAX(
88 get_milliseconds(performanceTime),
89 get_milliseconds(performanceMaxTime)));
93 printf(GREEN_RESULT_OK);
95 case FailStatus::FAILED:
96 PrintfErrorMessage(" FAILED ", reason, true);
98 case FailStatus::IGNORED:
99 PrintfIgnoredMessage("Ignored ", reason, true);
102 Assert(false && "Bad status");
104 m_stats.AddTest(status);
105 m_groupsStats[m_currentGroup].AddTest(status);
108 void ConsoleCollector::PrintfErrorMessage(const char* type,
109 const std::string& message,
112 using namespace DPL::Colors::Text;
114 printf("[%s%s%s] %s%s%s\n",
129 void ConsoleCollector::PrintfIgnoredMessage(const char* type,
130 const std::string& message,
133 using namespace DPL::Colors::Text;
135 printf("[%s%s%s] %s%s%s\n",
150 void ConsoleCollector::PrintStats(const std::string& title, const Statistic& stats)
152 using namespace DPL::Colors::Text;
153 printf("\n%sResults [%s]: %s\n", BOLD_GREEN_BEGIN,
154 title.c_str(), BOLD_GREEN_END);
155 printf("%s%s%3zu%s\n",
160 printf(" %s%s%3zu%s\n",
165 printf(" %s%s%3zu%s\n",
170 printf(" %s%s%3zu%s\n",