[M120 Migration][VD] Fix url crash in RequestCertificateConfirm
[platform/framework/web/chromium-efl.git] / dbus / dbus_statistics_unittest.cc
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "dbus/dbus_statistics.h"
6
7 #include "base/compiler_specific.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace dbus {
11
12 class DBusStatisticsTest : public testing::Test {
13  public:
14   DBusStatisticsTest() = default;
15
16   DBusStatisticsTest(const DBusStatisticsTest&) = delete;
17   DBusStatisticsTest& operator=(const DBusStatisticsTest&) = delete;
18
19   void SetUp() override { statistics::Initialize(); }
20
21   void TearDown() override { statistics::Shutdown(); }
22
23  protected:
24   void AddTestMethodCalls() {
25     statistics::AddSentMethodCall(
26         "service1", "service1.interface1", "method1");
27     statistics::AddReceivedSignal(
28         "service1", "service1.interface1", "method1");
29     statistics::AddBlockingSentMethodCall(
30         "service1", "service1.interface1", "method1");
31
32     statistics::AddSentMethodCall(
33         "service1", "service1.interface1", "method2");
34     statistics::AddSentMethodCall(
35         "service1", "service1.interface1", "method2");
36     statistics::AddReceivedSignal(
37         "service1", "service1.interface1", "method2");
38
39     statistics::AddSentMethodCall(
40         "service1", "service1.interface1", "method3");
41     statistics::AddSentMethodCall(
42         "service1", "service1.interface1", "method3");
43     statistics::AddSentMethodCall(
44         "service1", "service1.interface1", "method3");
45
46     statistics::AddSentMethodCall(
47         "service1", "service1.interface2", "method1");
48
49     statistics::AddSentMethodCall(
50         "service1", "service1.interface2", "method2");
51
52     statistics::AddSentMethodCall(
53         "service2", "service2.interface1", "method1");
54   }
55 };
56
57 TEST_F(DBusStatisticsTest, TestDBusStatsBasic) {
58   int sent = 0, received = 0, block = 0;
59
60   // Add a sent call
61   statistics::AddSentMethodCall("service1", "service1.interface1", "method1");
62   ASSERT_TRUE(statistics::testing::GetCalls(
63       "service1", "service1.interface1", "method1", &sent, &received, &block));
64   EXPECT_EQ(1, sent);
65   EXPECT_EQ(0, received);
66   EXPECT_EQ(0, block);
67
68   // Add a received call
69   statistics::AddReceivedSignal("service1", "service1.interface1", "method1");
70   ASSERT_TRUE(statistics::testing::GetCalls(
71       "service1", "service1.interface1", "method1", &sent, &received, &block));
72   EXPECT_EQ(1, sent);
73   EXPECT_EQ(1, received);
74   EXPECT_EQ(0, block);
75
76   // Add a block call
77   statistics::AddBlockingSentMethodCall(
78       "service1", "service1.interface1", "method1");
79   ASSERT_TRUE(statistics::testing::GetCalls(
80       "service1", "service1.interface1", "method1", &sent, &received, &block));
81   EXPECT_EQ(1, sent);
82   EXPECT_EQ(1, received);
83   EXPECT_EQ(1, block);
84 }
85
86 TEST_F(DBusStatisticsTest, TestDBusStatsMulti) {
87   int sent = 0, received = 0, block = 0;
88
89   // Add some more stats to exercise accessing multiple different stats.
90   AddTestMethodCalls();
91
92   // Make sure all entries can be found in the set and their counts were
93   // incremented correctly.
94   ASSERT_TRUE(statistics::testing::GetCalls(
95       "service1", "service1.interface1", "method1", &sent, &received, &block));
96   EXPECT_EQ(1, sent);
97   EXPECT_EQ(1, received);
98   ASSERT_TRUE(statistics::testing::GetCalls(
99       "service1", "service1.interface1", "method2", &sent, &received, &block));
100   EXPECT_EQ(2, sent);
101   EXPECT_EQ(1, received);
102   ASSERT_TRUE(statistics::testing::GetCalls(
103       "service1", "service1.interface1", "method3", &sent, &received, &block));
104   EXPECT_EQ(3, sent);
105   EXPECT_EQ(0, received);
106   ASSERT_TRUE(statistics::testing::GetCalls(
107       "service1", "service1.interface2", "method1", &sent, &received, &block));
108   EXPECT_EQ(1, sent);
109   EXPECT_EQ(0, received);
110   ASSERT_TRUE(statistics::testing::GetCalls(
111       "service1", "service1.interface2", "method2", &sent, &received, &block));
112   EXPECT_EQ(1, sent);
113   EXPECT_EQ(0, received);
114   ASSERT_TRUE(statistics::testing::GetCalls(
115       "service2", "service2.interface1", "method1", &sent, &received, &block));
116   EXPECT_EQ(1, sent);
117   EXPECT_EQ(0, received);
118
119   ASSERT_FALSE(statistics::testing::GetCalls(
120       "service1", "service1.interface3", "method2", &sent, &received, &block));
121 }
122
123 TEST_F(DBusStatisticsTest, TestGetAsString) {
124   std::string output_none = GetAsString(statistics::SHOW_SERVICE,
125                                         statistics::FORMAT_TOTALS);
126   EXPECT_EQ("No DBus calls.", output_none);
127
128   AddTestMethodCalls();
129
130   std::string output_service = GetAsString(statistics::SHOW_SERVICE,
131                                            statistics::FORMAT_TOTALS);
132   const std::string expected_output_service(
133       "service1: Sent (BLOCKING): 1 Sent: 8 Received: 2\n"
134       "service2: Sent: 1\n");
135   EXPECT_EQ(expected_output_service, output_service);
136
137   std::string output_interface = GetAsString(statistics::SHOW_INTERFACE,
138                                              statistics::FORMAT_TOTALS);
139   const std::string expected_output_interface(
140       "service1.interface1: Sent (BLOCKING): 1 Sent: 6 Received: 2\n"
141       "service1.interface2: Sent: 2\n"
142       "service2.interface1: Sent: 1\n");
143   EXPECT_EQ(expected_output_interface, output_interface);
144
145   std::string output_per_minute = GetAsString(statistics::SHOW_INTERFACE,
146                                               statistics::FORMAT_PER_MINUTE);
147   const std::string expected_output_per_minute(
148       "service1.interface1: Sent (BLOCKING): 1/min Sent: 6/min"
149       " Received: 2/min\n"
150       "service1.interface2: Sent: 2/min\n"
151       "service2.interface1: Sent: 1/min\n");
152   EXPECT_EQ(expected_output_per_minute, output_per_minute);
153
154   std::string output_all = GetAsString(statistics::SHOW_INTERFACE,
155                                        statistics::FORMAT_ALL);
156   const std::string expected_output_all(
157       "service1.interface1: Sent (BLOCKING): 1 (1/min) Sent: 6 (6/min)"
158       " Received: 2 (2/min)\n"
159       "service1.interface2: Sent: 2 (2/min)\n"
160       "service2.interface1: Sent: 1 (1/min)\n");
161   EXPECT_EQ(expected_output_all, output_all);
162
163
164   std::string output_method = GetAsString(statistics::SHOW_METHOD,
165                                           statistics::FORMAT_TOTALS);
166   const std::string expected_output_method(
167       "service1.interface1.method1: Sent (BLOCKING): 1 Sent: 1 Received: 1\n"
168       "service1.interface1.method2: Sent: 2 Received: 1\n"
169       "service1.interface1.method3: Sent: 3\n"
170       "service1.interface2.method1: Sent: 1\n"
171       "service1.interface2.method2: Sent: 1\n"
172       "service2.interface1.method1: Sent: 1\n");
173   EXPECT_EQ(expected_output_method, output_method);
174
175 }
176
177 }  // namespace dbus