From 8c6480131e1cf29e4ac0bae791918291e0559d41 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 28 Aug 2020 15:26:39 +0900 Subject: [PATCH] Improve coverages Add unittest for rua_internal, rua_stat Change-Id: I152be6cef37eba4ea138440d583942f03570143b Signed-off-by: Inkyun Kil --- tests/mock/sqlite3_mock.cc | 17 ++ tests/mock/sqlite3_mock.h | 5 + tests/unittest/rua_internal_unit_test.cc | 361 +++++++++++++++++++++++++++++++ tests/unittest/rua_manager_unit_test.cc | 30 +-- tests/unittest/rua_stat_unit_test.cc | 112 ++++++++++ tests/unittest/rua_unit_test.cc | 40 ++-- 6 files changed, 520 insertions(+), 45 deletions(-) create mode 100644 tests/unittest/rua_internal_unit_test.cc create mode 100644 tests/unittest/rua_stat_unit_test.cc diff --git a/tests/mock/sqlite3_mock.cc b/tests/mock/sqlite3_mock.cc index 83629a0..fd9e19e 100644 --- a/tests/mock/sqlite3_mock.cc +++ b/tests/mock/sqlite3_mock.cc @@ -31,6 +31,10 @@ extern "C" int sqlite3_close_v2(sqlite3* arg0) { return MOCK_HOOK_P1(SqlMock, sqlite3_close_v2, arg0); } +extern "C" int sqlite3_changes(sqlite3* arg0) { + return MOCK_HOOK_P1(SqlMock, sqlite3_changes, arg0); +} + extern "C" void sqlite3_free_table(char** arg0) { return MOCK_HOOK_P1(SqlMock, sqlite3_free_table, arg0); } @@ -50,6 +54,11 @@ extern "C" int sqlite3_exec(sqlite3* arg0, const char* arg1, return MOCK_HOOK_P5(SqlMock, sqlite3_exec, arg0, arg1, arg2, arg3, arg4); } +extern "C" int sqlite3_prepare(sqlite3* arg0, const char* arg1, + int arg2, sqlite3_stmt** arg3, const char** arg4) { + return MOCK_HOOK_P5(SqlMock, sqlite3_prepare, arg0, arg1, arg2, arg3, arg4); +} + extern "C" int sqlite3_prepare_v2(sqlite3* arg0, const char* arg1, int arg2, sqlite3_stmt** arg3, const char** arg4) { return MOCK_HOOK_P5(SqlMock, sqlite3_prepare_v2, arg0, arg1, arg2, arg3, arg4); @@ -64,10 +73,18 @@ extern "C" int sqlite3_bind_int(sqlite3_stmt* arg0, int arg1, int arg2) { return MOCK_HOOK_P3(SqlMock, sqlite3_bind_int, arg0, arg1, arg2); } +extern "C" int sqlite3_bind_double(sqlite3_stmt* arg0, int arg1, double arg2) { + return MOCK_HOOK_P3(SqlMock, sqlite3_bind_double, arg0, arg1, arg2); +} + extern "C" int sqlite3_step(sqlite3_stmt* arg0) { return MOCK_HOOK_P1(SqlMock, sqlite3_step, arg0); } +extern "C" const unsigned char* sqlite3_column_text(sqlite3_stmt* arg0, int arg1) { + return MOCK_HOOK_P2(SqlMock, sqlite3_column_text, arg0, arg1); +} + extern "C" int sqlite3_finalize(sqlite3_stmt* arg0) { return MOCK_HOOK_P1(SqlMock, sqlite3_finalize, arg0); } \ No newline at end of file diff --git a/tests/mock/sqlite3_mock.h b/tests/mock/sqlite3_mock.h index ab62a24..1177f1b 100644 --- a/tests/mock/sqlite3_mock.h +++ b/tests/mock/sqlite3_mock.h @@ -28,18 +28,23 @@ class SqlMock : public virtual ModuleMock { MOCK_METHOD1(sqlite3_free_table, void(char**)); MOCK_METHOD1(sqlite3_close_v2, int(sqlite3*)); + MOCK_METHOD1(sqlite3_changes, int(sqlite3*)); MOCK_METHOD3(sqlite3_busy_handler, int(sqlite3*, int(*)(void*, int), void*)); MOCK_METHOD4(sqlite3_open_v2, int(const char*, sqlite3**, int, const char*)); MOCK_METHOD6(sqlite3_get_table, int (sqlite3*, const char*, char***, int*, int*, char**)); MOCK_METHOD5(sqlite3_exec, int(sqlite3*, const char*, int(*)(void*, int, char**, char**), void*, char**)); + MOCK_METHOD5(sqlite3_prepare, int(sqlite3*, const char*, + int, sqlite3_stmt**, const char**)); MOCK_METHOD5(sqlite3_prepare_v2, int(sqlite3*, const char*, int, sqlite3_stmt**, const char**)); MOCK_METHOD5(sqlite3_bind_text, int(sqlite3_stmt*, int, const char*, int, void(*)(void*))); MOCK_METHOD3(sqlite3_bind_int, int(sqlite3_stmt*, int, int)); + MOCK_METHOD3(sqlite3_bind_double, int(sqlite3_stmt*, int, double)); MOCK_METHOD1(sqlite3_step, int(sqlite3_stmt*)); + MOCK_METHOD2(sqlite3_column_text, const unsigned char*(sqlite3_stmt*, int)); MOCK_METHOD1(sqlite3_finalize, int(sqlite3_stmt*)); }; diff --git a/tests/unittest/rua_internal_unit_test.cc b/tests/unittest/rua_internal_unit_test.cc new file mode 100644 index 0000000..01b5e0a --- /dev/null +++ b/tests/unittest/rua_internal_unit_test.cc @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include + +#include "aul_mock.h" +#include "sqlite3_mock.h" +#include "gio_mock.h" +#include "test_fixture.h" + +using ::testing::_; +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]); + } + + return nullptr; +} + +class InternalMocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; + +class RuaInternalTest : public TestFixture { + public: + RuaInternalTest() : TestFixture(std::make_unique()) {} + virtual ~RuaInternalTest() {} + + virtual void SetUp() { + table_ = __create_table(); + if (table_ == nullptr) + return; + } + + virtual void TearDown() { + if (table_) { + for (int i = 0; i < 10; i++) + free(table_[i]); + free(table_); + } + } + + public: + char** table_ = nullptr; +}; + +TEST_F(RuaInternalTest, rua_db_add_history) { + ASSERT_TRUE(table_ != nullptr); + sqlite3* db = (sqlite3*) table_; + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_free_table(_)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_get_table(_, _, _, _, _, _)). + WillOnce(DoAll(SetArgPointee<2>(table_), + SetArgPointee<3>(1), + SetArgPointee<4>(0), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_int(_, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock(), + g_dbus_connection_flush_sync(_, _, _)). + WillOnce(Return(true)); + + char** get_table = nullptr; + int rows = 0; + int cols = 0; + struct rua_rec record; + int ret = rua_history_load_db(&get_table, &rows, &cols); + EXPECT_EQ(ret, 0); + EXPECT_TRUE(get_table != nullptr); + + ret = rua_history_get_rec(&record, get_table, rows, cols, 0); + EXPECT_EQ(ret, 0); + + ret = rua_db_add_history(&record); + EXPECT_EQ(ret, 0); + + ret = rua_history_unload_db(&get_table); + EXPECT_EQ(ret, 0); +} + +TEST_F(RuaInternalTest, rua_db_add_history_for_update) { + ASSERT_TRUE(table_ != nullptr); + + free(table_[5]); + table_[5] = nullptr; + sqlite3* db = (sqlite3*) table_; + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_free_table(_)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_get_table(_, _, _, _, _, _)). + WillOnce(DoAll(SetArgPointee<2>(table_), + SetArgPointee<3>(1), + SetArgPointee<4>(0), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_int(_, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock(), + g_dbus_connection_flush_sync(_, _, _)). + WillOnce(Return(true)); + + char** get_table = nullptr; + int rows = 0; + int cols = 0; + struct rua_rec record; + int ret = rua_history_load_db(&get_table, &rows, &cols); + EXPECT_EQ(ret, 0); + EXPECT_TRUE(get_table != nullptr); + + ret = rua_history_get_rec(&record, get_table, rows, cols, 0); + EXPECT_EQ(ret, 0); + + ret = rua_db_add_history(&record); + EXPECT_EQ(ret, 0); + + ret = rua_history_unload_db(&get_table); + EXPECT_EQ(ret, 0); +} + +TEST_F(RuaInternalTest, rua_usr_db_update_image) { + ASSERT_TRUE(table_ != nullptr); + sqlite3* db = (sqlite3*) table_; + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock(), + g_dbus_connection_flush_sync(_, _, _)). + WillOnce(Return(true)); + + int ret = rua_db_update_image("pkg_name", "comp_id", "inst_id", "image"); + EXPECT_EQ(ret, 0); +} + +TEST_F(RuaInternalTest, rua_db_delete_history) { + ASSERT_TRUE(table_ != nullptr); + sqlite3* db = (sqlite3*) table_; + + bundle* b = bundle_create(); + ASSERT_TRUE(b != nullptr); + + if (b) { + bundle_add_str(b, AUL_K_RUA_PKGNAME, "pkgname"); + } + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock(), + g_dbus_connection_flush_sync(_, _, _)). + WillOnce(Return(true)); + + int ret = rua_db_delete_history(b); + EXPECT_EQ(ret, 0); + + if (b) + bundle_free(b); +} + +TEST_F(RuaInternalTest, rua_db_delete_history_apppath) { + ASSERT_TRUE(table_ != nullptr); + sqlite3* db = (sqlite3*) table_; + + bundle* b = bundle_create(); + ASSERT_TRUE(b != nullptr); + + if (b) + bundle_add_str(b, AUL_K_RUA_APPPATH, "apppath"); + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock(), + g_dbus_connection_flush_sync(_, _, _)). + WillOnce(Return(true)); + + int ret = rua_db_delete_history(b); + EXPECT_EQ(ret, 0); + + if (b) + bundle_free(b); +} + +TEST_F(RuaInternalTest, rua_db_delete_history_clear) { + ASSERT_TRUE(table_ != nullptr); + sqlite3* db = (sqlite3*) table_; + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock(), + g_dbus_connection_flush_sync(_, _, _)). + WillOnce(Return(true)); + + int ret = rua_db_delete_history(nullptr); + EXPECT_EQ(ret, 0); +} \ No newline at end of file diff --git a/tests/unittest/rua_manager_unit_test.cc b/tests/unittest/rua_manager_unit_test.cc index cc4289a..f066c8b 100644 --- a/tests/unittest/rua_manager_unit_test.cc +++ b/tests/unittest/rua_manager_unit_test.cc @@ -45,54 +45,44 @@ static bool __rua_info_cb(rua_info_h info, void* user_data) { static char** __create_table(void) { char** table = (char** )calloc(10, sizeof(char*)); table[0] = strdup("pkgname"); - if (table[0] == nullptr) { + if (table[0] == nullptr) goto out; - } table[1] = strdup("apppath"); - if (table[1] == nullptr) { + if (table[1] == nullptr) goto out; - } table[2] = strdup("arg"); - if (table[2] == nullptr) { + if (table[2] == nullptr) goto out; - } table[3] = strdup("122232"); - if (table[3] == nullptr) { + if (table[3] == nullptr) goto out; - } table[4] = strdup("instance_id"); - if (table[4] == nullptr) { + if (table[4] == nullptr) goto out; - } table[5] = strdup("instance_name"); - if (table[5] == nullptr) { + if (table[5] == nullptr) goto out; - } table[6] = strdup("icon"); - if (table[6] == nullptr) { + if (table[6] == nullptr) goto out; - } table[7] = strdup("uri"); - if (table[7] == nullptr) { + if (table[7] == nullptr) goto out; - } table[8] = strdup("image"); - if (table[8] == nullptr) { + if (table[8] == nullptr) goto out; - } table[9] = strdup("compid"); - if (table[9] == nullptr) { + if (table[9] == nullptr) goto out; - } return table; diff --git a/tests/unittest/rua_stat_unit_test.cc b/tests/unittest/rua_stat_unit_test.cc new file mode 100644 index 0000000..1257cb2 --- /dev/null +++ b/tests/unittest/rua_stat_unit_test.cc @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include + +#include "sqlite3_mock.h" +#include "test_fixture.h" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::SetArgPointee; +using ::testing::Return; + +static int __rua_stat_tag_iter(const char* stat_tag, void* user_data) { + +} + +class StatMocks : public ::testing::NiceMock {}; + +class RuaStatTest : public TestFixture { + public: + RuaStatTest() : TestFixture(std::make_unique()) {} + virtual ~RuaStatTest() {} + + virtual void SetUp() { + } + + virtual void TearDown() { + } + +}; + +TEST_F(RuaStatTest, rua_stat_update_for_uid_N) { + int ret = rua_stat_update_for_uid("caller", "tag", 5001); + EXPECT_NE(ret, 0); +} + +TEST_F(RuaStatTest, rua_stat_get_stat_tags) { + char** table = (char** )calloc(10, sizeof(char*)); + ASSERT_TRUE(table != nullptr); + sqlite3* db = (sqlite3*) table; + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillOnce(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillOnce(Return(0)); + + int ret = rua_stat_get_stat_tags("caller", __rua_stat_tag_iter, nullptr); + EXPECT_EQ(ret, 0); + + free(table); +} + +TEST_F(RuaStatTest, rua_stat_db_update) { + char** table = (char** )calloc(10, sizeof(char*)); + ASSERT_TRUE(table != nullptr); + sqlite3* db = (sqlite3*) table; + + EXPECT_CALL(GetMock(), + sqlite3_open_v2(_, _, _, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0)))); + EXPECT_CALL(GetMock(), + sqlite3_close_v2(_)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_exec(_, _, _, _, _)).WillRepeatedly(Return(SQLITE_OK)); + EXPECT_CALL(GetMock(), + sqlite3_bind_int(_, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_double(_, _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(GetMock(), + sqlite3_step(_)).WillRepeatedly(Return(SQLITE_DONE)); + EXPECT_CALL(GetMock(), + sqlite3_finalize(_)).WillRepeatedly(Return(0)); + + int ret = rua_stat_db_update("caller", "rua_stat_tag"); + EXPECT_EQ(ret, SQLITE_DONE); + + free(table); +} \ No newline at end of file diff --git a/tests/unittest/rua_unit_test.cc b/tests/unittest/rua_unit_test.cc index 1bbc61f..be8ed1e 100644 --- a/tests/unittest/rua_unit_test.cc +++ b/tests/unittest/rua_unit_test.cc @@ -90,7 +90,7 @@ TEST_F(RuaTest, rua_clear_history) { TEST_F(RuaTest, rua_history_load_db_N) { int ret, nrows, ncols; - ret = rua_history_load_db(NULL, &nrows, &ncols); + ret = rua_history_load_db(nullptr, &nrows, &ncols); EXPECT_NE(ret, 0); } @@ -100,7 +100,7 @@ TEST_F(RuaTest, rua_register_update_cb_N) { WillOnce(Return(0)); int id; - int ret = rua_register_update_cb(__rua_history_update_cb, NULL, &id); + int ret = rua_register_update_cb(__rua_history_update_cb, nullptr, &id); EXPECT_NE(ret, 0); } @@ -112,54 +112,44 @@ TEST_F(RuaTest, rua_unregister_update_cb_N) { static char** __create_table(void) { char** table = (char** )calloc(10, sizeof(char*)); table[0] = strdup("pkgname"); - if (table[0] == nullptr) { + if (table[0] == nullptr) goto out; - } table[1] = strdup("apppath"); - if (table[1] == nullptr) { + if (table[1] == nullptr) goto out; - } table[2] = strdup("arg"); - if (table[2] == nullptr) { + if (table[2] == nullptr) goto out; - } table[3] = strdup("122232"); - if (table[3] == nullptr) { + if (table[3] == nullptr) goto out; - } table[4] = strdup("instance_id"); - if (table[4] == nullptr) { + if (table[4] == nullptr) goto out; - } table[5] = strdup("instance_name"); - if (table[5] == nullptr) { + if (table[5] == nullptr) goto out; - } table[6] = strdup("icon"); - if (table[6] == nullptr) { + if (table[6] == nullptr) goto out; - } table[7] = strdup("uri"); - if (table[7] == nullptr) { + if (table[7] == nullptr) goto out; - } table[8] = strdup("image"); - if (table[8] == nullptr) { + if (table[8] == nullptr) goto out; - } table[9] = strdup("compid"); - if (table[9] == nullptr) { + if (table[9] == nullptr) goto out; - } return table; @@ -174,7 +164,7 @@ out: TEST_F(RuaTest, rua_history_get_rec) { char** table = __create_table(); - ASSERT_TRUE(table != NULL); + ASSERT_TRUE(table != nullptr); EXPECT_CALL(GetMock(), sqlite3_open_v2(_, _, _, _)).WillOnce(Return(0)); @@ -190,14 +180,14 @@ TEST_F(RuaTest, rua_history_get_rec) { SetArgPointee<3>(1), SetArgPointee<4>(0), (Return(0)))); - char** get_table = NULL; + char** get_table = nullptr; int rows = 0; int cols = 0; struct rua_rec record; int ret; ret = rua_history_load_db(&get_table, &rows, &cols); EXPECT_EQ(ret, 0); - EXPECT_TRUE(get_table != NULL); + EXPECT_TRUE(get_table != nullptr); ret = rua_history_get_rec(&record, get_table, rows, cols, 0); EXPECT_EQ(ret, 0); -- 2.7.4