This source file includes following definitions.
- SetUp
- TearDown
- AddTestMethodCalls
- TEST_F
- TEST_F
- TEST_F
#include "dbus/dbus_statistics.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace dbus {
class DBusStatisticsTest : public testing::Test {
public:
DBusStatisticsTest() {
}
virtual void SetUp() OVERRIDE {
statistics::Initialize();
}
virtual void TearDown() OVERRIDE {
statistics::Shutdown();
}
protected:
void AddTestMethodCalls() {
statistics::AddSentMethodCall(
"service1", "service1.interface1", "method1");
statistics::AddReceivedSignal(
"service1", "service1.interface1", "method1");
statistics::AddBlockingSentMethodCall(
"service1", "service1.interface1", "method1");
statistics::AddSentMethodCall(
"service1", "service1.interface1", "method2");
statistics::AddSentMethodCall(
"service1", "service1.interface1", "method2");
statistics::AddReceivedSignal(
"service1", "service1.interface1", "method2");
statistics::AddSentMethodCall(
"service1", "service1.interface1", "method3");
statistics::AddSentMethodCall(
"service1", "service1.interface1", "method3");
statistics::AddSentMethodCall(
"service1", "service1.interface1", "method3");
statistics::AddSentMethodCall(
"service1", "service1.interface2", "method1");
statistics::AddSentMethodCall(
"service1", "service1.interface2", "method2");
statistics::AddSentMethodCall(
"service2", "service2.interface1", "method1");
}
private:
DISALLOW_COPY_AND_ASSIGN(DBusStatisticsTest);
};
TEST_F(DBusStatisticsTest, TestDBusStatsBasic) {
int sent = 0, received = 0, block = 0;
statistics::AddSentMethodCall("service1", "service1.interface1", "method1");
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface1", "method1", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(0, received);
EXPECT_EQ(0, block);
statistics::AddReceivedSignal("service1", "service1.interface1", "method1");
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface1", "method1", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(1, received);
EXPECT_EQ(0, block);
statistics::AddBlockingSentMethodCall(
"service1", "service1.interface1", "method1");
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface1", "method1", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(1, received);
EXPECT_EQ(1, block);
}
TEST_F(DBusStatisticsTest, TestDBusStatsMulti) {
int sent = 0, received = 0, block = 0;
AddTestMethodCalls();
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface1", "method1", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(1, received);
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface1", "method2", &sent, &received, &block));
EXPECT_EQ(2, sent);
EXPECT_EQ(1, received);
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface1", "method3", &sent, &received, &block));
EXPECT_EQ(3, sent);
EXPECT_EQ(0, received);
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface2", "method1", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(0, received);
ASSERT_TRUE(statistics::testing::GetCalls(
"service1", "service1.interface2", "method2", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(0, received);
ASSERT_TRUE(statistics::testing::GetCalls(
"service2", "service2.interface1", "method1", &sent, &received, &block));
EXPECT_EQ(1, sent);
EXPECT_EQ(0, received);
ASSERT_FALSE(statistics::testing::GetCalls(
"service1", "service1.interface3", "method2", &sent, &received, &block));
}
TEST_F(DBusStatisticsTest, TestGetAsString) {
std::string output_none = GetAsString(statistics::SHOW_SERVICE,
statistics::FORMAT_TOTALS);
EXPECT_EQ("No DBus calls.", output_none);
AddTestMethodCalls();
std::string output_service = GetAsString(statistics::SHOW_SERVICE,
statistics::FORMAT_TOTALS);
const std::string expected_output_service(
"service1: Sent (BLOCKING): 1 Sent: 8 Received: 2\n"
"service2: Sent: 1\n");
EXPECT_EQ(expected_output_service, output_service);
std::string output_interface = GetAsString(statistics::SHOW_INTERFACE,
statistics::FORMAT_TOTALS);
const std::string expected_output_interface(
"service1.interface1: Sent (BLOCKING): 1 Sent: 6 Received: 2\n"
"service1.interface2: Sent: 2\n"
"service2.interface1: Sent: 1\n");
EXPECT_EQ(expected_output_interface, output_interface);
std::string output_per_minute = GetAsString(statistics::SHOW_INTERFACE,
statistics::FORMAT_PER_MINUTE);
const std::string expected_output_per_minute(
"service1.interface1: Sent (BLOCKING): 1/min Sent: 6/min"
" Received: 2/min\n"
"service1.interface2: Sent: 2/min\n"
"service2.interface1: Sent: 1/min\n");
EXPECT_EQ(expected_output_per_minute, output_per_minute);
std::string output_all = GetAsString(statistics::SHOW_INTERFACE,
statistics::FORMAT_ALL);
const std::string expected_output_all(
"service1.interface1: Sent (BLOCKING): 1 (1/min) Sent: 6 (6/min)"
" Received: 2 (2/min)\n"
"service1.interface2: Sent: 2 (2/min)\n"
"service2.interface1: Sent: 1 (1/min)\n");
EXPECT_EQ(expected_output_all, output_all);
std::string output_method = GetAsString(statistics::SHOW_METHOD,
statistics::FORMAT_TOTALS);
const std::string expected_output_method(
"service1.interface1.method1: Sent (BLOCKING): 1 Sent: 1 Received: 1\n"
"service1.interface1.method2: Sent: 2 Received: 1\n"
"service1.interface1.method3: Sent: 3\n"
"service1.interface2.method1: Sent: 1\n"
"service1.interface2.method2: Sent: 1\n"
"service2.interface1.method1: Sent: 1\n");
EXPECT_EQ(expected_output_method, output_method);
}
}