From 446c458e6df2768c1d75fa338e7f1284342a4f30 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 11 Jun 2024 08:13:06 +0900 Subject: [PATCH] Fix wrong unit test The label should be set. Change-Id: Iea2184d716d7a5bb0a8acbbdd3ecc420c6301e89 Signed-off-by: Hwankyu Jhun --- src/rua_info.c | 2 +- tests/unittest/rua_manager_unit_test.cc | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/rua_info.c b/src/rua_info.c index 59fd2bb..f433618 100644 --- a/src/rua_info.c +++ b/src/rua_info.c @@ -858,7 +858,7 @@ static char *__get_label(rua_info_h info) { pkgmgrinfo_appinfo_h app_info; aul_comp_info_h comp_info; - char *label; + char *label = NULL; int ret; if (info->value[RUA_INFO_COMP_INFO]) { diff --git a/tests/unittest/rua_manager_unit_test.cc b/tests/unittest/rua_manager_unit_test.cc index b0428e5..83a1624 100644 --- a/tests/unittest/rua_manager_unit_test.cc +++ b/tests/unittest/rua_manager_unit_test.cc @@ -32,10 +32,11 @@ using ::testing::_; using ::testing::DoAll; using ::testing::SetArgPointee; using ::testing::Return; +using ::testing::Invoke; static bool __rua_info_cb(rua_info_h info, void* user_data) { if (user_data) { - rua_info_h* cloned = (rua_info_h*)user_data; + rua_info_h* cloned = static_cast(user_data); rua_info_clone(info, cloned); } @@ -43,7 +44,7 @@ static bool __rua_info_cb(rua_info_h info, void* user_data) { } static char** __create_table(void) { - char** table = (char** )calloc(10, sizeof(char*)); + char** table = reinterpret_cast(calloc(10, sizeof(char*))); table[0] = strdup("pkgname"); if (table[0] == nullptr) goto out; @@ -397,12 +398,14 @@ TEST_F(RuaManagerTest, rua_info_is_managed_by_task_manager) { } TEST_F(RuaManagerTest, rua_info_get_label) { - EXPECT_CALL(GetMock(), - aul_comp_info_get_label(_, _)). - WillOnce(Return(0)); + EXPECT_CALL(GetMock(), aul_comp_info_get_label(_, _)) + .WillOnce(Invoke([&](aul_comp_info_h info, const char** label) { + *label = strdup("test"); + return 0; + })); - char* label; + char* label = NULL; int ret = rua_info_get_label(info_, &label); auto p = std::unique_ptr(label, std::free); EXPECT_EQ(ret, 0); -} \ No newline at end of file +} -- 2.7.4