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..f79aa3a98de56e3e0e835cadd3ff10e811b77e81 |
--- /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() { |
+ statistics::Initialize(); |
+ } |
+ |
+ virtual void TearDown() { |
+ 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::AddReceivedMethodCall("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::AddReceivedMethodCall("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 |
+ // incramented correctly. |
gauravsh
2012/11/12 21:41:58
NIT: incremented
stevenjb
2012/11/12 22:34:40
Done.
|
+ 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 |