Improve coverages 91/242591/3
authorInkyun Kil <inkyun.kil@samsung.com>
Fri, 28 Aug 2020 06:26:39 +0000 (15:26 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Tue, 1 Sep 2020 03:01:10 +0000 (12:01 +0900)
Add unittest for rua_internal, rua_stat

Change-Id: I152be6cef37eba4ea138440d583942f03570143b
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
tests/mock/sqlite3_mock.cc
tests/mock/sqlite3_mock.h
tests/unittest/rua_internal_unit_test.cc [new file with mode: 0644]
tests/unittest/rua_manager_unit_test.cc
tests/unittest/rua_stat_unit_test.cc [new file with mode: 0644]
tests/unittest/rua_unit_test.cc

index 83629a0..fd9e19e 100644 (file)
@@ -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
index ab62a24..1177f1b 100644 (file)
@@ -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 (file)
index 0000000..01b5e0a
--- /dev/null
@@ -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 <gtest/gtest.h>
+
+#include <rua.h>
+#include <rua_internal.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#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<GioMock>,
+              public ::testing::NiceMock<SqlMock> {};
+
+class RuaInternalTest : public TestFixture {
+ public:
+  RuaInternalTest() : TestFixture(std::make_unique<InternalMocks>()) {}
+  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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_free_table(_));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_get_table(_, _, _, _, _, _)).
+      WillOnce(DoAll(SetArgPointee<2>(table_),
+                     SetArgPointee<3>(1),
+                     SetArgPointee<4>(0), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_int(_, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_finalize(_)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+          WillOnce(Return(true));
+  EXPECT_CALL(GetMock<GioMock>(),
+      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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_free_table(_));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_get_table(_, _, _, _, _, _)).
+      WillOnce(DoAll(SetArgPointee<2>(table_),
+                     SetArgPointee<3>(1),
+                     SetArgPointee<4>(0), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_int(_, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_finalize(_)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+          WillOnce(Return(true));
+  EXPECT_CALL(GetMock<GioMock>(),
+      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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_finalize(_)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+          WillOnce(Return(true));
+  EXPECT_CALL(GetMock<GioMock>(),
+      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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_finalize(_)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+          WillOnce(Return(true));
+  EXPECT_CALL(GetMock<GioMock>(),
+      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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_finalize(_)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+          WillOnce(Return(true));
+  EXPECT_CALL(GetMock<GioMock>(),
+      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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_prepare_v2(_, _, _, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_finalize(_)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+          WillOnce(Return(true));
+  EXPECT_CALL(GetMock<GioMock>(),
+      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
index cc4289a..f066c8b 100644 (file)
@@ -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 (file)
index 0000000..1257cb2
--- /dev/null
@@ -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 <gtest/gtest.h>
+
+#include <rua.h>
+#include <rua_stat.h>
+#include <rua_stat_internal.h>
+
+#include <string>
+#include <memory>
+
+#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<SqlMock> {};
+
+class RuaStatTest : public TestFixture {
+ public:
+  RuaStatTest() : TestFixture(std::make_unique<StatMocks>()) {}
+  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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillOnce(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      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<SqlMock>(),
+      sqlite3_open_v2(_, _, _, _)).
+          WillRepeatedly(DoAll(SetArgPointee<1>(db), (Return(0))));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_close_v2(_)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_busy_handler(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_exec(_, _, _, _, _)).WillRepeatedly(Return(SQLITE_OK));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_int(_, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_double(_, _, _)).WillOnce(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_bind_text(_, _, _, _, _)).WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      sqlite3_step(_)).WillRepeatedly(Return(SQLITE_DONE));
+  EXPECT_CALL(GetMock<SqlMock>(),
+      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
index 1bbc61f..be8ed1e 100644 (file)
@@ -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<SqlMock>(),
       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);