Debian Codegraph @

tests/unit/analyzers/breakdown/breakdown.cpp

raw
1 //------------------------------------------------------------------------------
2 // Author: Andrey Kuznetsov
3 // Description: Unit tests
4 // Copyright (c) 2015 EPAM Systems
5 //------------------------------------------------------------------------------
6 /*
7 This file is part of Nfstrace.
8
9 Nfstrace is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, version 2 of the License.
12
13 Nfstrace is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Nfstrace. If not, see <http://www.gnu.org/licenses/>.
20 */
21 //------------------------------------------------------------------------------
22 #include <cstdlib>
23 #include <ctime>
24 #include <iostream>
25
26 #include <gmock/gmock.h>
27 #include <gtest/gtest.h>
28
29 #include "breakdowncounter.h"
30 //------------------------------------------------------------------------------
31 using namespace NST::breakdown;
32
33 using ::testing::Return;
34 using ::testing::AtLeast;
35 using ::testing::_;
36 //------------------------------------------------------------------------------
37 namespace
38 {
39 class BreakdownTest : public ::testing::Test
40 {
41 protected:
42 size_t count;
43 timeval t;
44
45 public:
46 void SetUp()
47 {
48 std::srand(std::time(0)); //use current time as seed for random generator
49 count = std::rand() % 100 + 3;
50 }
51
52 void TearDown()
53 {
54 }
55 };
56 }
57 //------------------------------------------------------------------------------
58 TEST_F(BreakdownTest, count)
59 {
60 BreakdownCounter break_down(count);
61
62 EXPECT_EQ(0U, break_down.get_total_count());
63
64 break_down[1].add(t);
65 break_down[1].add(t);
66 break_down[0].add(t);
67
68 EXPECT_EQ(3U, break_down.get_total_count());
69 }
70 //------------------------------------------------------------------------------