OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
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 "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace dbus { | |
10 | |
11 class DBusStatisticsTest : public testing::Test { | |
12 public: | |
13 DBusStatisticsTest() { | |
14 } | |
15 | |
16 virtual void SetUp() { | |
17 statistics::Initialize(); | |
18 } | |
19 | |
20 virtual void TearDown() { | |
21 statistics::Shutdown(); | |
22 } | |
23 }; | |
24 | |
25 TEST_F(DBusStatisticsTest, TestDBusStats) { | |
26 int sent = 0, received = 0, blocking = 0; | |
27 | |
28 // Add a sent call | |
29 statistics::AddSentMethodCall("service1", "interface1", "method1"); | |
30 ASSERT_TRUE(statistics::testing::GetCalls( | |
31 "service1", "interface1", "method1", &sent, &received, &blocking)); | |
32 ASSERT_EQ(1, sent); | |
33 ASSERT_EQ(0, received); | |
34 ASSERT_EQ(0, blocking); | |
35 | |
36 // Add a received call | |
37 statistics::AddReceivedMethodCall("service1", "interface1", "method1"); | |
38 ASSERT_TRUE(statistics::testing::GetCalls( | |
39 "service1", "interface1", "method1", &sent, &received, &blocking)); | |
40 ASSERT_EQ(1, sent); | |
41 ASSERT_EQ(1, received); | |
42 ASSERT_EQ(0, blocking); | |
43 | |
44 // Add a blocking call | |
45 statistics::AddBlockingSentMethodCall("service1", "interface1", "method1"); | |
46 ASSERT_TRUE(statistics::testing::GetCalls( | |
47 "service1", "interface1", "method1", &sent, &received, &blocking)); | |
48 ASSERT_EQ(1, sent); | |
49 ASSERT_EQ(1, received); | |
50 ASSERT_EQ(1, blocking); | |
51 | |
52 // Add some more stats to exercise accessing multiple different stats. | |
53 statistics::AddSentMethodCall("service1", "interface1", "method2"); | |
54 statistics::AddSentMethodCall("service1", "interface1", "method2"); | |
55 statistics::AddReceivedMethodCall("service1", "interface1", "method2"); | |
56 | |
57 statistics::AddSentMethodCall("service1", "interface1", "method3"); | |
58 statistics::AddSentMethodCall("service1", "interface1", "method3"); | |
59 statistics::AddSentMethodCall("service1", "interface1", "method3"); | |
60 | |
61 statistics::AddSentMethodCall("service1", "interface2", "method1"); | |
62 | |
63 statistics::AddSentMethodCall("service1", "interface2", "method2"); | |
64 | |
65 statistics::AddSentMethodCall("service2", "interface1", "method1"); | |
66 | |
67 // Make sure all entries can be found in the set and their counts were | |
68 // incramented correctly. | |
gauravsh
2012/11/12 21:41:58
NIT: incremented
stevenjb
2012/11/12 22:34:40
Done.
| |
69 ASSERT_TRUE(statistics::testing::GetCalls( | |
70 "service1", "interface1", "method1", &sent, &received, &blocking)); | |
71 ASSERT_EQ(1, sent); | |
72 ASSERT_EQ(1, received); | |
73 ASSERT_TRUE(statistics::testing::GetCalls( | |
74 "service1", "interface1", "method2", &sent, &received, &blocking)); | |
75 ASSERT_EQ(2, sent); | |
76 ASSERT_EQ(1, received); | |
77 ASSERT_TRUE(statistics::testing::GetCalls( | |
78 "service1", "interface1", "method3", &sent, &received, &blocking)); | |
79 ASSERT_EQ(3, sent); | |
80 ASSERT_EQ(0, received); | |
81 ASSERT_TRUE(statistics::testing::GetCalls( | |
82 "service1", "interface2", "method1", &sent, &received, &blocking)); | |
83 ASSERT_EQ(1, sent); | |
84 ASSERT_EQ(0, received); | |
85 ASSERT_TRUE(statistics::testing::GetCalls( | |
86 "service1", "interface2", "method2", &sent, &received, &blocking)); | |
87 ASSERT_EQ(1, sent); | |
88 ASSERT_EQ(0, received); | |
89 ASSERT_TRUE(statistics::testing::GetCalls( | |
90 "service2", "interface1", "method1", &sent, &received, &blocking)); | |
91 ASSERT_EQ(1, sent); | |
92 ASSERT_EQ(0, received); | |
93 | |
94 ASSERT_FALSE(statistics::testing::GetCalls( | |
95 "service1", "interface3", "method2", &sent, &received, &blocking)); | |
96 } | |
97 | |
98 } // namespace dbus | |
OLD | NEW |