Chromium Code Reviews| 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 |