mmifw-tests : add connection wait helper function, state change wait helper function 39/264339/1
authorulgal-park <ulgal.park@samsung.com>
Wed, 15 Sep 2021 13:08:07 +0000 (22:08 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 16 Sep 2021 07:36:48 +0000 (16:36 +0900)
Change-Id: I54bc86ec4266a33f80ff31e32d5f6489a0c0ee84

tests/meson.build
tests/mmifw-ipc-test.cpp
tests/mmifw-main-test.cpp
tests/mmifw-tests.h
tests/wait-helper.cpp [new file with mode: 0644]

index 7f6c4cf..92268f1 100644 (file)
@@ -1,7 +1,8 @@
 mmifw_tests_srcs = [
        'mmifw-tests.cpp',
        'mmifw-main-test.cpp',
-       'mmifw-ipc-test.cpp'
+       'mmifw-ipc-test.cpp',
+       'wait-helper.cpp'
        ]
 
 gmock_dep = dependency('gmock', method : 'pkg-config')
index 09078f6..5befc0d 100644 (file)
@@ -98,18 +98,13 @@ TEST_F(MMIFWIpcTest, MMIFWIpcGetVariableBeforeInit)
 
 TEST_F(MMIFWIpcTest, MMIFWIpcGetVariableAfterInit)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
index 9ec3cb5..ba309bd 100644 (file)
@@ -40,6 +40,15 @@ public:
        }
 };
 
+void wait_for_state_change(mmi_handle h, mmi_state state)
+{
+       int timer = 0;
+       while (state != mmi_state_get_current_state(h) && timer < MAX_WAIT_TIME)
+       {
+               ecore_main_loop_iterate();
+               timer++;
+       }
+}
 
 TEST_F(MMIFWMainTest, MMIFWMainInit)
 {
@@ -53,19 +62,12 @@ TEST_F(MMIFWMainTest, MMIFWMainInit)
 
 TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateDestroySuccess)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
-
        if(h){
                mmi_instance_destroy(&h);
                EXPECT_EQ(h, nullptr);
@@ -77,18 +79,13 @@ TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateDestroySuccess)
 
 TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateAndConnectSuccess)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
        
@@ -103,19 +100,12 @@ TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateAndConnectSuccess)
 
 TEST_F(MMIFWMainTest, MMIFWMainInstanceCreateFail)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = NULL;
        mmi_handle h = mmi_instance_create(app_id);
 
        EXPECT_EQ(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
-
        if(h){
                mmi_instance_destroy(&h);
                EXPECT_EQ(h, nullptr);
@@ -147,7 +137,6 @@ _cb_connection(void *data, int type, void *event)
 
 TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListener)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
@@ -155,11 +144,7 @@ TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListener)
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
@@ -183,7 +168,6 @@ TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListener)
 
 TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerFail)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
@@ -191,11 +175,7 @@ TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerFail)
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
@@ -219,7 +199,6 @@ TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerFail)
 
 TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerSecondFail)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
@@ -227,11 +206,7 @@ TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerSecondFail)
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
@@ -255,18 +230,13 @@ TEST_F(MMIFWMainTest, MMIFWMainEventAddSingleListenerSecondFail)
 
 TEST_F(MMIFWMainTest, MMIFWMainRequestSendGetFocus)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
@@ -275,12 +245,6 @@ TEST_F(MMIFWMainTest, MMIFWMainRequestSendGetFocus)
                EXPECT_EQ(mmi_res, MMI_RESULT_SUCCESS);
        }
 
-       while (timer != 150000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
-
        if(h){
                mmi_instance_destroy(&h);
                EXPECT_EQ(h, nullptr);
@@ -292,18 +256,13 @@ TEST_F(MMIFWMainTest, MMIFWMainRequestSendGetFocus)
 
 TEST_F(MMIFWMainTest, MMIFWMainRequestSendSetGetState)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
 
        EXPECT_NE(h, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
@@ -315,22 +274,12 @@ TEST_F(MMIFWMainTest, MMIFWMainRequestSendSetGetState)
                mmi_res  = mmi_request_send_set_state(h, state);
                EXPECT_EQ(mmi_res, MMI_RESULT_SUCCESS);
 
-               while (timer != 150000)
-               {
-                       ecore_main_loop_iterate();
-                       timer++;
-               }
+               wait_for_state_change(h, MMI_STATE_INITIATION);
 
                state = mmi_state_get_current_state(h);
                EXPECT_EQ(state, MMI_STATE_INITIATION);
        }
 
-       while (timer != 150000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
-
        if(h){
                mmi_instance_destroy(&h);
                EXPECT_EQ(h, nullptr);
@@ -342,21 +291,16 @@ TEST_F(MMIFWMainTest, MMIFWMainRequestSendSetGetState)
 
 TEST_F(MMIFWMainTest, MMIFWMainEventRemoveAllListener)
 {
-       int timer = 0;
        int res = mmi_init();
        const char *app_id = "org.tizen.mmi-system-ux-test";
        mmi_handle h = mmi_instance_create(app_id);
        mmi_event_listener * handler = NULL;
        mmi_event_listener * handler2 = NULL;
 
-       EXPECT_NE(h, nullptr);
-               EXPECT_EQ(handler, nullptr);
+               EXPECT_NE(h, nullptr);
+       EXPECT_EQ(handler, nullptr);
 
-       while (timer != 100000)
-       {
-               ecore_main_loop_iterate();
-               timer++;
-       }
+       wait_for_connect();
 
        EXPECT_TRUE(mmi_ipc_is_connected());
 
index d902a2b..29341ab 100644 (file)
 
 #define PRINT printf
 
+#define MAX_WAIT_TIME 300000
+
+extern void wait_for_connect();
+
 using ::testing::TestWithParam;
 using ::testing::Bool;
 using ::testing::Values;
diff --git a/tests/wait-helper.cpp b/tests/wait-helper.cpp
new file mode 100644 (file)
index 0000000..10ac03e
--- /dev/null
@@ -0,0 +1,15 @@
+#include "mmifw.h"
+#include "mmifw-tests.h"
+#include "mmifw-ipc.h"
+
+#include <Ecore.h>
+
+void wait_for_connect()
+{
+       int timer = 0;
+       while (!mmi_ipc_is_connected() && timer < MAX_WAIT_TIME)
+       {
+               ecore_main_loop_iterate();
+               timer++;
+       }
+}
\ No newline at end of file