Add unittest 87/238387/4
authormk5004.lee <mk5004.lee@samsung.com>
Mon, 13 Jul 2020 08:07:41 +0000 (17:07 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Wed, 22 Jul 2020 08:30:20 +0000 (17:30 +0900)
Change-Id: I555fe2cb3f4b6f1fcdcdad68be0d77121ea42ce3
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
22 files changed:
CMakeLists.txt
packaging/libshortcut.spec
test/Makefile [deleted file]
test/application.c [deleted file]
test/homescreen.c [deleted file]
test/icon.c [deleted file]
test/shortcut.c [deleted file]
tests/CMakeLists.txt [new file with mode: 0644]
tests/mock/mock_hook.h [new file with mode: 0644]
tests/mock/module_mock.h [new file with mode: 0644]
tests/mock/system_info_mock.cc [new file with mode: 0644]
tests/mock/system_info_mock.h [new file with mode: 0644]
tests/mock/test_fixture.cc [new file with mode: 0644]
tests/mock/test_fixture.h [new file with mode: 0644]
tests/test/Makefile [new file with mode: 0644]
tests/test/application.c [new file with mode: 0644]
tests/test/homescreen.c [new file with mode: 0644]
tests/test/icon.c [new file with mode: 0644]
tests/test/shortcut.c [new file with mode: 0644]
tests/unit_tests/CMakeLists.txt [new file with mode: 0644]
tests/unit_tests/src/test_main.cc [new file with mode: 0644]
tests/unit_tests/src/test_shortcut_manager.cc [new file with mode: 0644]

index ea60a32bc2411a988b08ab5c3c3460abc2daac4e..f8dd624cbae4bb72573bc66acf63773c55c69e1c 100644 (file)
@@ -2,5 +2,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 set(CMAKE_SKIP_BUILD_RPATH true)
 
-ADD_SUBDIRECTORY("pkgmgr_shortcut")
-ADD_SUBDIRECTORY("lib")
+ADD_SUBDIRECTORY(pkgmgr_shortcut)
+ADD_SUBDIRECTORY(lib)
+ADD_SUBDIRECTORY(tests)
index 297bb19ef6d9b9e971be2cbaa867703d0547220b..69320b6f9e55643c884383ecae6f67fa4d6b165f 100644 (file)
@@ -21,10 +21,38 @@ BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(gmock)
+
+%if 0%{?gcov:1}
+BuildRequires:  lcov
+BuildRequires:  zip
+%endif
 
 %description
 [Shortcut] AddToHome feature supporting library for menu/home screen developers.
 
+%package devel
+Summary:    AddToHome feature supporting library development files
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+
+%description devel
+[Shortcut] AddToHome feature supporting library for menu/home screen developers(dev).
+
+#################################################
+# capi-appfw-app-common-unittests
+#################################################
+%package -n shortcut_unittests
+Summary:    GTest for shortcut API
+Group:      Development/Libraries
+Requires:   %{name}
+
+%description -n shortcut_unittests
+GTest for shortcut API
+
+#################################################
+# gcov
+#################################################
 %if 0%{?gcov:1}
 %package gcov
 Summary:  Shortcut API(gcov)
@@ -34,14 +62,6 @@ Group:    System/API
 gcov objects of an Shortcut library
 %endif
 
-%package devel
-Summary:    AddToHome feature supporting library development files
-Group:      Development/Libraries
-Requires:   %{name} = %{version}-%{release}
-
-%description devel
-[Shortcut] AddToHome feature supporting library for menu/home screen developers(dev).
-
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -67,6 +87,15 @@ mkdir -p gcov-obj
 find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
 %endif
 
+%check
+ctest --output-on-failure %{?_smp_mflags}
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -q -d . -o shortcut.info
+genhtml shortcut.info -o shortcut.out
+zip -r shortcut.zip shortcut.out
+install -m 0644 shortcut.zip %{buildroot}%{_datadir}/gcov/badge.zip
+%endif
+
 %install
 rm -rf %{buildroot}
 
@@ -107,9 +136,16 @@ fi
 %{_libdir}/pkgconfig/shortcut.pc
 %{_libdir}/libshortcut.so
 
+#################################################
+# shortcut_unittests
+#################################################
+%files -n shortcut_unittests
+%{_bindir}/shortcut_unittests
 
+#################################################
+# gcov
+#################################################
 %if 0%{?gcov:1}
 %files gcov
-%{_datadir}/gcov/obj/*
+%{_datadir}/gcov/*
 %endif
-# End of a file
diff --git a/test/Makefile b/test/Makefile
deleted file mode 100644 (file)
index abe5c1b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-all:
-       @gcc homescreen.c -Wall -o homescreen `pkg-config ecore elementary shortcut --cflags --libs`
-       @gcc application.c -Wall -o application `pkg-config ecore elementary shortcut --cflags --libs`
-       @gcc shortcut.c -Wall -o shortcut `pkg-config ecore elementary shortcut --cflags --libs`
diff --git a/test/application.c b/test/application.c
deleted file mode 100644 (file)
index 9d5f9b5..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2011 - 2016 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 <Elementary.h>
-#include <shortcut.h>
-
-static int result_cb(int ret, int pid, void *data)
-{
-       printf("Client: Return %d (%d)\n", ret, pid);
-       /* elm_exit(); */
-       return 0;
-}
-
-static Eina_Bool shortcut_add_cb(void *data)
-{
-       int ret;
-
-       ret = add_to_home_shortcut("pkgname", "MyName", 0, "/usr/bin/true", "/opt/share/image/what.png", result_cb, NULL);
-       printf("Client: shortcut_add_to_home returns: %d\n", ret);
-
-       ret = add_to_home_dynamicbox("pkgname", "MyName", 0, "/usr/bin/true", "/opt/share/image/what.png", 1.0f, result_cb, NULL);
-       printf("Client: shortcut_add_to_home_with_period returns: %d\n", ret);
-
-       return ECORE_CALLBACK_RENEW;
-}
-
-int elm_main(int argc, char *argv[])
-{
-       Ecore_Timer *timer;
-
-       timer = ecore_timer_add(3.0f, shortcut_add_cb, NULL);
-       if (!timer)
-               printf("Failed to add a timer\n");
-
-       elm_run();
-       elm_shutdown();
-
-       return 0;
-}
-
-ELM_MAIN()
-/* End of a file */
diff --git a/test/homescreen.c b/test/homescreen.c
deleted file mode 100644 (file)
index be4858b..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2011 - 2016 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 <Elementary.h>
-#include <shortcut.h>
-
-int shortcut_request_cb(const char *pkgname, const char *name, int type, const char *exec, const char *icon, int pid, double period, void *data)
-{
-       printf("SERVER: name: %s, type: %d, exec: %s, icon: %s, pid: %d, data: %p, period: %lf\n",
-               name, type, exec, icon, pid, data, period);
-       return 0;
-}
-
-int elm_main(int argc, char *argv[])
-{
-       shortcut_set_request_cb(shortcut_request_cb, NULL);
-
-       elm_run();
-       elm_shutdown();
-
-       return 0;
-}
-
-ELM_MAIN()
-/* End of a file */
-
diff --git a/test/icon.c b/test/icon.c
deleted file mode 100644 (file)
index c5a8cb2..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2011 - 2016 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 <Elementary.h>
-#include <shortcut.h>
-#include <tzplatform_config.h>
-
-#define PATH_FMT_RO_ICONS_ROOT tzplatform_getenv(TZ_SYS_RO_ICONS)
-#define PATH_FMT_USER_SHARE_ROOT tzplatform_getenv(TZ_USER_SHARE)
-#define TIZEN_PATH_MAX 1024
-
-static int result_cb(struct shortcut_icon *handle, int ret, void *data)
-{
-       printf("Client: Return %d (%p)\n", ret, handle);
-       return 0;
-}
-
-static Eina_Bool test_main(void *data)
-{
-       struct shortcut_icon *handle;
-       static int idx = 0;
-       int ret;
-       char filename[256];
-       int type;
-       char path[TIZEN_PATH_MAX] = {0, };
-
-       idx++;
-
-       handle = shortcut_icon_request_create();
-       if (!handle) {
-               printf("Failed to create a request\n");
-               return ECORE_CALLBACK_RENEW;
-       }
-
-       printf("Test: %d\n", idx);
-       snprintf(path, TIZEN_PATH_MAX, "%s/default/small/org.tizen.music-player.png", PATH_FMT_RO_ICONS_ROOT);
-       ret = shortcut_icon_request_set_info(handle, NULL, SHORTCUT_ICON_TYPE_IMAGE, DEFAULT_ICON_PART, path, NULL, NULL);
-       printf("NAME set_info: %d\n", ret);
-
-       snprintf(filename, sizeof(filename), "App Name %d", idx);
-       ret = shortcut_icon_request_set_info(handle, NULL, SHORTCUT_ICON_TYPE_TEXT, DEFAULT_NAME_PART, filename, NULL, NULL);
-       printf("TEXT set_info: %d\n", ret);
-
-       snprintf(filename, sizeof(filename), "%s/live_magazine/always/out%d.png", PATH_FMT_USER_SHARE_ROOT, idx);
-
-       switch (idx % 7) {
-       case 0: type = DYNAMICBOX_TYPE_1x1; break;
-       case 1: type = DYNAMICBOX_TYPE_2x1; break;
-       case 2: type = DYNAMICBOX_TYPE_2x2; break;
-       case 3: type = DYNAMICBOX_TYPE_4x1; break;
-       case 4: type = DYNAMICBOX_TYPE_4x2; break;
-       case 5: type = DYNAMICBOX_TYPE_4x3; break;
-       case 6: type = DYNAMICBOX_TYPE_4x4; break;
-       default: type = DYNAMICBOX_TYPE_1x1; break;
-       }
-
-       ret = shortcut_icon_request_send(handle, type, NULL, NULL, filename, result_cb, NULL);
-       printf("request: %d\n", ret);
-
-       ret = shortcut_icon_request_destroy(handle);
-       printf("destroy: %d\n", ret);
-       return ECORE_CALLBACK_RENEW;
-}
-
-static int initialized_cb(int status, void *data)
-{
-       printf("Hello initializer\n");
-       return 0;
-}
-
-int elm_main(int argc, char *argv[])
-{
-       shortcut_icon_service_init(NULL, NULL);
-
-       ecore_timer_add(5.0f, test_main, NULL);
-
-       elm_run();
-       shortcut_icon_service_fini();
-       elm_shutdown();
-       return 0;
-}
-
-ELM_MAIN()
-/* End of a file */
diff --git a/test/shortcut.c b/test/shortcut.c
deleted file mode 100644 (file)
index e849e5b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2011 - 2016 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 <Elementary.h>
-#include <shortcut.h>
-
-static int shortcut_list_cb(const char *appid, const char *icon, const char *name, const char *extra_key, const char *extra_data, void *data)
-{
-       printf("appid[%s] icon[%s], name[%s] extra_key[%s], extra_ata[%s]\n", appid, icon, name, extra_key, extra_data);
-       return 0;
-}
-
-int elm_main(int argc, char *argv[])
-{
-       int ret;
-       ret = shortcut_get_list(NULL, shortcut_list_cb, NULL);
-       if (ret < 0)
-               printf("Error: %d\n", ret);
-
-       elm_run();
-       elm_shutdown();
-
-       return 0;
-}
-
-ELM_MAIN()
-/* End of a file */
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..449cb2a
--- /dev/null
@@ -0,0 +1,8 @@
+IF(NOT DEFINED MINIMUM_BUILD)
+ENABLE_TESTING()
+SET(SHORTCUT_UNIT_TESTS shortcut_unittests)
+ADD_TEST(NAME ${SHORTCUT_UNIT_TESTS} COMMAND ${SHORTCUT_UNIT_TESTS})
+
+ADD_SUBDIRECTORY(unit_tests)
+ADD_DEPENDENCIES(${SHORTCUT_UNIT_TESTS} shortcut)
+ENDIF(NOT DEFINED MINIMUM_BUILD)
diff --git a/tests/mock/mock_hook.h b/tests/mock/mock_hook.h
new file mode 100644 (file)
index 0000000..79831d7
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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 MOCK_MOCK_HOOK_H_
+#define 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  // MOCK_MOCK_HOOK_H_
diff --git a/tests/mock/module_mock.h b/tests/mock/module_mock.h
new file mode 100644 (file)
index 0000000..0934014
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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 MOCK_MODULE_MOCK_H_
+#define MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+  virtual ~ModuleMock() {}
+};
+
+#endif  // MOCK_MODULE_MOCK_H_
diff --git a/tests/mock/system_info_mock.cc b/tests/mock/system_info_mock.cc
new file mode 100644 (file)
index 0000000..cd6917e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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 "system_info_mock.h"
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int system_info_get_platform_bool(const char* arg0, bool* arg1) {
+  return MOCK_HOOK_P2(SystemInfoMock, system_info_get_platform_bool, arg0, arg1);
+}
diff --git a/tests/mock/system_info_mock.h b/tests/mock/system_info_mock.h
new file mode 100644 (file)
index 0000000..eecbc52
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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 MOCK_SYSTEM_INFO_MOCK_H_
+#define MOCK_SYSTEM_INFO_MOCK_H_
+
+#include <tizen.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class SystemInfoMock : public virtual ModuleMock {
+ public:
+  virtual ~SystemInfoMock() {}
+
+  MOCK_METHOD2(system_info_get_platform_bool, int(const char*, bool*));
+};
+
+#endif  // MOCK_SYSTEM_INFO_MOCK_H_
diff --git a/tests/mock/test_fixture.cc b/tests/mock/test_fixture.cc
new file mode 100644 (file)
index 0000000..27f5666
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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 "test_fixture.h"
+
+#include <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
diff --git a/tests/mock/test_fixture.h b/tests/mock/test_fixture.h
new file mode 100644 (file)
index 0000000..db223f1
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 MOCK_TEST_FIXTURE_H_
+#define MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "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  // MOCK_TEST_FIXTURE_H_
diff --git a/tests/test/Makefile b/tests/test/Makefile
new file mode 100644 (file)
index 0000000..abe5c1b
--- /dev/null
@@ -0,0 +1,4 @@
+all:
+       @gcc homescreen.c -Wall -o homescreen `pkg-config ecore elementary shortcut --cflags --libs`
+       @gcc application.c -Wall -o application `pkg-config ecore elementary shortcut --cflags --libs`
+       @gcc shortcut.c -Wall -o shortcut `pkg-config ecore elementary shortcut --cflags --libs`
diff --git a/tests/test/application.c b/tests/test/application.c
new file mode 100644 (file)
index 0000000..9d5f9b5
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 - 2016 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 <Elementary.h>
+#include <shortcut.h>
+
+static int result_cb(int ret, int pid, void *data)
+{
+       printf("Client: Return %d (%d)\n", ret, pid);
+       /* elm_exit(); */
+       return 0;
+}
+
+static Eina_Bool shortcut_add_cb(void *data)
+{
+       int ret;
+
+       ret = add_to_home_shortcut("pkgname", "MyName", 0, "/usr/bin/true", "/opt/share/image/what.png", result_cb, NULL);
+       printf("Client: shortcut_add_to_home returns: %d\n", ret);
+
+       ret = add_to_home_dynamicbox("pkgname", "MyName", 0, "/usr/bin/true", "/opt/share/image/what.png", 1.0f, result_cb, NULL);
+       printf("Client: shortcut_add_to_home_with_period returns: %d\n", ret);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+int elm_main(int argc, char *argv[])
+{
+       Ecore_Timer *timer;
+
+       timer = ecore_timer_add(3.0f, shortcut_add_cb, NULL);
+       if (!timer)
+               printf("Failed to add a timer\n");
+
+       elm_run();
+       elm_shutdown();
+
+       return 0;
+}
+
+ELM_MAIN()
+/* End of a file */
diff --git a/tests/test/homescreen.c b/tests/test/homescreen.c
new file mode 100644 (file)
index 0000000..be4858b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011 - 2016 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 <Elementary.h>
+#include <shortcut.h>
+
+int shortcut_request_cb(const char *pkgname, const char *name, int type, const char *exec, const char *icon, int pid, double period, void *data)
+{
+       printf("SERVER: name: %s, type: %d, exec: %s, icon: %s, pid: %d, data: %p, period: %lf\n",
+               name, type, exec, icon, pid, data, period);
+       return 0;
+}
+
+int elm_main(int argc, char *argv[])
+{
+       shortcut_set_request_cb(shortcut_request_cb, NULL);
+
+       elm_run();
+       elm_shutdown();
+
+       return 0;
+}
+
+ELM_MAIN()
+/* End of a file */
+
diff --git a/tests/test/icon.c b/tests/test/icon.c
new file mode 100644 (file)
index 0000000..c5a8cb2
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011 - 2016 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 <Elementary.h>
+#include <shortcut.h>
+#include <tzplatform_config.h>
+
+#define PATH_FMT_RO_ICONS_ROOT tzplatform_getenv(TZ_SYS_RO_ICONS)
+#define PATH_FMT_USER_SHARE_ROOT tzplatform_getenv(TZ_USER_SHARE)
+#define TIZEN_PATH_MAX 1024
+
+static int result_cb(struct shortcut_icon *handle, int ret, void *data)
+{
+       printf("Client: Return %d (%p)\n", ret, handle);
+       return 0;
+}
+
+static Eina_Bool test_main(void *data)
+{
+       struct shortcut_icon *handle;
+       static int idx = 0;
+       int ret;
+       char filename[256];
+       int type;
+       char path[TIZEN_PATH_MAX] = {0, };
+
+       idx++;
+
+       handle = shortcut_icon_request_create();
+       if (!handle) {
+               printf("Failed to create a request\n");
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       printf("Test: %d\n", idx);
+       snprintf(path, TIZEN_PATH_MAX, "%s/default/small/org.tizen.music-player.png", PATH_FMT_RO_ICONS_ROOT);
+       ret = shortcut_icon_request_set_info(handle, NULL, SHORTCUT_ICON_TYPE_IMAGE, DEFAULT_ICON_PART, path, NULL, NULL);
+       printf("NAME set_info: %d\n", ret);
+
+       snprintf(filename, sizeof(filename), "App Name %d", idx);
+       ret = shortcut_icon_request_set_info(handle, NULL, SHORTCUT_ICON_TYPE_TEXT, DEFAULT_NAME_PART, filename, NULL, NULL);
+       printf("TEXT set_info: %d\n", ret);
+
+       snprintf(filename, sizeof(filename), "%s/live_magazine/always/out%d.png", PATH_FMT_USER_SHARE_ROOT, idx);
+
+       switch (idx % 7) {
+       case 0: type = DYNAMICBOX_TYPE_1x1; break;
+       case 1: type = DYNAMICBOX_TYPE_2x1; break;
+       case 2: type = DYNAMICBOX_TYPE_2x2; break;
+       case 3: type = DYNAMICBOX_TYPE_4x1; break;
+       case 4: type = DYNAMICBOX_TYPE_4x2; break;
+       case 5: type = DYNAMICBOX_TYPE_4x3; break;
+       case 6: type = DYNAMICBOX_TYPE_4x4; break;
+       default: type = DYNAMICBOX_TYPE_1x1; break;
+       }
+
+       ret = shortcut_icon_request_send(handle, type, NULL, NULL, filename, result_cb, NULL);
+       printf("request: %d\n", ret);
+
+       ret = shortcut_icon_request_destroy(handle);
+       printf("destroy: %d\n", ret);
+       return ECORE_CALLBACK_RENEW;
+}
+
+static int initialized_cb(int status, void *data)
+{
+       printf("Hello initializer\n");
+       return 0;
+}
+
+int elm_main(int argc, char *argv[])
+{
+       shortcut_icon_service_init(NULL, NULL);
+
+       ecore_timer_add(5.0f, test_main, NULL);
+
+       elm_run();
+       shortcut_icon_service_fini();
+       elm_shutdown();
+       return 0;
+}
+
+ELM_MAIN()
+/* End of a file */
diff --git a/tests/test/shortcut.c b/tests/test/shortcut.c
new file mode 100644 (file)
index 0000000..e849e5b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 - 2016 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 <Elementary.h>
+#include <shortcut.h>
+
+static int shortcut_list_cb(const char *appid, const char *icon, const char *name, const char *extra_key, const char *extra_data, void *data)
+{
+       printf("appid[%s] icon[%s], name[%s] extra_key[%s], extra_ata[%s]\n", appid, icon, name, extra_key, extra_data);
+       return 0;
+}
+
+int elm_main(int argc, char *argv[])
+{
+       int ret;
+       ret = shortcut_get_list(NULL, shortcut_list_cb, NULL);
+       if (ret < 0)
+               printf("Error: %d\n", ret);
+
+       elm_run();
+       elm_shutdown();
+
+       return 0;
+}
+
+ELM_MAIN()
+/* End of a file */
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..325a58d
--- /dev/null
@@ -0,0 +1,46 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)\r
+PROJECT(shortcut_unittests C CXX)\r
+\r
+INCLUDE(FindPkgConfig)\r
+PKG_CHECK_MODULES(shortcut_unittests REQUIRED\r
+       gmock\r
+       dlog\r
+       sqlite3\r
+       libxml-2.0\r
+       glib-2.0\r
+       db-util\r
+       vconf\r
+       capi-base-common\r
+       aul\r
+       capi-system-info\r
+       libtzplatform-config\r
+)\r
+\r
+FOREACH(flag ${shortcut_unittests_CFLAGS})\r
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")\r
+ENDFOREACH(flag)\r
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline")\r
+\r
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14")\r
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")\r
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")\r
+\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../lib/include)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock)\r
+\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src LIB_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES)\r
+\r
+ADD_EXECUTABLE(${PROJECT_NAME}\r
+       ${SOURCES}\r
+       ${MOCK_SOURCES}\r
+       #${LIB_SOURCES}\r
+)\r
+\r
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}\r
+    ${shortcut_unittests_LDFLAGS}\r
+)\r
+\r
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)\r
diff --git a/tests/unit_tests/src/test_main.cc b/tests/unit_tests/src/test_main.cc
new file mode 100644 (file)
index 0000000..c2eb730
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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 <gmock/gmock.h>
+
+int main(int argc, char** argv) {
+  int ret = -1;
+
+  try {
+    testing::InitGoogleTest(&argc, argv);
+  } catch(...) {
+    std::cout << "Exception occurred" << std::endl;
+  }
+
+  try {
+    ret = RUN_ALL_TESTS();
+  } catch (const ::testing::internal::GoogleTestFailureException& e) {
+    ret = -1;
+    std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
+  }
+
+  return ret;
+}
diff --git a/tests/unit_tests/src/test_shortcut_manager.cc b/tests/unit_tests/src/test_shortcut_manager.cc
new file mode 100644 (file)
index 0000000..8b3e1f6
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+#include <shortcut_manager.h>
+
+#include <memory>
+
+#include "system_info_mock.h"
+#include "test_fixture.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::Invoke;
+
+class Mocks : public ::testing::NiceMock<SystemInfoMock> {};
+
+class ShortcutTest : public TestFixture {
+ public:
+  ShortcutTest() : TestFixture(std::make_unique<Mocks>()) {}
+  virtual ~ShortcutTest() {}
+
+  virtual void SetUp() {
+  }
+
+  virtual void TearDown() {
+  }
+};