Add unit tests skeleton 32/234232/8
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 22 May 2020 12:48:22 +0000 (21:48 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 28 May 2020 06:05:43 +0000 (15:05 +0900)
Change-Id: Iaa5130f16e1eb4a3c6b06c3cc9579164ae565467
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
Makefile.am
configure.ac
ism/tests/Makefile.am [new file with mode: 0644]
ism/tests/ecore_imf_unittests.cpp [new file with mode: 0644]
ism/tests/main.cpp [new file with mode: 0644]
packaging/isf.spec

index f8d9e02..305ab06 100644 (file)
@@ -34,7 +34,7 @@ EXTRA_DIST            = config.rpath \
                          intltool-update.in
 
 AUTOMAKE_OPTIONS       = gnu
-SUBDIRS                = ism/src ism/utils ism/modules ism/configs po ism/extras ism/data ism/demos
+SUBDIRS                = ism/src ism/utils ism/modules ism/configs po ism/extras ism/data ism/demos ism/tests
 
 MAINTAINERCLEANFILES   = Makefile.in \
                          aclocal.m4 \
index 36e4dd7..f942941 100644 (file)
@@ -382,6 +382,9 @@ PKG_CHECK_MODULES(SYSTEMD, [libsystemd],
                   [ISF_HAS_SYSTEMD=yes],
                   [ISF_HAS_SYSTEMD=no])
 
+# Check gmock
+PKG_CHECK_MODULES(GMOCK, [gmock])
+
 if test "$ISF_HAS_VCONF" = "yes"; then
   AC_DEFINE(HAVE_VCONF,1,[Have VConf functions.])
 fi
@@ -911,6 +914,7 @@ AC_CONFIG_FILES([Makefile
                  ism/extras/kbd_mode_changer/Makefile
                  ism/extras/pkgmgr_parser/Makefile
                  ism/demos/Makefile
+                 ism/tests/Makefile
                  intltool-extract
                  intltool-merge
                  intltool-update
diff --git a/ism/tests/Makefile.am b/ism/tests/Makefile.am
new file mode 100644 (file)
index 0000000..699ceb0
--- /dev/null
@@ -0,0 +1,43 @@
+MAINTAINERCLEANFILES = Makefile.in
+CLEANFILES           = *.bak
+
+AM_CPPFLAGS = -I$(top_builddir) \
+           -I$(top_builddir)/ism/src \
+           -I$(top_srcdir) \
+           -I$(top_srcdir)/ism/src \
+           -I$(top_srcdir)/ism/intl \
+           -I$(top_srcdir)/ism/data \
+           -I$(top_srcdir)/ism/utils \
+           -I$(top_srcdir)/ism/extras/kbd_mode_changer/include \
+           -I$(includedir) \
+           -DSCIM_DATADIR=\"@SCIM_DATADIR@\" \
+           -DSCIM_LOCALEDIR=\"@SCIM_LOCALEDIR@\" \
+           -DSCIM_SYSCONFDIR=\"@SCIM_SYSCONFDIR@\" \
+           -DSCIM_LIBEXECDIR=\"@SCIM_LIBEXECDIR@\" \
+           -DSCIM_ICONDIR=\"@SCIM_ICONDIR@\" \
+           -DSCIM_MODULE_PATH=\"@SCIM_MODULE_PATH@\" \
+           -DSCIM_TEMPDIR=\"@SCIM_TEMPDIR@\"
+
+
+noinst_HEADERS =
+
+ISF_TESTS = isf-tests
+
+appexecdir            = /usr/bin/
+appexec_PROGRAMS      = $(ISF_TESTS)
+
+isf_tests_SOURCES  = main.cpp ecore_imf_unittests.cpp
+
+isf_tests_CXXFLAGS = @GMOCK_CFLAGS@ \
+                     @ECORE_IMF_CFLAGS@ \
+                     @ECORE_EVAS_CFLAGS@ \
+                     @EVAS_CFLAGS@ \
+                     -fPIE
+
+isf_tests_LDFLAGS  = @GMOCK_LIBS@ -rpath $(libdir)\
+                     @ECORE_IMF_LIBS@ \
+                     @ECORE_EVAS_LIBS@ \
+                     @EVAS_LIBS@ \
+                     -pie
+
+isf_tests_LDADD    =
diff --git a/ism/tests/ecore_imf_unittests.cpp b/ism/tests/ecore_imf_unittests.cpp
new file mode 100644 (file)
index 0000000..2905198
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+ * ISF(Input Service Framework)
+ *
+ * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
+ * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jihoon Kim <jihoon48.kim@samsung.com>, Inhong Han <inhong1.han@samsung.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+#include <gtest/gtest.h>
+#include <Ecore_IMF.h>
+#include <Ecore_Evas.h>
+#include <Evas.h>
+#include <Ecore.h>
+
+#define WIDTH 480
+#define HEIGHT 800
+
+namespace {
+
+static bool callback_called = false;
+static Ecore_IMF_Input_Panel_State input_panel_state = ECORE_IMF_INPUT_PANEL_STATE_HIDE;
+
+static void STOP_LOOP();
+static void WAIT_FOR_CALLBACK();
+
+class EcoreIMFContextTest : public testing::Test {
+    public:
+        virtual void SetUp() {
+            setenv("ECORE_IMF_MODULE", "wayland", 1);
+            setenv("WAYLAND_DISPLAY", "wayland-0", 1);
+            setenv("XDG_RUNTIME_DIR", "/run", 1);
+
+            callback_called = false;
+            int ret;
+
+            ret = ecore_evas_init();
+            ASSERT_NE(ret, 0);
+
+            ret = ecore_imf_init();
+            ASSERT_NE(ret, 0);
+        }
+        virtual void TearDown() {
+            ecore_imf_shutdown();
+            ecore_evas_shutdown();
+        }
+
+        Ecore_Timer *timer_exit = nullptr;
+};
+
+static Eina_Bool _timeout_timer_cb(void *data)
+{
+    printf("timeout\n");
+    STOP_LOOP();
+
+   return ECORE_CALLBACK_DONE;
+}
+
+static void _input_panel_state_cb (void *data, Ecore_IMF_Context *ctx, int value)
+{
+    int x, y, w, h;
+
+    input_panel_state = (Ecore_IMF_Input_Panel_State)value;
+
+    if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
+        ecore_imf_context_input_panel_geometry_get (ctx, &x, &y, &w, &h);
+        printf ("Input panel is shown. ctx : %p\n", ctx);
+        printf ("x : %d, y : %d, w : %d, h : %d\n", x, y, w, h);
+    } else if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
+        printf ("Input panel is hidden. ctx : %p\n", ctx);
+    } else if (value == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW) {
+        printf ("Input panel will be shown. ctx : %p\n", ctx);
+    }
+
+    callback_called = true;
+
+    STOP_LOOP();
+}
+
+static void STOP_LOOP()
+{
+    ecore_main_loop_quit();
+}
+
+static void WAIT_FOR_CALLBACK()
+{
+    ecore_main_loop_begin();
+}
+
+/**
+ * @testcase        ecore_imf_context_add_p
+ * @since           2.4
+ * @description     Positive UTC of ecore_imf_context_add().
+ */
+TEST_F(EcoreIMFContextTest, utc_ecore_imf_context_add_p)
+{
+    const char *ctx_id = ecore_imf_context_default_id_get();
+    ASSERT_NE(ctx_id, nullptr);
+
+    Ecore_IMF_Context *ctx = ecore_imf_context_add(ctx_id);
+    EXPECT_NE(ctx, nullptr);
+}
+
+/**
+ * @testcase        ecore_imf_context_add_n
+ * @since           2.4
+ * @description     Negative UTC of ecore_imf_context_add().
+ */
+TEST_F(EcoreIMFContextTest, utc_ecore_imf_context_add_n)
+{
+    Ecore_IMF_Context *ctx = ecore_imf_context_add(NULL);
+    EXPECT_EQ(ctx, nullptr);
+}
+
+TEST_F(EcoreIMFContextTest, utc_ime_show_in_canvas)
+{
+    callback_called = false;
+    input_panel_state = ECORE_IMF_INPUT_PANEL_STATE_HIDE;
+
+    int ret = ecore_evas_init();
+    ASSERT_NE(ret, 0);
+
+    const char *ctx_id = ecore_imf_context_default_id_get();
+    ASSERT_NE(ctx_id, nullptr);
+
+    Ecore_IMF_Context *ctx = ecore_imf_context_add(ctx_id);
+    ASSERT_NE(ctx, nullptr);
+
+    Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
+    ASSERT_NE(ee, nullptr);
+
+    ecore_evas_show(ee);
+
+    Evas *evas = ecore_evas_get(ee);
+    ASSERT_NE(evas, nullptr);
+
+    evas_focus_in(evas);
+
+    Evas_Object *bg = evas_object_rectangle_add(evas);
+    evas_object_resize(bg, WIDTH, HEIGHT);
+    evas_object_color_set(bg, 255, 255, 255, 255);
+    evas_object_show(bg);
+
+    ecore_imf_context_client_canvas_set(ctx, evas);
+    ecore_imf_context_focus_in(ctx);
+
+    timer_exit = ecore_timer_add(1.5, _timeout_timer_cb, NULL);
+
+    ecore_imf_context_input_panel_event_callback_add(ctx, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _input_panel_state_cb, NULL);
+
+    WAIT_FOR_CALLBACK();
+
+    if (bg)
+        evas_object_del(bg);
+
+    ecore_evas_free(ee);
+
+    EXPECT_EQ(callback_called, true);
+}
+
+TEST_F(EcoreIMFContextTest, utc_ime_show_in_canvas_no_window_show)
+{
+    callback_called = false;
+    input_panel_state = ECORE_IMF_INPUT_PANEL_STATE_HIDE;
+
+    int ret = ecore_evas_init();
+    ASSERT_NE(ret, 0);
+
+    const char *ctx_id = ecore_imf_context_default_id_get();
+    ASSERT_NE(ctx_id, nullptr);
+
+    Ecore_IMF_Context *ctx = ecore_imf_context_add(ctx_id);
+    ASSERT_NE(ctx, nullptr);
+
+    Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
+    ASSERT_NE(ee, nullptr);
+
+    Evas *evas = ecore_evas_get(ee);
+    ASSERT_NE(evas, nullptr);
+
+    evas_focus_in(evas);
+
+    Evas_Object *bg = evas_object_rectangle_add(evas);
+    evas_object_resize(bg, WIDTH, HEIGHT);
+    evas_object_color_set(bg, 255, 255, 255, 255);
+    evas_object_show(bg);
+
+    // no call ecore_evas_show() intentionally for testing
+
+    timer_exit = ecore_timer_add(1.5, _timeout_timer_cb, NULL);
+
+    ecore_imf_context_client_canvas_set(ctx, evas);
+    ecore_imf_context_focus_in(ctx);
+
+    ecore_imf_context_input_panel_event_callback_add(ctx, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _input_panel_state_cb, NULL);
+
+    WAIT_FOR_CALLBACK();
+
+    Ecore_IMF_Input_Panel_State input_panel_state = ecore_imf_context_input_panel_state_get(ctx);
+
+    evas_object_del(bg);
+    ecore_evas_free(ee);
+
+    EXPECT_EQ(callback_called, false);
+    EXPECT_EQ(input_panel_state, ECORE_IMF_INPUT_PANEL_STATE_HIDE);
+}
+
+TEST_F(EcoreIMFContextTest, utc_ime_show_in_client_window)
+{
+    callback_called = false;
+    input_panel_state = ECORE_IMF_INPUT_PANEL_STATE_HIDE;
+
+    int ret = ecore_evas_init();
+    ASSERT_NE(ret, 0);
+
+    const char *ctx_id = ecore_imf_context_default_id_get();
+    ASSERT_NE(ctx_id, nullptr);
+
+    Ecore_IMF_Context *ctx = ecore_imf_context_add(ctx_id);
+    ASSERT_NE(ctx, nullptr);
+
+    Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
+    ASSERT_NE(ee, nullptr);
+
+    ecore_evas_show(ee);
+
+    Evas *evas = ecore_evas_get(ee);
+
+    Evas_Object *bg = evas_object_rectangle_add(evas);
+    evas_object_resize(bg, WIDTH, HEIGHT);
+    evas_object_color_set(bg, 255, 255, 255, 255);
+    evas_object_show(bg);
+
+    timer_exit = ecore_timer_add(1.5, _timeout_timer_cb, NULL);
+
+    ecore_imf_context_client_window_set(ctx, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(evas)));
+    ecore_imf_context_focus_in(ctx);
+
+    ecore_imf_context_input_panel_event_callback_add(ctx, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _input_panel_state_cb, NULL);
+
+    WAIT_FOR_CALLBACK();
+
+    evas_object_del(bg);
+    ecore_evas_free(ee);
+
+    EXPECT_EQ(callback_called, true);
+    EXPECT_EQ(input_panel_state, ECORE_IMF_INPUT_PANEL_STATE_SHOW);
+}
+
+} // namespace
diff --git a/ism/tests/main.cpp b/ism/tests/main.cpp
new file mode 100644 (file)
index 0000000..a37d671
--- /dev/null
@@ -0,0 +1,7 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv) {
+    testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}
index 79b19a1..80543da 100644 (file)
@@ -46,6 +46,7 @@ BuildRequires:  pkgconfig(capi-appfw-package-manager)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(notification)
+BuildRequires:  pkgconfig(gmock)
 Requires(postun): /sbin/ldconfig
 Requires:      org.tizen.isf-kbd-mode-changer
 
@@ -70,6 +71,14 @@ Requires: %{name} = %{version}-%{release}
 %description -n org.tizen.isf-kbd-mode-changer
 Keyboard mode changer application
 
+%package unittests
+Summary: Unit test cases for isf
+Group: Graphics & UI Framework/Input
+Requires: %{name} = %{version}-%{release}
+
+%description unittests
+Unit test cases for isf
+
 %prep
 %setup -q
 
@@ -167,3 +176,7 @@ mkdir -p %{TZ_SYS_RO_APP}/org.tizen.isf-kbd-mode-changer
 %license COPYING
 %{TZ_SYS_RO_PACKAGES}/org.tizen.isf-kbd-mode-changer.xml
 %{APP_PREFIX}/*
+
+%files unittests
+%defattr(-,root,root,-)
+%{_bindir}/*