diff options
author | Inkyun Kil <inkyun.kil@samsung.com> | 2020-10-30 14:58:28 +0900 |
---|---|---|
committer | Inkyun Kil <inkyun.kil@samsung.com> | 2020-11-19 15:57:08 +0900 |
commit | 0159ecc467ad5745ac204a690dbb24001be3981f (patch) | |
tree | c503405d3df4fc00eef602d1197ec7ed11238933 | |
parent | a8a5f55faa8880eff38874ca42d8178ba42e9aa7 (diff) | |
download | minicontrol-0159ecc467ad5745ac204a690dbb24001be3981f.tar.gz minicontrol-0159ecc467ad5745ac204a690dbb24001be3981f.tar.bz2 minicontrol-0159ecc467ad5745ac204a690dbb24001be3981f.zip |
Improve coverage
Change-Id: I9c74a2c5e6e95006db967a1f6770688f139b9335
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
-rw-r--r-- | packaging/minicontrol.spec | 3 | ||||
-rw-r--r-- | unittests/minicontrol_test.cc | 84 | ||||
-rw-r--r-- | unittests/mock/ecore_evas_mock.cc | 42 | ||||
-rw-r--r-- | unittests/mock/ecore_evas_mock.h | 38 | ||||
-rw-r--r-- | unittests/mock/elementary_mock.cc | 15 | ||||
-rw-r--r-- | unittests/mock/elementary_mock.h | 4 | ||||
-rw-r--r-- | unittests/mock/gio_mock.cc | 47 | ||||
-rwxr-xr-x | unittests/mock/gio_mock.h | 42 |
8 files changed, 267 insertions, 8 deletions
diff --git a/packaging/minicontrol.spec b/packaging/minicontrol.spec index 858fbd0..a6866ab 100644 --- a/packaging/minicontrol.spec +++ b/packaging/minicontrol.spec @@ -79,8 +79,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %endif %check -cd unittests -LD_LIBRARY_PATH=../ ctest -V +(cd unittests && LD_LIBRARY_PATH=../ ctest -V) %if 0%{?gcov:1} lcov -c --ignore-errors graph --no-external -q -d . -o minicontrol.info genhtml minicontrol.info -o minicontrol.out diff --git a/unittests/minicontrol_test.cc b/unittests/minicontrol_test.cc index 7931fac..4123696 100644 --- a/unittests/minicontrol_test.cc +++ b/unittests/minicontrol_test.cc @@ -17,11 +17,20 @@ #include <gmock/gmock.h> #include <minicontrol.h> +#include <bundle_cpp.h> #include "mock/elementary_mock.h" +#include "mock/ecore_evas_mock.h" +#include "mock/gio_mock.h" #include "mock/test_fixture.h" -class Mocks : public ::testing::NiceMock<ElementaryMock> {}; +using ::testing::_; +using ::testing::Return; +using namespace tizen_base; + +class Mocks : public ::testing::NiceMock<ElementaryMock>, + public ::testing::NiceMock<GioMock>, + public ::testing::NiceMock<EcoreEvasMock> {}; class MinicontrolTest : public TestFixture { public: @@ -32,7 +41,72 @@ class MinicontrolTest : public TestFixture { virtual void TearDown() {} }; -TEST_F(MinicontrolTest, minicontrol_viewer_add_n) { - Evas_Object* plug = minicontrol_viewer_add(nullptr, "minicontrol_name"); - EXPECT_EQ(plug, nullptr); -}
\ No newline at end of file +static void __event_cb(minicontrol_event_e event, const char *minicontrol_name, + bundle *event_arg, void *user_data) { + +} + +TEST_F(MinicontrolTest, minicontrol_viewer_add) { + auto p = std::unique_ptr<char, decltype(std::free)*>((char*)malloc(1), std::free); + EXPECT_CALL(GetMock<ElementaryMock>(), + elm_plug_add(_)).WillOnce(Return((Evas_Object*)p.get())); + EXPECT_CALL(GetMock<ElementaryMock>(), + elm_plug_connect(_, _, _, _)). + WillOnce(Return(true)); + EXPECT_CALL(GetMock<ElementaryMock>(), + elm_plug_image_object_get(_)). + WillOnce(Return(nullptr)); + EXPECT_CALL(GetMock<EcoreEvasMock>(), + ecore_evas_object_ecore_evas_get(_)). + WillOnce(Return(nullptr)); + EXPECT_CALL(GetMock<EcoreEvasMock>(), + ecore_evas_data_set(_, _, _)). + WillOnce(Return()); + EXPECT_CALL(GetMock<EcoreEvasMock>(), + ecore_evas_callback_delete_request_set(_, _)). + WillOnce(Return()); + EXPECT_CALL(GetMock<EcoreEvasMock>(), + evas_object_event_callback_add(_, _, _, _)). + WillOnce(Return()); + Evas_Object* plug = minicontrol_viewer_add((Evas_Object*)p.get(), "minicontrol_name"); + EXPECT_NE(plug, nullptr); +} + +TEST_F(MinicontrolTest, minicontrol_viewer_send_event) { + GDBusConnection* _conn = (GDBusConnection*)g_object_new(G_TYPE_OBJECT, nullptr); + + EXPECT_CALL(GetMock<GioMock>(), + g_bus_get_sync(_, _, _)). + WillOnce(Return(_conn)); + EXPECT_CALL(GetMock<GioMock>(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillOnce(Return(true)); + + Bundle b; + b.Add("key", "val"); + int ret = minicontrol_viewer_send_event("minicontrol_name", + MINICONTROL_VIEWER_EVENT_SHOW, b.GetHandle()); + EXPECT_EQ(ret, MINICONTROL_ERROR_NONE); +} + +TEST_F(MinicontrolTest, minicontrol_viewer_set_event_cb) { + GDBusConnection* _conn = (GDBusConnection*)g_object_new(G_TYPE_OBJECT, nullptr); + + EXPECT_CALL(GetMock<GioMock>(), + g_bus_get_sync(_, _, _)). + WillRepeatedly(Return(_conn)); + EXPECT_CALL(GetMock<GioMock>(), + g_dbus_connection_emit_signal(_, _, _, _, _, _, _)). + WillRepeatedly(Return(true)); + EXPECT_CALL(GetMock<GioMock>(), + g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _)). + WillOnce(Return(1)); + + int ret = minicontrol_viewer_set_event_cb(__event_cb, nullptr); + EXPECT_EQ(ret, MINICONTROL_ERROR_NONE); +} + +TEST_F(MinicontrolTest, minicontrol_viewer_unset_event_cb) { + int ret = minicontrol_viewer_unset_event_cb(); + EXPECT_EQ(ret, MINICONTROL_ERROR_NONE); +} diff --git a/unittests/mock/ecore_evas_mock.cc b/unittests/mock/ecore_evas_mock.cc new file mode 100644 index 0000000..14fcd7a --- /dev/null +++ b/unittests/mock/ecore_evas_mock.cc @@ -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. + */ + +#include "ecore_evas_mock.h" + +#include "mock_hook.h" +#include "test_fixture.h" + + +extern "C" Ecore_Evas* ecore_evas_object_ecore_evas_get(Evas_Object* arg0) { + return MOCK_HOOK_P1(EcoreEvasMock, ecore_evas_object_ecore_evas_get, arg0); +} + +extern "C" void ecore_evas_data_set(Ecore_Evas* arg0, const char* arg1, + const void* arg2) { + return MOCK_HOOK_P3(EcoreEvasMock, ecore_evas_data_set, arg0, arg1, arg2); +} + +extern "C" void ecore_evas_callback_delete_request_set(Ecore_Evas* arg0, + Ecore_Evas_Event_Cb arg1) { + return MOCK_HOOK_P2(EcoreEvasMock, ecore_evas_callback_delete_request_set, + arg0, arg1); +} + +extern "C" void evas_object_event_callback_add(Evas_Object *eo_obj, + Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data) { + return MOCK_HOOK_P4(EcoreEvasMock, evas_object_event_callback_add, + eo_obj, type, func, data); +}
\ No newline at end of file diff --git a/unittests/mock/ecore_evas_mock.h b/unittests/mock/ecore_evas_mock.h new file mode 100644 index 0000000..0d91de5 --- /dev/null +++ b/unittests/mock/ecore_evas_mock.h @@ -0,0 +1,38 @@ +/* + * 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_ECORE_EVAS_MOCK_H_ +#define MOCK_ECORE_EVAS_MOCK_H_ +#include <gmock/gmock.h> + +#include <Ecore_Evas.h> +#include <Ecore_Evas_Types.h> + +#include "module_mock.h" + +class EcoreEvasMock : public virtual ModuleMock { + public: + virtual ~EcoreEvasMock() {} + + MOCK_METHOD1(ecore_evas_object_ecore_evas_get, Ecore_Evas *(Evas_Object*)); + MOCK_METHOD3(ecore_evas_data_set, void (Ecore_Evas*, const char*, const void*)); + MOCK_METHOD2(ecore_evas_callback_delete_request_set, void (Ecore_Evas*, + Ecore_Evas_Event_Cb)); + MOCK_METHOD4(evas_object_event_callback_add, void (Evas_Object *, + Evas_Callback_Type, Evas_Object_Event_Cb, const void *)); +}; + +#endif // MOCK_ECORE_EVAS_MOCK_H_
\ No newline at end of file diff --git a/unittests/mock/elementary_mock.cc b/unittests/mock/elementary_mock.cc index d581c70..a8c3b67 100644 --- a/unittests/mock/elementary_mock.cc +++ b/unittests/mock/elementary_mock.cc @@ -21,5 +21,18 @@ extern "C" Evas_Object* elm_plug_add(Evas_Object* arg0) { - MOCK_HOOK_P1(ElementaryMock, elm_plug_add, arg0); + return MOCK_HOOK_P1(ElementaryMock, elm_plug_add, arg0); } + +extern "C" Efl_Canvas_Object* elm_plug_image_object_get(const Elm_Plug* arg0) { + return MOCK_HOOK_P1(ElementaryMock, elm_plug_image_object_get, arg0); +} + +extern "C" Eina_Bool elm_plug_connect(Elm_Plug* arg0, const char* arg1, + int arg2, Eina_Bool arg3) { + return MOCK_HOOK_P4(ElementaryMock, elm_plug_connect, arg0, arg1, arg2, arg3); +} + +extern "C" void evas_object_del(Evas_Object *obj) { + return MOCK_HOOK_P1(ElementaryMock, evas_object_del, obj); +}
\ No newline at end of file diff --git a/unittests/mock/elementary_mock.h b/unittests/mock/elementary_mock.h index 948dc4b..4c3480c 100644 --- a/unittests/mock/elementary_mock.h +++ b/unittests/mock/elementary_mock.h @@ -27,6 +27,10 @@ class ElementaryMock : public virtual ModuleMock { virtual ~ElementaryMock() {} MOCK_METHOD1(elm_plug_add, Evas_Object*(Evas_Object*)); + MOCK_METHOD1(evas_object_del, void(Evas_Object*)); + MOCK_METHOD1(elm_plug_image_object_get, Efl_Canvas_Object*(const Elm_Plug*)); + MOCK_METHOD4(elm_plug_connect, Eina_Bool(Elm_Plug* obj, const char* svcname, + int svcnum, Eina_Bool svcsys)); }; #endif // MOCK_ELEMENTARY_MOCK_H_
\ No newline at end of file diff --git a/unittests/mock/gio_mock.cc b/unittests/mock/gio_mock.cc new file mode 100644 index 0000000..410e584 --- /dev/null +++ b/unittests/mock/gio_mock.cc @@ -0,0 +1,47 @@ +/* + * 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); +} + +extern "C" GDBusConnection* g_bus_get_sync(GBusType arg0, + GCancellable* arg1, GError** arg2) { + return MOCK_HOOK_P3(GioMock, g_bus_get_sync, arg0, arg1, arg2); +} diff --git a/unittests/mock/gio_mock.h b/unittests/mock/gio_mock.h new file mode 100755 index 0000000..028dcc9 --- /dev/null +++ b/unittests/mock/gio_mock.h @@ -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 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_METHOD3(g_bus_get_sync, GDBusConnection*(GBusType, GCancellable*, + 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_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_ |