#include "aul_mock.h"
-extern "C" int aul_add_rua_history_for_uid(
- bundle* arg0, uid_t arg1) {
+extern "C" int aul_add_rua_history_for_uid(bundle* arg0, uid_t arg1) {
return MOCK_HOOK_P2(AulMock, aul_add_rua_history_for_uid, arg0, arg1);
}
+
+extern "C" int aul_delete_rua_history_for_uid(bundle* arg0, uid_t arg1) {
+ return MOCK_HOOK_P2(AulMock, aul_delete_rua_history_for_uid, arg0, arg1);
+}
+
+extern "C" int aul_comp_info_create(const char* arg0, aul_comp_info_h* arg1) {
+ return MOCK_HOOK_P2(AulMock, aul_comp_info_create, arg0, arg1);
+}
+
+extern "C" int aul_comp_info_destroy(
+ aul_comp_info_h arg0) {
+ return MOCK_HOOK_P1(AulMock, aul_comp_info_destroy, arg0);
+}
+
+extern "C" int aul_comp_info_clone(aul_comp_info_h arg0, aul_comp_info_h* arg1) {
+ return MOCK_HOOK_P2(AulMock, aul_comp_info_clone, arg0, arg1);
+}
+
+extern "C" int aul_comp_info_is_taskmanage(aul_comp_info_h arg0, bool* arg1) {
+ return MOCK_HOOK_P2(AulMock, aul_comp_info_is_taskmanage, arg0, arg1);
+}
+
+extern "C" int aul_comp_info_get_label(aul_comp_info_h arg0, const char** arg1) {
+ return MOCK_HOOK_P2(AulMock, aul_comp_info_get_label, arg0, arg1);
+}
\ No newline at end of file
#include <gmock/gmock.h>
#include <aul.h>
+#include <aul_comp_info.h>
#include <bundle.h>
#include "module_mock.h"
virtual ~AulMock() {}
MOCK_METHOD2(aul_add_rua_history_for_uid, int(bundle*, uid_t));
-
+ MOCK_METHOD2(aul_delete_rua_history_for_uid, int(bundle*, uid_t));
+ MOCK_METHOD2(aul_comp_info_create, int(const char*, aul_comp_info_h*));
+ MOCK_METHOD2(aul_comp_info_clone, int(aul_comp_info_h, aul_comp_info_h*));
+ MOCK_METHOD1(aul_comp_info_destroy, int(aul_comp_info_h));
+ MOCK_METHOD2(aul_comp_info_is_taskmanage, int(aul_comp_info_h, bool*));
+ MOCK_METHOD2(aul_comp_info_get_label, int(aul_comp_info_h, const char**));
};
#endif // UNIT_TESTS_MOCK_AUL_MOCK_H_
--- /dev/null
+/*
+ * 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 "gio_mock.h"
+
+#include <gio/gio.h>
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0,
+ const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
+ const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7,
+ gpointer arg8, GDestroyNotify arg9) {
+ return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+}
+
+extern "C" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg0,
+ const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
+ GVariant* arg5, GError** arg6) {
+ return MOCK_HOOK_P7(GioMock, g_dbus_connection_emit_signal,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+extern "C" gboolean g_dbus_connection_flush_sync(GDBusConnection* arg0,
+ GCancellable* arg1, GError** arg2) {
+ return MOCK_HOOK_P3(GioMock, g_dbus_connection_flush_sync, arg0, arg1, arg2);
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef UNIT_TESTS_MOCK_GIO_MOCK_H_
+#define UNIT_TESTS_MOCK_GIO_MOCK_H_
+
+#include <gio/gio.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class GioMock : public virtual ModuleMock {
+ public:
+ virtual ~GioMock() {}
+
+ MOCK_METHOD10(g_dbus_connection_signal_subscribe,
+ guint(GDBusConnection*, const gchar*, const gchar*, const gchar*,
+ const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback,
+ gpointer, GDestroyNotify));
+ MOCK_METHOD7(g_dbus_connection_emit_signal,
+ gboolean(GDBusConnection*, const gchar*, const gchar*, const gchar*,
+ const gchar*, GVariant*, GError**));
+ MOCK_METHOD3(g_dbus_connection_flush_sync,
+ gboolean(GDBusConnection*, GCancellable*, GError**));
+};
+
+#endif // UNIT_TESTS_MOCK_GIO_MOCK_H_
--- /dev/null
+/*
+ * 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 "pkgmgr_info_mock.h"
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int pkgmgrinfo_appinfo_get_appinfo(const char* arg0,
+ pkgmgrinfo_appinfo_h* arg1) {
+ return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_appinfo, arg0,
+ arg1);
+}
+
+extern "C" int pkgmgrinfo_appinfo_destroy_appinfo(
+ pkgmgrinfo_appinfo_h arg0) {
+ return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_appinfo_destroy_appinfo,
+ arg0);
+}
+
+
+extern "C" int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h arg0,
+ pkgmgrinfo_appinfo_h* arg1) {
+ return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_clone_appinfo, arg0,
+ arg1);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef UNIT_TESTS_MOCK_PKGMGR_INFO_MOCK_H_
+#define UNIT_TESTS_MOCK_PKGMGR_INFO_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <pkgmgr-info.h>
+
+#include "module_mock.h"
+
+class PkgmgrInfoMock : public virtual ModuleMock {
+ public:
+ virtual ~PkgmgrInfoMock() {}
+
+ MOCK_METHOD2(pkgmgrinfo_appinfo_get_appinfo,
+ int(const char*, pkgmgrinfo_appinfo_h*));
+ MOCK_METHOD1(pkgmgrinfo_appinfo_destroy_appinfo, int(pkgmgrinfo_appinfo_h));
+ MOCK_METHOD2(pkgmgrinfo_appinfo_clone_appinfo, int(pkgmgrinfo_appinfo_h,
+ pkgmgrinfo_appinfo_h*));
+};
+
+#endif // UNIT_TESTS_MOCK_PKGMGR_INFO_MOCK_H_
--- /dev/null
+/*
+ * 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 "mock_hook.h"
+#include "test_fixture.h"
+#include "sqlite3_mock.h"
+
+typedef int(*cb)(void*, int);
+typedef int(*execcb)(void*, int, char**, char**);
+typedef void(*bindcb)(void*);
+
+extern "C" int sqlite3_open_v2(const char* arg0,
+ sqlite3** arg1, int arg2, const char* arg3) {
+ return MOCK_HOOK_P4(SqlMock, sqlite3_open_v2, arg0, arg1, arg2, arg3);
+}
+
+extern "C" int sqlite3_close_v2(sqlite3* arg0) {
+ return MOCK_HOOK_P1(SqlMock, sqlite3_close_v2, arg0);
+}
+
+extern "C" void sqlite3_free_table(char** arg0) {
+ return MOCK_HOOK_P1(SqlMock, sqlite3_free_table, arg0);
+}
+
+extern "C" int sqlite3_busy_handler(sqlite3* arg0, cb arg1, void* arg2) {
+ return MOCK_HOOK_P3(SqlMock, sqlite3_busy_handler, arg0, arg1, arg2);
+}
+
+extern "C" int sqlite3_get_table(sqlite3* arg0, const char* arg1,
+ char*** arg2, int* arg3, int* arg4, char** arg5) {
+ return MOCK_HOOK_P6(SqlMock, sqlite3_get_table, arg0, arg1, arg2, arg3,
+ arg4, arg5);
+}
+
+extern "C" int sqlite3_exec(sqlite3* arg0, const char* arg1,
+ execcb arg2, void* arg3, char** arg4) {
+ return MOCK_HOOK_P5(SqlMock, sqlite3_exec, 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);
+}
+
+extern "C" int sqlite3_bind_text(sqlite3_stmt* arg0, int arg1, const char* arg2,
+ int arg3, bindcb arg4) {
+ return MOCK_HOOK_P5(SqlMock, sqlite3_bind_text, arg0, arg1, arg2, arg3, arg4);
+}
+
+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_step(sqlite3_stmt* arg0) {
+ return MOCK_HOOK_P1(SqlMock, sqlite3_step, arg0);
+}
+
+extern "C" int sqlite3_finalize(sqlite3_stmt* arg0) {
+ return MOCK_HOOK_P1(SqlMock, sqlite3_finalize, arg0);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef UNIT_TESTS_MOCK_SQLITE3_MOCK_H_
+#define UNIT_TESTS_MOCK_SQLITE3_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <sqlite3.h>
+
+#include "module_mock.h"
+
+class SqlMock : public virtual ModuleMock {
+ public:
+ virtual ~SqlMock() {}
+
+ MOCK_METHOD1(sqlite3_free_table, void(char**));
+ MOCK_METHOD1(sqlite3_close_v2, 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_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_METHOD1(sqlite3_step, int(sqlite3_stmt*));
+ MOCK_METHOD1(sqlite3_finalize, int(sqlite3_stmt*));
+
+};
+
+#endif // UNIT_TESTS_MOCK_SQLITE3_MOCK_H_
PKG_CHECK_MODULES(gtest_pkgs REQUIRED gmock)
TARGET_LINK_LIBRARIES(${TARGET_RUA_UNIT_TEST} PUBLIC ${gtest_pkgs_LDFLAGS} ${PROJECT_NAME})
-SET_TARGET_PROPERTIES(${TARGET_RUA_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_RUA_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default")
SET_TARGET_PROPERTIES(${TARGET_RUA_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
ADD_TEST(
--- /dev/null
+/*
+ * 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_manager.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "aul_mock.h"
+#include "sqlite3_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "test_fixture.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::SetArgPointee;
+using ::testing::Return;
+
+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_clone(info, cloned);
+ }
+
+ return false;
+}
+
+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 ManagerMocks : public ::testing::NiceMock<AulMock>,
+ public ::testing::NiceMock<PkgmgrInfoMock>,
+ public ::testing::NiceMock<SqlMock> {};
+
+class RuaManagerTest : public TestFixture {
+ public:
+ RuaManagerTest() : TestFixture(std::make_unique<ManagerMocks>()) {}
+ virtual ~RuaManagerTest() {}
+
+ virtual void SetUp() {
+ table_ = __create_table();
+ if (table_ == nullptr)
+ return;
+
+ temp_ = (void*)malloc(1);
+ if (temp_ == nullptr)
+ return;
+
+ EXPECT_CALL(GetMock<SqlMock>(),
+ sqlite3_open_v2(_, _, _, _)).WillRepeatedly(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<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_get_appinfo(_, _)).
+ WillOnce(DoAll(SetArgPointee<1>(temp_),Return(0)));
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_comp_info_create(_, _)).
+ WillOnce(DoAll(SetArgPointee<1>(temp_),Return(0)));
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_comp_info_destroy(_)).
+ WillRepeatedly(Return(0));
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_destroy_appinfo(_)).
+ WillRepeatedly(Return(0));
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_clone_appinfo(_, _)).
+ WillOnce(DoAll(SetArgPointee<1>(temp_),Return(0)));
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_comp_info_clone(_, _)).
+ WillOnce(DoAll(SetArgPointee<1>(temp_),Return(0)));
+
+ rua_manager_foreach_rua_info(__rua_info_cb, &info_);
+ }
+
+ virtual void TearDown() {
+ if (table_) {
+ for (int i = 0; i < 10; i++)
+ free(table_[i]);
+ free(table_);
+ }
+ if (temp_)
+ free(temp_);
+
+ rua_info_destroy(info_);
+ }
+
+ public:
+ rua_info_h info_ = nullptr;
+
+ private:
+ char** table_ = nullptr;
+ void* temp_ = nullptr;
+};
+
+TEST_F(RuaManagerTest, rua_manager_delete_rua_info) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_delete_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret = rua_manager_delete_rua_info(info_);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_manager_delete_all_rua_info) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_delete_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret = rua_manager_delete_all_rua_info();
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_manager_get_app_control_from_rua_info_N) {
+ app_control_h ac;
+
+ int ret = rua_manager_get_app_control_from_rua_info(info_, &ac);
+ EXPECT_NE(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_manager_get_rua_context_from_rua_info) {
+ rua_context_h ctx;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_context_destroy(ctx);
+ EXPECT_EQ(ret, 0);
+}
+
+
+TEST_F(RuaManagerTest, rua_manager_is_running_N) {
+ rua_context_h ctx;
+ bool running;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_manager_is_running(ctx, &running);
+ EXPECT_NE(ret, 0);
+
+ ret = rua_context_destroy(ctx);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_manager_resume_N) {
+ rua_context_h ctx;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_manager_resume(ctx);
+ EXPECT_NE(ret, 0);
+
+ ret = rua_context_destroy(ctx);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_manager_terminate_N) {
+ rua_context_h ctx;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_manager_terminate(ctx);
+ EXPECT_NE(ret, 0);
+
+ ret = rua_context_destroy(ctx);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_context_get_app_id) {
+ rua_context_h ctx;
+ char* appid;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_context_get_app_id(ctx, &appid);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(appid, std::string("pkgname"));
+
+ free(appid);
+}
+
+TEST_F(RuaManagerTest, rua_context_get_instance_id) {
+ rua_context_h ctx;
+ char* instanceid;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_context_get_instance_id(ctx, &instanceid);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(instanceid, std::string("instance_id"));
+
+ free(instanceid);
+}
+
+TEST_F(RuaManagerTest, rua_context_get_component_id) {
+ rua_context_h ctx;
+ char* compid;
+
+ int ret = rua_manager_get_rua_context_from_rua_info(info_, &ctx);
+ EXPECT_EQ(ret, 0);
+
+ ret = rua_context_get_component_id(ctx, &compid);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(compid, std::string("compid"));
+
+ free(compid);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_app_id) {
+ char* app_id;
+
+ int ret = rua_info_get_app_id(info_, &app_id);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(app_id, std::string("pkgname"));
+
+ free(app_id);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_app_path) {
+ char* app_path;
+
+ int ret = rua_info_get_app_path(info_, &app_path);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(app_path, std::string("apppath"));
+
+ free(app_path);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_args) {
+ char* args;
+
+ int ret = rua_info_get_args(info_, &args);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(args, std::string("arg"));
+
+ free(args);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_launch_time) {
+ time_t launch_time;
+
+ int ret = rua_info_get_launch_time(info_, &launch_time);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(launch_time, 122232);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_instance_id) {
+ char* instance_id;
+
+ int ret = rua_info_get_instance_id(info_, &instance_id);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(instance_id, std::string("instance_id"));
+
+ free(instance_id);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_instance_name) {
+ char* instance_name;
+
+ int ret = rua_info_get_instance_name(info_, &instance_name);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(instance_name, std::string("instance_name"));
+
+ free(instance_name);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_icon) {
+ char* icon;
+
+ int ret = rua_info_get_icon(info_, &icon);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(icon, std::string("icon"));
+
+ free(icon);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_uri) {
+ char* uri;
+
+ int ret = rua_info_get_uri(info_, &uri);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(uri, std::string("uri"));
+
+ free(uri);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_image) {
+ char* image;
+
+ int ret = rua_info_get_image(info_, &image);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(image, std::string("image"));
+
+ free(image);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_component_id) {
+ char* comp_id;
+
+ int ret = rua_info_get_component_id(info_, &comp_id);
+ EXPECT_EQ(ret, 0);
+ EXPECT_EQ(comp_id, std::string("compid"));
+
+ free(comp_id);
+}
+
+TEST_F(RuaManagerTest, rua_info_is_managed_by_task_manager) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_comp_info_is_taskmanage(_, _)).
+ WillOnce(Return(0));
+
+ bool managed;
+
+ int ret = rua_info_is_managed_by_task_manager(info_, &managed);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaManagerTest, rua_info_get_label) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_comp_info_get_label(_, _)).
+ WillOnce(Return(0));
+
+ char* label;
+
+ int ret = rua_info_get_label(info_, &label);
+ EXPECT_EQ(ret, 0);
+}
\ No newline at end of file
#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;
-class Mocks : public ::testing::NiceMock<AulMock>{};
+class Mocks : public ::testing::NiceMock<AulMock>,
+ public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<SqlMock> {};
class RuaTest : public TestFixture {
public:
}
};
+static void __rua_history_update_cb(char** table, int nrows, int ncols,
+ void* user_data) {
+}
+
TEST_F(RuaTest, rua_add_history_for_uid) {
EXPECT_CALL(GetMock<AulMock>(),
aul_add_rua_history_for_uid(_, _)).
WillOnce(Return(0));
+ int ret = rua_add_history_for_uid("test", "/app_path", "arg", 5001);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaTest, rua_delete_history_with_pkgname) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_delete_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret = rua_delete_history_with_pkgname("test");
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaTest, rua_delete_history_with_apppath) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_delete_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret = rua_delete_history_with_apppath("/app_path");
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaTest, rua_clear_history) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_delete_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret = rua_clear_history();
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaTest, rua_history_load_db_N) {
+ int ret, nrows, ncols;
+ ret = rua_history_load_db(NULL, &nrows, &ncols);
+ EXPECT_NE(ret, 0);
+}
+
+TEST_F(RuaTest, rua_register_update_cb_N) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _)).
+ WillOnce(Return(0));
+
+ int id;
+ int ret = rua_register_update_cb(__rua_history_update_cb, NULL, &id);
+ EXPECT_NE(ret, 0);
+}
+
+TEST_F(RuaTest, rua_unregister_update_cb_N) {
+ int ret = rua_unregister_update_cb(1);
+ 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]);
+ }
+
+ return nullptr;
+}
+
+TEST_F(RuaTest, rua_history_get_rec) {
+ char** table = __create_table();
+ ASSERT_TRUE(table != NULL);
+
+ EXPECT_CALL(GetMock<SqlMock>(),
+ sqlite3_open_v2(_, _, _, _)).WillOnce(Return(0));
+ EXPECT_CALL(GetMock<SqlMock>(),
+ sqlite3_close_v2(_)).WillOnce(Return(0));
+ EXPECT_CALL(GetMock<SqlMock>(),
+ sqlite3_free_table(_));
+ EXPECT_CALL(GetMock<SqlMock>(),
+ sqlite3_busy_handler(_, _, _)).WillOnce(Return(0));
+ EXPECT_CALL(GetMock<SqlMock>(),
+ sqlite3_get_table(_, _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<2>(table),
+ SetArgPointee<3>(1),
+ SetArgPointee<4>(0), (Return(0))));
+
+ char** get_table = NULL;
+ int rows = 0;
+ int cols = 0;
+ struct rua_rec record;
int ret;
- ret = rua_add_history_for_uid("test", "/app_path", "arg", 5001);
+ ret = rua_history_load_db(&get_table, &rows, &cols);
EXPECT_EQ(ret, 0);
+ EXPECT_TRUE(get_table != NULL);
+
+ ret = rua_history_get_rec(&record, get_table, rows, cols, 0);
+ 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_delete_history_with_pkgname_N) {
+TEST_F(RuaTest, rua_is_latest_app_N) {
int ret;
- ret = rua_delete_history_with_pkgname("test");
+ ret = rua_is_latest_app("pkgname");
EXPECT_NE(ret, 0);
}
+TEST_F(RuaTest, rua_delete_history_with_instance_id) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_delete_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret;
+ ret = rua_delete_history_with_instance_id("appid", "instanceid");
+ EXPECT_EQ(ret, 0);
+}
\ No newline at end of file