[UTC][camera][Non-ACR] Run mainloop for some TCs to improve line coverage 07/289307/4
authorJeongmo Yang <jm80.yang@samsung.com>
Mon, 6 Mar 2023 06:45:18 +0000 (15:45 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 8 Mar 2023 08:42:40 +0000 (17:42 +0900)
Change-Id: Ie194508aabdd4bfc039a6c884cd9d807bd8b3a5b
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
src/utc/camera/CMakeLists.txt
src/utc/camera/utc_media_camera_lifecycle.c
src/utc/camera/utc_media_camera_setting.c
src/utc/camera/utc_media_camera_util.c [new file with mode: 0644]
src/utc/camera/utc_media_camera_util.h [new file with mode: 0644]

index bdf4715f2152fe1aec193d4a66f84b8147b2a007..c9215e7b7a766d52fa08ce9b8cb21208379ffdd6 100644 (file)
@@ -5,6 +5,7 @@ SET(RPM_NAME "core-${PKG_NAME}-tests")
 
 SET(CAPI_LIB "capi-media-camera")
 SET(TC_SOURCES
+    utc_media_camera_util.c
     utc_media_camera_attr.c
     utc_media_camera_lifecycle.c
     utc_media_camera_setting.c
index a4a2606c69ad167cbdda6b75c8e759ad3d225369..edc14d65a355c896960b726b2435f032eab57eb2 100644 (file)
@@ -21,6 +21,7 @@
 #include <pthread.h>
 #include <glib-object.h>
 #include <system_info.h>
+#include "utc_media_camera_util.h"
 
 #include "assert.h"
 
@@ -259,6 +260,8 @@ static void _media_packet_preview_cb(media_packet_h pkt, void *user_data)
                pkt = NULL;
        }
 
+       utc_media_camera_util_mainloop_quit(user_data);
+
        return;
 }
 
@@ -354,7 +357,7 @@ int utc_media_camera_start_preview_p2(void)
 
        ret = camera_start_preview(camera);
 
-       usleep(50 * 1000);
+       utc_media_camera_util_mainloop_run();
 
        camera_stop_preview(camera);
        camera_unset_media_packet_preview_cb(camera);
@@ -436,6 +439,8 @@ static void _camera_capture_cb(camera_image_data_s *image, camera_image_data_s *
 
 static void _camera_capture_completed_cb(void *data)
 {
+       utc_media_camera_util_mainloop_quit(data);
+
        return;
 }
 
@@ -505,7 +510,7 @@ int utc_media_camera_start_capture_p(void)
 
        ret = camera_start_capture(camera, _camera_capture_cb, _camera_capture_completed_cb, NULL);
 
-       usleep(1000 * 2000);
+       utc_media_camera_util_mainloop_run();
 
        camera_start_preview(camera);
        camera_stop_preview(camera);
index 1367954e8c611ee2322a5b8970f235796b96881f..e3eaf8a8531499853c528e064c94b87ddddda575 100644 (file)
@@ -24,6 +24,7 @@
 #include <Evas.h>
 #endif /* TIZENIOT */
 #include "tct_common.h"
+#include "utc_media_camera_util.h"
 #include "assert.h"
 
 
@@ -1564,6 +1565,8 @@ int utc_media_camera_unset_media_packet_preview_cb_p(void)
 
 static void _changed_cb(camera_state_e previous, camera_state_e current, bool by_asm, void *user_data)
 {
+       utc_media_camera_util_mainloop_quit(user_data);
+
        return;
 }
 
@@ -1651,6 +1654,12 @@ int utc_media_camera_set_state_changed_cb_p(void)
        ret = camera_set_state_changed_cb(camera, _changed_cb, NULL);
        assert_eq(ret, CAMERA_ERROR_NONE);
 
+       camera_start_preview(camera);
+
+       utc_media_camera_util_mainloop_run();
+
+       camera_stop_preview(camera);
+
        return 0;
 }
 
@@ -1871,6 +1880,9 @@ static bool _preview_resolution_cb2(int width, int height, void *user_data)
 
 static void _device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
 {
+       if (state == CAMERA_DEVICE_STATE_WORKING)
+               utc_media_camera_util_mainloop_quit(user_data);
+
        return;
 }
 
@@ -3668,9 +3680,15 @@ int utc_media_camera_add_device_state_changed_cb_p(void)
        else
                check_ret = CAMERA_ERROR_NOT_SUPPORTED;
 
+       camera_start_preview(camera);
+
+       utc_media_camera_util_mainloop_run();
+
        if (cb_id > 0)
                camera_remove_device_state_changed_cb(cb_id);
 
+       camera_stop_preview(camera);
+
        assert_eq(ret, check_ret);
 
        return 0;
diff --git a/src/utc/camera/utc_media_camera_util.c b/src/utc/camera/utc_media_camera_util.c
new file mode 100644 (file)
index 0000000..eb4b1eb
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2023 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 <dlog.h>
+#include "utc_media_camera_util.h"
+
+
+#define CAMERA_MAINLOOP_TIMEOUT 5000 /* milliseconds */
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "UTC_CAMERA_UTIL"
+
+
+static GMainLoop *g_camera_mainloop;
+static guint g_camera_timeout_id;
+
+
+gboolean utc_media_camera_util_mainloop_quit(gpointer user_data)
+{
+       if (!g_camera_mainloop)
+               return FALSE;
+
+       dlog_print(DLOG_INFO, LOG_TAG, "QUIT MAINLOOP");
+
+       g_main_loop_quit(g_camera_mainloop);
+
+       return FALSE;
+}
+
+void utc_media_camera_util_mainloop_run(void)
+{
+       g_camera_timeout_id = g_timeout_add(CAMERA_MAINLOOP_TIMEOUT, utc_media_camera_util_mainloop_quit, NULL);
+       if (g_camera_timeout_id == 0) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add timer");
+               return;
+       }
+
+       g_camera_mainloop = g_main_loop_new(NULL, FALSE);
+       if (!g_camera_mainloop) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get new mainloop");
+               g_source_remove(g_camera_timeout_id);
+               g_camera_timeout_id = 0;
+               return;
+       }
+
+       g_main_loop_run(g_camera_mainloop);
+
+       if (g_main_context_find_source_by_id(NULL, g_camera_timeout_id)) {
+               dlog_print(DLOG_INFO, LOG_TAG, "FOUND source[%u]", g_camera_timeout_id);
+               g_source_remove(g_camera_timeout_id);
+       } else {
+               dlog_print(DLOG_WARN, LOG_TAG, "NOT FOUND source[%u]", g_camera_timeout_id);
+       }
+
+       g_camera_timeout_id = 0;
+
+       g_main_loop_unref(g_camera_mainloop);
+       g_camera_mainloop = NULL;
+}
diff --git a/src/utc/camera/utc_media_camera_util.h b/src/utc/camera/utc_media_camera_util.h
new file mode 100644 (file)
index 0000000..a026d08
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2023 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 __UTC_MEDIA_CAMERA_UTIL_H__
+#define __UTC_MEDIA_CAMERA_UTIL_H__
+
+#include <glib.h>
+
+
+gboolean utc_media_camera_util_mainloop_quit(gpointer user_data);
+void utc_media_camera_util_mainloop_run(void);
+
+#endif /* __UTC_MEDIA_CAMERA_UTIL_H__ */