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

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: Rebase 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..b8a2ddb23f4d0a1f979fbe0eea953a349d203068
--- /dev/null
+++ b/dbus/dbus_statistics_unittest.cc
@@ -0,0 +1,98 @@
+// 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() {
hashimoto 2012/11/13 06:11:44 nit: OVERRIDE
stevenjb 2012/11/13 19:54:15 Done.
+ statistics::Initialize();
+ }
+
+ virtual void TearDown() {
hashimoto 2012/11/13 06:11:44 nit: OVERRIDE
stevenjb 2012/11/13 19:54:15 Done.
+ statistics::Shutdown();
+ }
+};
+
+TEST_F(DBusStatisticsTest, TestDBusStats) {
+ int sent = 0, received = 0, blocking = 0;
+
+ // Add a sent call
+ statistics::AddSentMethodCall("service1", "interface1", "method1");
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface1", "method1", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_EQ(0, blocking);
+
+ // Add a received call
+ statistics::AddReceivedSignal("service1", "interface1", "method1");
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface1", "method1", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(1, received);
+ ASSERT_EQ(0, blocking);
+
+ // Add a blocking call
+ statistics::AddBlockingSentMethodCall("service1", "interface1", "method1");
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface1", "method1", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(1, received);
+ ASSERT_EQ(1, blocking);
+
+ // Add some more stats to exercise accessing multiple different stats.
+ statistics::AddSentMethodCall("service1", "interface1", "method2");
+ statistics::AddSentMethodCall("service1", "interface1", "method2");
+ statistics::AddReceivedSignal("service1", "interface1", "method2");
+
+ statistics::AddSentMethodCall("service1", "interface1", "method3");
+ statistics::AddSentMethodCall("service1", "interface1", "method3");
+ statistics::AddSentMethodCall("service1", "interface1", "method3");
+
+ statistics::AddSentMethodCall("service1", "interface2", "method1");
+
+ statistics::AddSentMethodCall("service1", "interface2", "method2");
+
+ statistics::AddSentMethodCall("service2", "interface1", "method1");
+
+ // Make sure all entries can be found in the set and their counts were
+ // incremented correctly.
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface1", "method1", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(1, received);
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface1", "method2", &sent, &received, &blocking));
+ ASSERT_EQ(2, sent);
+ ASSERT_EQ(1, received);
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface1", "method3", &sent, &received, &blocking));
+ ASSERT_EQ(3, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface2", "method1", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service1", "interface2", "method2", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+ ASSERT_TRUE(statistics::testing::GetCalls(
+ "service2", "interface1", "method1", &sent, &received, &blocking));
+ ASSERT_EQ(1, sent);
+ ASSERT_EQ(0, received);
+
+ ASSERT_FALSE(statistics::testing::GetCalls(
+ "service1", "interface3", "method2", &sent, &received, &blocking));
+}
+
+} // namespace dbus
« dbus/dbus_statistics.cc ('K') | « dbus/dbus_statistics.cc ('k') | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698