PKG_CHECK_MODULES(GUM_DEPS REQUIRED libgum)
PKG_CHECK_MODULES(MANIFEST_PARSER_DEPS REQUIRED manifest-parser)
PKG_CHECK_MODULES(MINIZIP_DEPS REQUIRED minizip)
+PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
PKG_CHECK_MODULES(PKGMGR_TYPES_DEPS REQUIRED pkgmgr-types)
PKG_CHECK_MODULES(TPK_INSTALLER_DEPS REQUIRED tpk-installer)
PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
PKG_CHECK_MODULES(WGT_INSTALLER_DEPS REQUIRED wgt-installer)
PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
+PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
+PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex program_options)
BuildRequires: pkgconfig(libgum)
BuildRequires: pkgconfig(manifest-parser)
BuildRequires: pkgconfig(minizip)
+BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(pkgmgr-types)
BuildRequires: pkgconfig(tpk-installer)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(wgt-installer)
BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(glib-2.0)
%if 0%{?gcov:1}
BuildRequires: lcov
%endif
%check
+export LD_LIBRARY_PATH=../../src/unified
ctest -V
%if 0%{?gcov:1}
lcov -c --ignore-errors graph --no-external -q -d . -o unified-backend.info
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock/ UNIT_TESTS_SRCS)
ADD_EXECUTABLE(${TARGET_UNIFIED_INSTALLER_UNIT_TEST}
${UNIT_TESTS_SRCS}
)
-#TARGET_INCLUDE_DIRECTORIES(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PUBLIC
-# "${CMAKE_CURRENT_SOURCE_DIR}/../"
-# "${CMAKE_CURRENT_SOURCE_DIR}/../../src"
-#)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PUBLIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/../"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../src"
+)
APPLY_PKG_CONFIG(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PUBLIC
GMOCK_DEPS
+ APP_INSTALLERS_DEPS
+ GIO_DEPS
+ GLIB_DEPS
+ GUM_DEPS
+ PKGMGR_INFO_DEPS
)
-TARGET_LINK_LIBRARIES(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PUBLIC ${TARGET_LIBNAME_UNIFIED} ${TARGET_TPK_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
+TARGET_LINK_LIBRARIES(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PRIVATE ${TARGET_LIBNAME_UNIFIED})
SET_TARGET_PROPERTIES(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
SET_TARGET_PROPERTIES(${TARGET_UNIFIED_INSTALLER_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
--- /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 "unit_tests/mock/gum_mock.h"
+
+#include <gum/gum-user.h>
+#include <gum/gum-user-service.h>
+#include <gum/common/gum-user-types.h>
+
+#include "unit_tests/mock/mock_hook.h"
+#include "unit_tests/mock/test_fixture.h"
+
+extern "C" GumUser* gum_user_get_sync(uid_t uid, gboolean offline) {
+ return MOCK_HOOK_P2(GumMock, gum_user_get_sync, uid, offline);
+}
--- /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 TEST_UNIT_TESTS_MOCK_GUM_MOCK_H_
+#define TEST_UNIT_TESTS_MOCK_GUM_MOCK_H_
+
+#include <gum/gum-user.h>
+#include <gum/gum-user-service.h>
+#include <gum/common/gum-user-types.h>
+
+#include <gmock/gmock.h>
+
+#include "unit_tests/mock/module_mock.h"
+
+class GumMock : public virtual ModuleMock {
+ public:
+ virtual ~GumMock() {}
+#if 1
+ MOCK_METHOD2(gum_user_get_sync, GumUser*(uid_t, gboolean));
+#else
+ MOCK_METHOD3(g_bus_get_sync,
+ GDBusConnection*(GBusType, GCancellable*, GError**));
+ MOCK_METHOD7(g_bus_own_name_on_connection,
+ guint(GDBusConnection*, const gchar*, GBusNameOwnerFlags,
+ GBusNameAcquiredCallback, GBusNameLostCallback,
+ gpointer, GDestroyNotify));
+
+ MOCK_METHOD4(g_dbus_message_new_method_call,
+ GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*));
+ MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*));
+ MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*));
+
+ MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync,
+ GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags,
+ gint, volatile guint32*, GCancellable*, GError**));
+ MOCK_METHOD7(g_dbus_connection_emit_signal,
+ gboolean(GDBusConnection*, const gchar*, const gchar*, const gchar*,
+ const gchar*, GVariant*, GError**));
+ MOCK_METHOD7(g_dbus_connection_register_object,
+ guint(GDBusConnection*, const gchar*, GDBusInterfaceInfo*,
+ const GDBusInterfaceVTable*, gpointer, GDestroyNotify, GError**));
+ MOCK_METHOD10(g_dbus_connection_signal_subscribe,
+ guint(GDBusConnection*, const gchar*, const gchar*, const gchar*,
+ const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback,
+ gpointer, GDestroyNotify));
+ MOCK_METHOD8(g_dbus_connection_send_message_with_reply,
+ void(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, gint,
+ volatile guint32*, GCancellable*, GAsyncReadyCallback, gpointer));
+ MOCK_METHOD3(g_dbus_connection_send_message_with_reply_finish,
+ GDBusMessage*(GDBusConnection*, GAsyncResult*, GError**));
+
+ MOCK_METHOD2(g_dbus_node_info_new_for_xml,
+ GDBusNodeInfo*(const gchar*, GError**));
+
+ MOCK_METHOD2(g_dbus_method_invocation_return_value,
+ GDBusNodeInfo*(GDBusMethodInvocation*, GVariant*));
+#endif
+};
+
+#endif // TEST_UNIT_TESTS_MOCK_GUM_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.
+ */
+
+#ifndef TEST_UNIT_TESTS_MOCK_MOCK_HOOK_H_
+#define TEST_UNIT_TESTS_MOCK_MOCK_HOOK_H_
+
+#define MOCK_HOOK_P0(MOCK_CLASS, f) \
+ TestFixture::GetMock<MOCK_CLASS>().f()
+#define MOCK_HOOK_P1(MOCK_CLASS, f, p1) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1)
+#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2)
+#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3)
+#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4)
+#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5)
+#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6)
+#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7)
+#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7, p8)
+#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \
+ TestFixture::GetMock<MOCK_CLASS>().f( \
+ p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
+
+#endif // TEST_UNIT_TESTS_MOCK_MOCK_HOOK_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.
+ */
+
+#ifndef TEST_UNIT_TESTS_MOCK_MODULE_MOCK_H_
+#define TEST_UNIT_TESTS_MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // TEST_UNIT_TESTS_MOCK_MODULE_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 "unit_tests/mock/pkgmgr_info_mock.h"
+
+#include <pkgmgr-info.h>
+
+#include "unit_tests/mock/mock_hook.h"
+#include "unit_tests/mock/test_fixture.h"
+
+extern "C" int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+ const char* pkgid, uid_t uid, pkgmgrinfo_pkginfo_h* handle) {
+ return MOCK_HOOK_P3(PkgmgrInfoMock,
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo, pkgid, uid, handle);
+}
+
+extern "C" int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle,
+ char** type) {
+ return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_type, handle,
+ type);
+}
--- /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 TEST_UNIT_TESTS_MOCK_PKGMGR_INFO_MOCK_H_
+#define TEST_UNIT_TESTS_MOCK_PKGMGR_INFO_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <pkgmgr-info.h>
+
+#include "unit_tests/mock/module_mock.h"
+
+class PkgmgrInfoMock : public virtual ModuleMock {
+ public:
+ virtual ~PkgmgrInfoMock() {}
+
+ MOCK_METHOD3(pkgmgrinfo_pkginfo_get_usr_all_pkginfo,
+ int(const char*, uid_t, pkgmgrinfo_pkginfo_h*));
+ MOCK_METHOD2(pkgmgrinfo_pkginfo_get_type,
+ int(pkgmgrinfo_pkginfo_h, char**));
+};
+
+#endif // TEST_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 "unit_tests/mock/test_fixture.h"
+#include <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
--- /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 TEST_UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+#define TEST_UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "unit_tests/mock/module_mock.h"
+
+class TestFixture : public ::testing::Test {
+ public:
+ explicit TestFixture(std::unique_ptr<ModuleMock>&& mock) {
+ mock_ = std::move(mock);
+ }
+ virtual ~TestFixture() {
+ mock_.reset();
+ }
+
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+
+ template <typename T>
+ static T& GetMock() {
+ auto ptr = dynamic_cast<T*>(mock_.get());
+ if (!ptr)
+ throw std::invalid_argument("The test does not provide mock of \"" +
+ std::string(typeid(T).name()) + "\"");
+ return *ptr;
+ }
+
+ static std::unique_ptr<ModuleMock> mock_;
+};
+
+#endif // TEST_UNIT_TESTS_MOCK_TEST_FIXTURE_H_
--- /dev/null
+NEW
+/opt/usr/share/package-unpacked/unpack-265cd0
+org.example.tpk40sample2
+false
--- /dev/null
+NEW
+/opt/usr/share/package-unpacked/unpack-265cd0
+vHhZK6lhQg
+false
* limitations under the License.
*/
+#include <gio/gio.h>
+#include <glib-object.h>
#include <stdlib.h>
-#include <gtest/gtest.h>
+#include <pkgmgrinfo_basic.h>
+#include <gtest/gtest.h>
#include <iostream>
#include <memory>
+#include "common/installer/app_installer.h"
#include "unified/unified_installer_factory.h"
-class UnifiedInstallerFactoryTest : public testing::Test {
+#include "unit_tests/mock/gum_mock.h"
+#include "unit_tests/mock/pkgmgr_info_mock.h"
+#include "unit_tests/mock/test_fixture.h"
+
+#include "common/pkgmgr_interface.h"
+
+
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Invoke;
+using ::testing::StrEq;
+using ::testing::SetArgPointee;
+using ::testing::Return;
+
+static GumUser* __gum_user_get_sync_fake(
+ uid_t, gboolean) {
+ return nullptr;
+}
+
+class Mocks : public ::testing::NiceMock<GumMock>,
+ public ::testing::NiceMock<PkgmgrInfoMock>{};
+
+class UnifiedInstallerFactoryTest : public TestFixture {
public:
+ UnifiedInstallerFactoryTest() : TestFixture(std::make_unique<Mocks>()) {}
virtual ~UnifiedInstallerFactoryTest() {}
virtual void SetUp() {}
virtual void TestDown() {}
};
-TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_P) {
- // template testcase.
+class TestPkgmgrInstaller : public common_installer::PkgmgrInstallerInterface {
+ public:
+ bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
+ common_installer::InstallationMode* mode) {
+ *installer = pkgmgr_installer_offline_new();
+ if (!*installer)
+ return false;
+ *mode = common_installer::InstallationMode::ONLINE;
+ return true;
+ }
+
+ bool ShouldCreateSignal() const {
+ return false;
+ }
+};
+
+TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromPkgID) {
+ std::vector<std::string> arguments =
+ {"unified-backend", "-i", "tpk_pkgid", "wgt_pkgid"};
+ std::vector<char*> argv;
+ for (const auto& arg : arguments)
+ argv.push_back(const_cast<char*>(
+ reinterpret_cast<const char*>(arg.data())));
+ argv.push_back(nullptr);
+
+ TestPkgmgrInstaller pkgmgr_installer;
+ EXPECT_CALL(GetMock<GumMock>(),
+ gum_user_get_sync(_, _)).
+ WillRepeatedly(Invoke(__gum_user_get_sync_fake));
+
+ auto pkgmgr = common_installer::PkgMgrInterface::Create(
+ argv.size() - 1,
+ argv.data(),
+ &pkgmgr_installer,
+ nullptr);
+ if (!pkgmgr) {
+ ASSERT_TRUE(false);
+ }
+
+ std::unique_ptr<common_installer::UnifiedInstallerFactory>factory(
+ new common_installer::UnifiedInstallerFactory());
+
+ pkgmgrinfo_pkginfo_h handle1 = calloc(1, sizeof(manifest_x));
+ pkgmgrinfo_pkginfo_h handle2 = calloc(1, sizeof(manifest_x));
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo(StrEq("tpk_pkgid"), _, _)).
+ WillOnce(DoAll(
+ SetArgPointee<2>(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
+ Return(PMINFO_R_OK)));
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo(StrEq("wgt_pkgid"), _, _)).
+ WillOnce(DoAll(
+ SetArgPointee<2>(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),
+ Return(PMINFO_R_OK)));
+ char wgt[] = "wgt";
+ char tpk[] = "tpk";
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_type(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1), _)).
+ WillOnce(DoAll(
+ SetArgPointee<1>(const_cast<char*>(tpk)),
+ Return(PMINFO_R_OK)));
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_type(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2), _)).
+ WillOnce(DoAll(
+ SetArgPointee<1>(const_cast<char*>(wgt)),
+ Return(PMINFO_R_OK)));
+
+ EXPECT_EQ(pkgmgr->GetRequestInfoCount(), 2);
+
+ for (int idx = 0; idx < 2; idx++) {
+ std::unique_ptr<common_installer::AppInstaller> installer =
+ factory->CreateInstaller(pkgmgr, idx);
+ // TODO(jungh.yeon): Need to add ways about validating instance.
+ EXPECT_NE(installer, nullptr);
+ }
+}
+
+TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromFilename) {
+ std::vector<std::string> arguments =
+ {"unified-backend", "-b", "test_samples/tpk-recovery-123456",
+ "test_samples/wgt-recovery-123456"};
+ std::vector<char*> argv;
+ for (const auto& arg : arguments)
+ argv.push_back(const_cast<char*>(
+ reinterpret_cast<const char*>(arg.data())));
+ argv.push_back(nullptr);
+
+ pkgmgrinfo_pkginfo_h handle1 = calloc(1, sizeof(manifest_x));
+ pkgmgrinfo_pkginfo_h handle2 = calloc(1, sizeof(manifest_x));
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+ StrEq("test_samples/tpk-recovery-123456"), _, _)).
+ WillOnce(DoAll(
+ SetArgPointee<2>(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
+ Return(PMINFO_R_OK)));
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+ StrEq("test_samples/wgt-recovery-123456"), _, _)).
+ WillOnce(DoAll(
+ SetArgPointee<2>(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),
+ Return(PMINFO_R_OK)));
+
+ TestPkgmgrInstaller pkgmgr_installer;
+ EXPECT_CALL(GetMock<GumMock>(),
+ gum_user_get_sync(_, _)).
+ WillRepeatedly(Invoke(__gum_user_get_sync_fake));
+
+ auto pkgmgr = common_installer::PkgMgrInterface::Create(
+ argv.size() - 1,
+ argv.data(),
+ &pkgmgr_installer,
+ nullptr);
+ if (!pkgmgr) {
+ ASSERT_TRUE(false);
+ }
+
+ EXPECT_EQ(pkgmgr->GetRequestInfoCount(), 2);
+
+ std::unique_ptr<common_installer::UnifiedInstallerFactory>factory(
+ new common_installer::UnifiedInstallerFactory());
+
+ for (int idx = 0; idx < 2; idx++) {
+ std::unique_ptr<common_installer::AppInstaller> installer =
+ factory->CreateInstaller(pkgmgr, idx);
+ // TODO(jungh.yeon): Need to add ways about validating instance.
+ EXPECT_NE(installer, nullptr);
+ }
+}
+
+TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromPkgFile) {
+ std::vector<std::string> arguments =
+ {"unified-backend", "-i", "test_samples/test-tpk-pkg.tpk",
+ "test_samples/test-wgt-pkg.wgt"};
+ std::vector<char*> argv;
+ for (const auto& arg : arguments)
+ argv.push_back(const_cast<char*>(
+ reinterpret_cast<const char*>(arg.data())));
+ argv.push_back(nullptr);
+
+ TestPkgmgrInstaller pkgmgr_installer;
+ EXPECT_CALL(GetMock<GumMock>(),
+ gum_user_get_sync(_, _)).
+ WillRepeatedly(Invoke(__gum_user_get_sync_fake));
+
+ pkgmgrinfo_pkginfo_h handle1 = calloc(1, sizeof(manifest_x));
+ pkgmgrinfo_pkginfo_h handle2 = calloc(1, sizeof(manifest_x));
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+ StrEq("test_samples/test-tpk-pkg.tpk"), _, _)).
+ WillOnce(DoAll(
+ SetArgPointee<2>(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
+ Return(PMINFO_R_OK)));
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+ StrEq("test_samples/test-wgt-pkg.wgt"), _, _)).
+ WillOnce(DoAll(
+ SetArgPointee<2>(
+ reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),
+ Return(PMINFO_R_OK)));
+
+ auto pkgmgr = common_installer::PkgMgrInterface::Create(
+ argv.size() - 1,
+ argv.data(),
+ &pkgmgr_installer,
+ nullptr);
+ if (!pkgmgr) {
+ ASSERT_TRUE(false);
+ }
+
+ EXPECT_EQ(pkgmgr->GetRequestInfoCount(), 2);
+
+ std::unique_ptr<common_installer::UnifiedInstallerFactory>factory(
+ new common_installer::UnifiedInstallerFactory());
- ASSERT_TRUE(true);
+ for (int idx = 0; idx < 2; idx++) {
+ std::unique_ptr<common_installer::AppInstaller> installer =
+ factory->CreateInstaller(pkgmgr, idx);
+ // TODO(jungh.yeon): Need to add ways about validating instance.
+ EXPECT_NE(installer, nullptr);
+ }
}