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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: dbus/dbus_statistics_unittest.cc
diff --git a/dbus/dbus_statistics_unittest.cc b/dbus/dbus_statistics_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..809e688a98062c7c65374bfafeff46bbbb766917
--- /dev/null
+++ b/dbus/dbus_statistics_unittest.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "dbus/dbus_statistics.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace dbus {
+
+class DbusStatisticsTest : public testing::Test {
+ public:
+ DbusStatisticsTest() {
+ }
+
+ virtual void SetUp() {
+ DbusStatistics::Initialize();
+ }
+
+ virtual void TearDown() {
+ DbusStatistics::Shutdown();
+ }
+};
+
+TEST_F(DbusStatisticsTest, TestDbusStats) {
+ int sent = 0, received = 0;
+
+ // Add a sent call
+ DbusStatistics::AddSentCall("service1", "interface1", "method1");
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface1", "method1", &sent, &received));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+
+ // Add a received call
+ DbusStatistics::AddReceivedCall("service1", "interface1", "method1");
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface1", "method1", &sent, &received));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(1, received);
+
+ // Add some more stats
+ DbusStatistics::AddSentCall("service1", "interface1", "method2");
+ DbusStatistics::AddSentCall("service1", "interface1", "method2");
+ DbusStatistics::AddReceivedCall("service1", "interface1", "method2");
+
+ DbusStatistics::AddSentCall("service1", "interface1", "method3");
+ DbusStatistics::AddSentCall("service1", "interface1", "method3");
+ DbusStatistics::AddSentCall("service1", "interface1", "method3");
+
+ DbusStatistics::AddSentCall("service1", "interface2", "method1");
+
+ DbusStatistics::AddSentCall("service1", "interface2", "method2");
+
+ DbusStatistics::AddSentCall("service2", "interface1", "method1");
+
+ // Make sure all entries can be found in the set and their counts were
+ // incramented correctly.
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface1", "method1", &sent, &received));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(1, received);
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface1", "method2", &sent, &received));
+ ASSERT_EQ(2, sent);
+ ASSERT_EQ(1, received);
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface1", "method3", &sent, &received));
+ ASSERT_EQ(3, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface2", "method1", &sent, &received));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface2", "method2", &sent, &received));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_TRUE(DbusStatistics::GetCallsForTesting(
+ "service2", "interface1", "method1", &sent, &received));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+
+ ASSERT_FALSE(DbusStatistics::GetCallsForTesting(
+ "service1", "interface3", "method2", &sent, &received));
+}
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
+
+} // namespace dbus

Powered by Google App Engine
This is Rietveld 408576698