diff options
author | hyunho <hhstark.kang@samsung.com> | 2020-10-06 12:17:12 +0900 |
---|---|---|
committer | hyunho <hhstark.kang@samsung.com> | 2020-10-06 12:17:12 +0900 |
commit | 7c436c0ca677065ed34c99e613e7b8fea019dcad (patch) | |
tree | 55ab7b08722b20f71a3e4d2389e79eed83d34818 | |
parent | 6d14b4560bd78fdddf90d6054643c90582db04d4 (diff) | |
download | librua-7c436c0ca677065ed34c99e613e7b8fea019dcad.tar.gz librua-7c436c0ca677065ed34c99e613e7b8fea019dcad.tar.bz2 librua-7c436c0ca677065ed34c99e613e7b8fea019dcad.zip |
Fix memory leak
Change-Id: I93819b930a3ebe430b7849eab1d6cd466a324533
Signed-off-by: hyunho <hhstark.kang@samsung.com>
-rw-r--r-- | tests/unittest/rua_unit_test.cc | 124 |
1 files changed, 63 insertions, 61 deletions
diff --git a/tests/unittest/rua_unit_test.cc b/tests/unittest/rua_unit_test.cc index 87146f8..d8d13b7 100644 --- a/tests/unittest/rua_unit_test.cc +++ b/tests/unittest/rua_unit_test.cc @@ -32,6 +32,60 @@ using ::testing::DoAll; using ::testing::SetArgPointee; using ::testing::Return; +static char** __create_table(void) { + char** table = (char** )calloc(10, sizeof(char*)); + table[0] = strdup("pkgname"); + if (table[0] == nullptr) + goto out; + + table[1] = strdup("apppath"); + if (table[1] == nullptr) + goto out; + + table[2] = strdup("arg"); + if (table[2] == nullptr) + goto out; + + table[3] = strdup("122232"); + if (table[3] == nullptr) + goto out; + + table[4] = strdup("instance_id"); + if (table[4] == nullptr) + goto out; + + table[5] = strdup("instance_name"); + if (table[5] == nullptr) + goto out; + + table[6] = strdup("icon"); + if (table[6] == nullptr) + goto out; + + table[7] = strdup("uri"); + if (table[7] == nullptr) + goto out; + + table[8] = strdup("image"); + if (table[8] == nullptr) + goto out; + + table[9] = strdup("compid"); + if (table[9] == nullptr) + goto out; + + return table; + +out: + for (int i = 0; i < 10; i++) { + if (table[i]) + free(table[i]); + } + + free(table); + return nullptr; +} + class Mocks : public ::testing::NiceMock<AulMock>, public ::testing::NiceMock<GioMock>, public ::testing::NiceMock<SqlMock> {}; @@ -42,10 +96,17 @@ class RuaTest : public TestFixture { virtual ~RuaTest() {} virtual void SetUp() { + table_ = __create_table(); } virtual void TearDown() { + if (table_) { + for (int i = 0; i < 10; i++) + free(table_[i]); + free(table_); + } } + char** table_ = nullptr; }; static void __rua_history_update_cb(char** table, int nrows, int ncols, @@ -110,63 +171,8 @@ TEST_F(RuaTest, rua_unregister_update_cb_N) { EXPECT_NE(ret, 0); } -static char** __create_table(void) { - char** table = (char** )calloc(10, sizeof(char*)); - table[0] = strdup("pkgname"); - if (table[0] == nullptr) - goto out; - - table[1] = strdup("apppath"); - if (table[1] == nullptr) - goto out; - - table[2] = strdup("arg"); - if (table[2] == nullptr) - goto out; - - table[3] = strdup("122232"); - if (table[3] == nullptr) - goto out; - - table[4] = strdup("instance_id"); - if (table[4] == nullptr) - goto out; - - table[5] = strdup("instance_name"); - if (table[5] == nullptr) - goto out; - - table[6] = strdup("icon"); - if (table[6] == nullptr) - goto out; - - table[7] = strdup("uri"); - if (table[7] == nullptr) - goto out; - - table[8] = strdup("image"); - if (table[8] == nullptr) - goto out; - - table[9] = strdup("compid"); - if (table[9] == nullptr) - goto out; - - return table; - -out: - for (int i = 0; i < 10; i++) { - if (table[i]) - free(table[i]); - } - - free(table); - return nullptr; -} - TEST_F(RuaTest, rua_history_get_rec) { - char** table = __create_table(); - ASSERT_TRUE(table != nullptr); + ASSERT_TRUE(table_ != nullptr); EXPECT_CALL(GetMock<SqlMock>(), sqlite3_open_v2(_, _, _, _)).WillOnce(Return(0)); @@ -178,7 +184,7 @@ TEST_F(RuaTest, rua_history_get_rec) { sqlite3_busy_handler(_, _, _)).WillOnce(Return(0)); EXPECT_CALL(GetMock<SqlMock>(), sqlite3_get_table(_, _, _, _, _, _)). - WillOnce(DoAll(SetArgPointee<2>(table), + WillOnce(DoAll(SetArgPointee<2>(table_), SetArgPointee<3>(1), SetArgPointee<4>(0), (Return(0)))); @@ -195,10 +201,6 @@ TEST_F(RuaTest, rua_history_get_rec) { EXPECT_EQ(ret, 0); rua_history_unload_db(&get_table); - - for (int i = 0; i < 10; i++) - free(table[i]); - free(table); } TEST_F(RuaTest, rua_is_latest_app_N) { |