fe550bd51113415e538eff03cc3d69da7062fdbe
[platform/core/test/security-tests.git] / src / framework / include / dpl / test / statistic.h
1 /*
2  * Copyright (c) 2014 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  * @file        statistic.h
18  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
20  * @version     1.0
21  * @brief       Header file with implementation of Statistic class
22  */
23
24 #ifndef DPL_TEST_STATISTIC_H
25 #define DPL_TEST_STATISTIC_H
26
27 #include <cstddef>
28
29 #include <dpl/assert.h>
30 #include <dpl/test/test_results_collector.h>
31
32 namespace DPL {
33 namespace Test {
34
35 class Statistic
36 {
37   public:
38     Statistic() :
39         m_failed(0),
40         m_ignored(0),
41         m_passed(0),
42         m_count(0)
43     {}
44
45     void AddTest(TestResultsCollectorBase::FailStatus status)
46     {
47         ++m_count;
48         switch (status) {
49         case TestResultsCollectorBase::FailStatus::FAILED:   ++m_failed;
50             break;
51         case TestResultsCollectorBase::FailStatus::IGNORED:  ++m_ignored;
52             break;
53         case TestResultsCollectorBase::FailStatus::NONE:     ++m_passed;
54             break;
55         default:
56             Assert(false && "Bad FailStatus");
57         }
58     }
59
60     std::size_t GetTotal() const
61     {
62         return m_count;
63     }
64     std::size_t GetPassed() const
65     {
66         return m_passed;
67     }
68     std::size_t GetSuccesed() const
69     {
70         return m_passed;
71     }
72     std::size_t GetFailed() const
73     {
74         return m_failed;
75     }
76     std::size_t GetIgnored() const
77     {
78         return m_ignored;
79     }
80     float GetPassedOrIgnoredPercend() const
81     {
82         float passIgnoredPercent =
83             100.0f * (static_cast<float>(m_passed)
84                       + static_cast<float>(m_ignored))
85             / static_cast<float>(m_count);
86         return passIgnoredPercent;
87     }
88
89   private:
90     std::size_t m_failed;
91     std::size_t m_ignored;
92     std::size_t m_passed;
93     std::size_t m_count;
94 };
95
96 } // namespace Test
97 } // namespace DPL
98
99 #endif // DPL_TEST_STATISTIC_H