Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: dbus/dbus_statistics_unittest.cc

Issue 11363173: Add DBusStatistics and DBusLogSource to log and show dbus stats (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 DbusStatistics::Initialize();
18 }
19
20 virtual void TearDown() {
21 DbusStatistics::Shutdown();
22 }
23 };
24
25 TEST_F(DbusStatisticsTest, TestDbusStats) {
26 int sent = 0, received = 0;
27
28 // Add a sent call
29 DbusStatistics::AddSentCall("service1", "interface1", "method1");
30 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
31 "service1", "interface1", "method1", &sent, &received));
32 ASSERT_EQ(1, sent);
33 ASSERT_EQ(0, received);
34
35 // Add a received call
36 DbusStatistics::AddReceivedCall("service1", "interface1", "method1");
37 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
38 "service1", "interface1", "method1", &sent, &received));
39 ASSERT_EQ(1, sent);
40 ASSERT_EQ(1, received);
41
42 // Add some more stats
43 DbusStatistics::AddSentCall("service1", "interface1", "method2");
44 DbusStatistics::AddSentCall("service1", "interface1", "method2");
45 DbusStatistics::AddReceivedCall("service1", "interface1", "method2");
46
47 DbusStatistics::AddSentCall("service1", "interface1", "method3");
48 DbusStatistics::AddSentCall("service1", "interface1", "method3");
49 DbusStatistics::AddSentCall("service1", "interface1", "method3");
50
51 DbusStatistics::AddSentCall("service1", "interface2", "method1");
52
53 DbusStatistics::AddSentCall("service1", "interface2", "method2");
54
55 DbusStatistics::AddSentCall("service2", "interface1", "method1");
56
57 // Make sure all entries can be found in the set and their counts were
58 // incramented correctly.
59 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
60 "service1", "interface1", "method1", &sent, &received));
61 ASSERT_EQ(1, sent);
62 ASSERT_EQ(1, received);
63 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
64 "service1", "interface1", "method2", &sent, &received));
65 ASSERT_EQ(2, sent);
66 ASSERT_EQ(1, received);
67 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
68 "service1", "interface1", "method3", &sent, &received));
69 ASSERT_EQ(3, sent);
70 ASSERT_EQ(0, received);
71 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
72 "service1", "interface2", "method1", &sent, &received));
73 ASSERT_EQ(1, sent);
74 ASSERT_EQ(0, received);
75 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
76 "service1", "interface2", "method2", &sent, &received));
77 ASSERT_EQ(1, sent);
78 ASSERT_EQ(0, received);
79 ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
80 "service2", "interface1", "method1", &sent, &received));
81 ASSERT_EQ(1, sent);
82 ASSERT_EQ(0, received);
83
84 ASSERT_FALSE(DbusStatistics::GetCallsForTesting(
85 "service1", "interface3", "method2", &sent, &received));
86 }
satorux1 2012/11/12 00:40:43 Add a test for GetAsString()? Having a test for th
stevenjb 2012/11/12 19:46:40 I think that this would be more likely to cause br
gauravsh 2012/11/12 21:41:58 Surely, if one was changing the GetAsString method
87
88 } // namespace dbus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698