From af389692c0a687675c74fd432e3a2309337ad3c9 Mon Sep 17 00:00:00 2001 From: "Enrico Loparco (eloparco)" Date: Thu, 24 Jun 2021 17:04:19 +0200 Subject: [HICN-712] Fix listener table retrieval Signed-off-by: Enrico Loparco (eloparco) Change-Id: I8cd7c37a570011c2215255fab5e020291dfd0ef7 --- .../src/hicn/core/test/test-listener_table.cc | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'hicn-light/src/hicn/core/test/test-listener_table.cc') diff --git a/hicn-light/src/hicn/core/test/test-listener_table.cc b/hicn-light/src/hicn/core/test/test-listener_table.cc index 89bc3357f..34db546fc 100644 --- a/hicn-light/src/hicn/core/test/test-listener_table.cc +++ b/hicn-light/src/hicn/core/test/test-listener_table.cc @@ -14,6 +14,7 @@ */ #include +#include #include #include @@ -29,6 +30,7 @@ extern "C" { } #define LISTENER_NAME "listener_name_test" +#define LISTENER_NAME_2 "listener_name_test_2" class ListenerTableTest : public ::testing::Test { protected: @@ -142,6 +144,48 @@ TEST_F(ListenerTableTest, RemoveListener) EXPECT_EQ(listener_not_found, nullptr); } +TEST_F(ListenerTableTest, PrintTable) +{ + listener_table_allocate(listener_table, listener, &key, LISTENER_NAME); + + listener_t *listener_2; + listener_key_t key_2 = { + .address = _ADDRESS4_LOCALHOST(2), + .type = FACE_TYPE_TCP + }; + listener_table_allocate(listener_table, listener_2, &key_2, LISTENER_NAME_2); + + testing::internal::CaptureStdout(); + listener_table_print(listener_table); + std::string std_out = testing::internal::GetCapturedStdout(); + + ASSERT_NE(std_out, ""); + EXPECT_THAT(std_out, testing::HasSubstr(LISTENER_NAME)); + EXPECT_THAT(std_out, testing::HasSubstr(LISTENER_NAME_2)); +} + +TEST_F(ListenerTableTest, AddMultipleListeners) +{ + listener_table_allocate(listener_table, listener, &key, LISTENER_NAME); + + listener_t *listener_2; + listener_key_t key_2 = { + .address = _ADDRESS4_LOCALHOST(2), + .type = FACE_TYPE_TCP + }; + listener_table_allocate(listener_table, listener_2, &key_2, "listener_name_test_2"); + + // Check listener table size + size_t listener_table_size = listener_table_len(listener_table); + EXPECT_EQ(listener_table_size, (size_t) 2); + + listener_t *l1 = listener_table_get_by_name(listener_table, LISTENER_NAME); + ASSERT_NE(l1, nullptr); + listener_t *l2 = listener_table_get_by_name(listener_table, LISTENER_NAME_2); + ASSERT_NE(l2, nullptr); + EXPECT_NE(l1, l2); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); -- cgit 1.2.3-korg