aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Langlois <pierre.langlois@arm.com>2015-03-09 16:04:00 +0000
committerPierre Langlois <pierre.langlois@arm.com>2016-03-04 17:48:46 +0000
commit32e5852cde58198945b919cfa35beac7591f2c59 (patch)
tree2ed353d481abaa63dc3cd80acfae8f53c6ce864f
parente795732d50fbdadbf1550bd3e476bb99fd2f9aa3 (diff)
downloadkdbinder-32e5852cde58198945b919cfa35beac7591f2c59.tar.gz
libkdbinder: kdbus: create a bus for each Connection tests
This commit adds a base class for all Connection tests. It takes care of creating a bus and making sure it did not fail to do so. Change-Id: Ieaf889c6c8ff11498a573e3a099e4d026dc33d42
-rw-r--r--libs/kdbinder/tests/kdbus/connection.cpp97
1 files changed, 48 insertions, 49 deletions
diff --git a/libs/kdbinder/tests/kdbus/connection.cpp b/libs/kdbinder/tests/kdbus/connection.cpp
index 5473565..b3e9702 100644
--- a/libs/kdbinder/tests/kdbus/connection.cpp
+++ b/libs/kdbinder/tests/kdbus/connection.cpp
@@ -41,10 +41,21 @@ bool connection_owns_name(Connection& c, const std::string& name) {
return it->owner_id == c.id;
}
-TEST(Connection, hello) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+class ConnectionTest : public testing::Test {
+ public:
+ void SetUp() override {
+ bus_ = Bus::make("test-bus");
+
+ ASSERT_TRUE(bus_->IsAlive());
+ }
+
+ protected:
+ std::unique_ptr<Bus> bus_;
+};
+
+TEST_F(ConnectionTest, hello) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
ASSERT_TRUE(c2 != nullptr);
ASSERT_TRUE(c1->id == 1);
@@ -52,17 +63,15 @@ TEST(Connection, hello) {
ASSERT_TRUE(c2->id == 2);
}
-TEST(Connection, acquire_name) {
- auto b = Bus::make("test-bus");
- auto c = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, acquire_name) {
+ auto c = Connection::hello(*bus_, "test-conn");
ASSERT_TRUE(c->acquire_name("foo.bar.test").error_code == 0);
ASSERT_TRUE(connection_owns_name(*c, "foo.bar.test"));
}
-TEST(Connection, release_name) {
- auto b = Bus::make("test-bus");
- auto c = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, release_name) {
+ auto c = Connection::hello(*bus_, "test-conn");
ASSERT_TRUE(c->acquire_name("foo.bar.test").error_code == 0);
ASSERT_TRUE(c->release_name("foo.bar.test").error_code == 0);
@@ -70,10 +79,9 @@ TEST(Connection, release_name) {
ASSERT_FALSE(connection_owns_name(*c, "foo.bar.test"));
}
-TEST(Connection, acquire_name_deny) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, acquire_name_deny) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
ASSERT_TRUE(c1->acquire_name("foo.bar.test").error_code == 0);
ASSERT_FALSE(c2->acquire_name("foo.bar.test").error_code == 0);
@@ -84,10 +92,9 @@ TEST(Connection, acquire_name_deny) {
ASSERT_TRUE(connection_owns_name(*c2, "foo.bar.test"));
}
-TEST(Connection, acquire_name_replace) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, acquire_name_replace) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
ASSERT_TRUE(c1->acquire_name("foo.bar.test", Connection::AllowReplacement).error_code == 0);
ASSERT_TRUE(c2->acquire_name("foo.bar.test", Connection::ReplaceExisting).error_code == 0);
@@ -106,10 +113,9 @@ TEST(Connection, acquire_name_replace) {
ASSERT_FALSE(connection_owns_name(*c2, "foo.bar.test"));
}
-TEST(Connection, acquire_name_queue) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, acquire_name_queue) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
ASSERT_TRUE(c1->acquire_name("foo.bar.test").error_code == 0);
ASSERT_TRUE(c2->acquire_name("foo.bar.test", Connection::Queue).error_code == 0);
@@ -119,9 +125,8 @@ TEST(Connection, acquire_name_queue) {
ASSERT_TRUE(connection_owns_name(*c2, "foo.bar.test"));
}
-TEST(Connection, name_list_unique) {
- auto b = Bus::make("test-bus");
- auto c = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, name_list_unique) {
+ auto c = Connection::hello(*bus_, "test-conn");
auto list = c->name_list(Connection::Unique);
@@ -129,9 +134,8 @@ TEST(Connection, name_list_unique) {
ASSERT_TRUE(list.front().owner_id == c->id);
}
-TEST(Connection, name_list_names) {
- auto b = Bus::make("test-bus");
- auto c = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, name_list_names) {
+ auto c = Connection::hello(*bus_, "test-conn");
c->acquire_name("foo.bar.test1");
c->acquire_name("foo.bar.test2");
@@ -157,10 +161,9 @@ TEST(Connection, name_list_names) {
}) != list.cend());
}
-TEST(Connection, queue_message) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, queue_message) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
uint8_t data = 42;
Message msg(c2->id, c1->id, 0, 0, ItemPayloadVec(&data, sizeof(uint8_t)));
@@ -168,10 +171,9 @@ TEST(Connection, queue_message) {
ASSERT_TRUE(c1->queue_message(msg).error_code == 0);
}
-TEST(Connection, dequeue_message_blocking) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, dequeue_message_blocking) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
uint8_t data_in = 42;
uint8_t data_out = 0;
@@ -191,10 +193,9 @@ TEST(Connection, dequeue_message_blocking) {
c2->free(reply);
}
-TEST(Connection, source_id) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, source_id) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
uint8_t data_in = 42;
uint8_t data_out = 0;
@@ -218,10 +219,9 @@ TEST(Connection, source_id) {
c2->free(reply);
}
-TEST(Connection, transact) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, transact) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
uint8_t data_in = 42;
uint8_t data_out = 0;
uint64_t cookie = 123456789;
@@ -258,15 +258,14 @@ TEST(Connection, transact) {
c1->free(reply);
}
-TEST(Connection, remove_notification) {
- auto b = Bus::make("test-bus");
- auto c1 = Connection::hello(*b, "test-conn");
- auto c2 = Connection::hello(*b, "test-conn");
+TEST_F(ConnectionTest, remove_notification) {
+ auto c1 = Connection::hello(*bus_, "test-conn");
+ auto c2 = Connection::hello(*bus_, "test-conn");
uint64_t c2_id = c2->id;
c1->notify_when_dead(*c2);
- std::thread([&b, &c2]{
+ std::thread([&c2]{
auto c = std::move(c2);
// c2's destructor is called.
}).join();