Adjust AccessProvider api to current security-server.
[platform/core/test/security-tests.git] / tests / common / summary_collector.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /*
18  * @file        summary_collector.cpp
19  * @author      Michal Witanowski (m.witanowski@samsung.com)
20  * @version     1.0
21  * @brief       Implementation of custom test results collector needed by summary view.
22  */
23
24 #include <summary_collector.h>
25 #include <fstream>
26
27 namespace {
28     const char* summaryFileName = "/tmp/security-tests-summary-file";
29     const char* summaryCollectorName =  "summary";
30 };
31
32 SummaryCollector::SummaryCollector()
33 {
34     Start();
35 }
36
37
38 // Overrides DPL::Test::TestResultsCollectorBase::Start() virtual method.
39 void SummaryCollector::Start()
40 {
41     m_total = m_succeeded = m_failed = m_ignored = 0;
42 }
43
44 // append results to the file
45 void SummaryCollector::Finish()
46 {
47     std::ofstream outputFile;
48     outputFile.open(summaryFileName, std::ofstream::out | std::ofstream::app);
49     if (!outputFile)
50         return; //failed to open file
51
52     outputFile << m_total << ' '
53                << m_succeeded << ' '
54                << m_failed << ' '
55                << m_ignored << std::endl;
56     outputFile.close();
57 }
58
59 void SummaryCollector::CollectResult(const std::string& /*id*/,
60                                       const std::string& /*description*/,
61                                       const FailStatus::Type status,
62                                       const std::string& /*reason = ""*/,
63                                       const bool& isPerformanceTest,
64                                       const std::chrono::system_clock::duration& performanceTime,
65                                       const std::chrono::system_clock::duration& performanceMaxTime)
66 {
67     (void)isPerformanceTest;
68     (void)performanceTime;
69     (void)performanceMaxTime;
70     switch (status) {
71         case FailStatus::IGNORED: ++m_ignored; break;
72         case FailStatus::INTERNAL: // internal error count as fail
73         case FailStatus::FAILED: ++m_failed; break;
74         case FailStatus::NONE: ++m_succeeded; break;
75     };
76     ++m_total;
77 }
78
79 void SummaryCollector::CollectResult(const std::string& /*id*/,
80                                       const std::string& /*description*/,
81                                       const FailStatus::Type status,
82                                       const std::string& /*reason = ""*/)
83 {
84     switch (status) {
85         case FailStatus::IGNORED: ++m_ignored; break;
86         case FailStatus::INTERNAL: // internal error count as fail
87         case FailStatus::FAILED: ++m_failed; break;
88         case FailStatus::NONE: ++m_succeeded; break;
89     };
90     ++m_total;
91 }
92
93 DPL::Test::TestResultsCollectorBase* SummaryCollector::Constructor()
94 {
95     return new SummaryCollector();
96 }
97
98 void SummaryCollector::Register()
99 {
100     //register custom results collector
101     DPL::Test::TestResultsCollectorBase::RegisterCollectorConstructor(summaryCollectorName,
102         &SummaryCollector::Constructor);
103 }