2 * Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include "mmifw-tests.h"
26 #include "mmifw-ipc.h"
29 #include <rpc-port-internal.h>
31 class MMIFWMainTest : public ::testing::Test
34 void SetUp(void) override
38 void TearDown(void) override
43 void wait_for_state_change(mmi_handle h, mmi_state state)
46 while (state != mmi_state_get_current_state(h) && timer < MAX_WAIT_TIME)
48 ecore_main_loop_iterate();
53 TEST_F(MMIFWMainTest, MMIFWMainInit)
63 TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateDestroySuccess)
66 const char *app_id = "org.tizen.mmi-system-ux-test";
67 mmi_handle h = mmi_instance_create(app_id);
69 EXPECT_NE(h, nullptr);
72 mmi_instance_destroy(&h);
73 EXPECT_EQ(h, nullptr);
80 TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateAndConnectSuccess)
83 const char *app_id = "org.tizen.mmi-system-ux-test";
84 mmi_handle h = mmi_instance_create(app_id);
86 EXPECT_NE(h, nullptr);
90 EXPECT_TRUE(mmi_ipc_is_connected());
93 mmi_instance_destroy(&h);
94 EXPECT_EQ(h, nullptr);
101 TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateFail)
103 int res = mmi_init();
104 const char *app_id = NULL;
105 mmi_handle h = mmi_instance_create(app_id);
107 EXPECT_EQ(h, nullptr);
110 mmi_instance_destroy(&h);
111 EXPECT_EQ(h, nullptr);
119 _cb_focus(void *data, int type, void *event)
122 return ECORE_CALLBACK_PASS_ON;
125 return ECORE_CALLBACK_PASS_ON;
129 _cb_connection(void *data, int type, void *event)
132 return ECORE_CALLBACK_PASS_ON;
135 return ECORE_CALLBACK_PASS_ON;
138 TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListener)
140 int res = mmi_init();
141 const char *app_id = "org.tizen.mmi-system-ux-test";
142 mmi_handle h = mmi_instance_create(app_id);
143 mmi_event_listener * handler = NULL;
145 EXPECT_NE(h, nullptr);
148 handler = mmi_event_add_listener(h, MMI_EVENT_CONNECTION, _cb_connection, h);
153 EXPECT_TRUE(mmi_ipc_is_connected());
155 EXPECT_NE(handler, nullptr);
158 mmi_event_remove_listener(h, handler);
161 mmi_instance_destroy(&h);
162 EXPECT_EQ(h, nullptr);
169 TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerFail)
171 int res = mmi_init();
172 const char *app_id = "org.tizen.mmi-system-ux-test";
173 mmi_handle h = mmi_instance_create(app_id);
174 mmi_event_listener * handler =NULL;
176 EXPECT_NE(h, nullptr);
179 handler = mmi_event_add_listener(h, MMI_EVENT_CONNECTION, NULL, NULL);
184 EXPECT_TRUE(mmi_ipc_is_connected());
186 EXPECT_EQ(handler, nullptr);
189 mmi_event_remove_listener(h, handler);
192 mmi_instance_destroy(&h);
193 EXPECT_EQ(h, nullptr);
200 TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerSecondFail)
202 int res = mmi_init();
203 const char *app_id = "org.tizen.mmi-system-ux-test";
204 mmi_handle h = mmi_instance_create(app_id);
205 mmi_event_listener * handler =NULL;
207 EXPECT_NE(h, nullptr);
210 handler = mmi_event_add_listener(h, 100, _cb_connection, NULL);
215 EXPECT_TRUE(mmi_ipc_is_connected());
217 EXPECT_EQ(handler, nullptr);
220 mmi_event_remove_listener(h, handler);
223 mmi_instance_destroy(&h);
224 EXPECT_EQ(h, nullptr);
231 TEST_F(MMIFWMainTest, MMIFWMainRequestSendGetFocus)
233 int res = mmi_init();
234 const char *app_id = "org.tizen.mmi-system-ux-test";
235 mmi_handle h = mmi_instance_create(app_id);
237 EXPECT_NE(h, nullptr);
241 EXPECT_TRUE(mmi_ipc_is_connected());
244 mmi_result mmi_res = mmi_request_send_get_focus(h);
245 EXPECT_EQ(mmi_res, MMI_RESULT_SUCCESS);
249 mmi_instance_destroy(&h);
250 EXPECT_EQ(h, nullptr);
257 TEST_F(MMIFWMainTest, MMIFWMainRequestSendSetGetState)
259 int res = mmi_init();
260 const char *app_id = "org.tizen.mmi-system-ux-test";
261 mmi_handle h = mmi_instance_create(app_id);
263 EXPECT_NE(h, nullptr);
267 EXPECT_TRUE(mmi_ipc_is_connected());
270 mmi_result mmi_res = mmi_request_send_get_focus(h);
271 EXPECT_EQ(mmi_res, MMI_RESULT_SUCCESS);
273 mmi_state state = MMI_STATE_INITIATION;
274 mmi_res = mmi_request_send_set_state(h, state);
275 EXPECT_EQ(mmi_res, MMI_RESULT_SUCCESS);
277 wait_for_state_change(h, MMI_STATE_INITIATION);
279 state = mmi_state_get_current_state(h);
280 EXPECT_EQ(state, MMI_STATE_INITIATION);
284 mmi_instance_destroy(&h);
285 EXPECT_EQ(h, nullptr);
292 TEST_F(MMIFWMainTest, MMIFWMainEventRemoveAllListener)
294 int res = mmi_init();
295 const char *app_id = "org.tizen.mmi-system-ux-test";
296 mmi_handle h = mmi_instance_create(app_id);
297 mmi_event_listener * handler = NULL;
298 mmi_event_listener * handler2 = NULL;
300 EXPECT_NE(h, nullptr);
301 EXPECT_EQ(handler, nullptr);
305 EXPECT_TRUE(mmi_ipc_is_connected());
308 handler = mmi_event_add_listener(h, MMI_EVENT_CONNECTION, _cb_connection, h);
309 handler2 = mmi_event_add_listener(h, MMI_EVENT_FOCUS, _cb_focus, h);
312 EXPECT_NE(handler, nullptr);
313 EXPECT_NE(handler2, nullptr);
316 mmi_event_remove_all_listeners(h);
320 mmi_instance_destroy(&h);
321 EXPECT_EQ(h, nullptr);