--- /dev/null
+/*
+ * app2sd-unittest
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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/gio.h>
+#include <gmock/gmock.h>
+#include "inc/app2ext_interface.h"
+
+static GVariant* __last_parameters;
+static gchar* __last_method_name;
+
+extern "C" GDBusConnection* g_bus_get_sync(GBusType type,
+ GCancellable* cancellable, GError** error) {
+ gpointer dummy = g_object_new(G_TYPE_OBJECT, nullptr);
+ return (GDBusConnection*)dummy;
+}
+
+extern "C" GDBusProxy* g_dbus_proxy_new_sync(GDBusConnection* connection,
+ GDBusProxyFlags flags, GDBusInterfaceInfo* info, const gchar* name,
+ const gchar* object_path, const gchar* interface_name,
+ GCancellable* cancellable, GError** error) {
+ gpointer dummy = g_object_new(G_TYPE_OBJECT, nullptr);
+ return (GDBusProxy*)dummy;
+}
+
+extern "C" GVariant* g_dbus_proxy_call_sync(GDBusProxy* proxy,
+ const gchar* method_name, GVariant* parameters, GDBusCallFlags flags,
+ gint timeout_msec, GCancellable* cancellable, GError** error) {
+ GVariant* gv = g_variant_new("(i)", 0);
+
+ if (parameters != nullptr) {
+ if (__last_parameters)
+ g_variant_unref(__last_parameters);
+ __last_parameters = g_variant_ref(parameters);
+ }
+
+ if (__last_method_name)
+ g_free(__last_method_name);
+
+ __last_method_name = g_strdup(method_name);
+ return gv;
+}
+
+namespace {
+class App2extInterfaceTest : public ::testing::Test {
+ protected:
+ void SetUp() override {}
+
+ void TearDown() override {
+ if (__last_parameters) {
+ g_variant_unref(__last_parameters);
+ __last_parameters = nullptr;
+ }
+ if (__last_method_name) {
+ g_free(__last_method_name);
+ __last_method_name = nullptr;
+ }
+ }
+};
+
+TEST_F(App2extInterfaceTest, Init) {
+ app2ext_handle* handle = app2ext_init(APP2EXT_INTERNAL_MEM);
+ EXPECT_THAT(handle, testing::Eq(nullptr));
+ handle = app2ext_init(APP2EXT_SD_CARD);
+ ASSERT_TRUE(handle != nullptr);
+ EXPECT_THAT(handle->type, testing::Eq(APP2EXT_SD_CARD));
+ app2ext_deinit(handle);
+}
+
+TEST_F(App2extInterfaceTest, EnableDisableExternalPkgs) {
+ // wrong parameters
+ int ret = app2ext_enable_external_pkg(nullptr);
+ EXPECT_THAT(ret, testing::Eq(-1));
+ ret = app2ext_disable_external_pkg(nullptr);
+ EXPECT_THAT(ret, testing::Eq(-1));
+
+ // normal
+ ret = app2ext_enable_external_pkg("not.exists.package");
+ EXPECT_THAT(ret, testing::Eq(0));
+ EXPECT_THAT(__last_method_name, testing::StrEq("OndemandSetupInit"));
+ gchar* pkgid;
+ gint uid;
+ g_variant_get(__last_parameters, "(si)", &pkgid, &uid);
+ EXPECT_THAT(pkgid, testing::StrEq("not.exists.package"));
+ g_free(pkgid);
+
+ ret = app2ext_disable_external_pkg("not.exists.package");
+ EXPECT_THAT(ret, testing::Eq(0));
+ EXPECT_THAT(__last_method_name, testing::StrEq("OndemandSetupExit"));
+ g_variant_get(__last_parameters, "(si)", &pkgid, &uid);
+ EXPECT_THAT(pkgid, testing::StrEq("not.exists.package"));
+ g_free(pkgid);
+
+ ret = app2ext_enable_all_external_pkgs();
+ EXPECT_THAT(ret, testing::Eq(0));
+ EXPECT_THAT(__last_method_name, testing::StrEq("EnableFullPkg"));
+
+ ret = app2ext_disable_all_external_pkgs();
+ EXPECT_THAT(ret, testing::Eq(0));
+ EXPECT_THAT(__last_method_name, testing::StrEq("DisableFullPkg"));
+}
+
+TEST_F(App2extInterfaceTest, Cleanup) {
+ // wrong parameters
+ int ret = app2ext_force_clean_pkg(nullptr);
+ EXPECT_THAT(ret, testing::Eq(-1));
+
+ // normal
+ ret = app2ext_force_clean_pkg("not.exists.package");
+ EXPECT_THAT(ret, testing::Eq(0));
+ EXPECT_THAT(__last_method_name, testing::StrEq("ForceClean"));
+ gchar* pkgid;
+ gint uid;
+ g_variant_get(__last_parameters, "(si)", &pkgid, &uid);
+ EXPECT_THAT(pkgid, testing::StrEq("not.exists.package"));
+ g_free(pkgid);
+}
+
+TEST_F(App2extInterfaceTest, Migrate) {
+ int ret = app2ext_migrate_legacy_all();
+ EXPECT_THAT(ret, testing::Eq(0));
+ EXPECT_THAT(__last_method_name, testing::StrEq("MigrateLegacyAll"));
+}
+
+TEST_F(App2extInterfaceTest, Get) {
+ // wrong parameter
+ char* ret = app2ext_usr_getname_image(nullptr, 0);
+ EXPECT_THAT(ret, testing::Eq(nullptr));
+ ret = app2ext_usr_get_image_path(nullptr, 0);
+ EXPECT_THAT(ret, testing::Eq(nullptr));
+
+ ret = app2ext_usr_getname_image("not.exists.package", 0);
+ EXPECT_TRUE(ret != nullptr);
+}
+
+}
\ No newline at end of file