Add unit test 58/193458/7 accepted/tizen/unified/20181130.064930 submit/tizen/20181129.024814
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 21 Nov 2018 02:52:31 +0000 (11:52 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Mon, 26 Nov 2018 04:43:50 +0000 (13:43 +0900)
- Precondition to run gtests-libmm-camcorder
 : The executable label should be changed to "User" after install
 : The user should be "owner"

[Version] 0.10.173
[Profile] Common
[Issue Type] Update
[Dependency module] N/A
[Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-unified_20181113.3]

Change-Id: I11d1dc586f36d4d407fc9180a20abcbc84f32223
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
Makefile.am
configure.ac
packaging/libmm-camcorder.spec
unittest/Makefile.am [new file with mode: 0644]
unittest/gtests_libmm_camcorder.cpp [new file with mode: 0644]
unittest/gtests_libmm_camcorder.h [new file with mode: 0644]

index e4cce4a..08af3cd 100644 (file)
@@ -2,6 +2,10 @@ ACLOCAL_AMFLAGS='-I m4'
 
 SUBDIRS = src
 
+if GTESTS
+SUBDIRS += unittest
+endif
+
 pcfiles = mm-camcorder.pc
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = $(pcfiles)
index f041375..52a670d 100644 (file)
@@ -21,6 +21,8 @@ AC_HEADER_STDC
 AC_HEADER_TIME
 AC_PROG_GCC_TRADITIONAL
 AC_PROG_LIBTOOL
+AC_PROG_CXX
+AC_SUBST(GCC_CXXFLAGS)
 
 # Checks for libraries.
 PKG_CHECK_MODULES(GST, gstreamer-1.0 >= 1.2.0)
@@ -139,6 +141,21 @@ AC_ARG_ENABLE(product-tv, AC_HELP_STRING([--enable-product-tv],[enable tv define
 ],[PRODUCT_TV=no])
 AM_CONDITIONAL([PRODUCT_TV], [test "x$PRODUCT_TV" = "xyes"])
 
+AC_ARG_ENABLE(gtests, AC_HELP_STRING([--enable-gtests], [enable gtests]),
+[
+  case "${enableval}" in
+    yes) GTESTS=yes ;;
+    no)  GTESTS=no ;;
+    *) AC_MSG_ERROR(bad value ${enableval} for --enable-gtests) ;;
+  esac
+],[GTESTS=no])
+if test "x$GTESTS" = "xyes"; then
+PKG_CHECK_MODULES(GMOCK, gmock)
+AC_SUBST(GMOCK_CFLAGS)
+AC_SUBST(GMOCK_LIBS)
+fi
+AM_CONDITIONAL([GTESTS], [test "x$GTESTS" = "xyes"])
+
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS([fcntl.h memory.h stdlib.h string.h sys/time.h unistd.h])
@@ -159,6 +176,7 @@ AC_CHECK_FUNCS([memset select])
 AC_CONFIG_FILES([
 Makefile
 src/Makefile
+unittest/Makefile
 mm-camcorder.pc
 ])
 AC_OUTPUT
index 6935c42..9a8abbd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.172
+Version:    0.10.173
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
@@ -14,6 +14,7 @@ BuildRequires:  pkgconfig(mm-common)
 BuildRequires:  pkgconfig(libexif)
 BuildRequires:  pkgconfig(mmutil-imgp)
 BuildRequires:  pkgconfig(mmutil-jpeg)
+BuildRequires:  pkgconfig(gstreamer-1.0)
 BuildRequires:  pkgconfig(gstreamer-base-1.0)
 BuildRequires:  pkgconfig(gstreamer-allocators-1.0)
 BuildRequires:  pkgconfig(gstreamer-video-1.0)
@@ -31,6 +32,9 @@ BuildRequires:  pkgconfig(ttrace)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(dpm)
 BuildRequires:  pkgconfig(dlog)
+%if "%{gtests}" == "1"
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 Camera and recorder function supported library.
@@ -60,6 +64,9 @@ export CFLAGS+=" -D_LARGEFILE64_SOURCE -DGST_USE_UNSTABLE_API -DSYSCONFDIR=\\\"%
 %else
        --enable-mm-resource-manager \
 %endif
+%if "%{gtests}" == "1"
+       --enable-gtests \
+%endif
        --disable-static
 make %{?jobs:-j%jobs}
 
@@ -78,6 +85,9 @@ make %{?jobs:-j%jobs}
 %defattr(-,root,root,-)
 %{_libdir}/*.so.*
 %{_datadir}/sounds/mm-camcorder/*
+%if "%{gtests}" == "1"
+%{_bindir}/gtests-libmm-camcorder
+%endif
 
 %files devel
 %defattr(-,root,root,-)
diff --git a/unittest/Makefile.am b/unittest/Makefile.am
new file mode 100644 (file)
index 0000000..6578b33
--- /dev/null
@@ -0,0 +1,17 @@
+bin_PROGRAMS = gtests-libmm-camcorder
+
+gtests_libmm_camcorder_SOURCES = gtests_libmm_camcorder.cpp
+
+gtests_libmm_camcorder_CXXFLAGS = \
+       -I$(top_srcdir)/src/include\
+       $(GST_CFLAGS)\
+       $(MM_COMMON_CFLAGS)\
+       $(GMOCK_CFLAGS)
+
+gtests_libmm_camcorder_DEPENDENCIES = \
+       $(top_srcdir)/src/libmmfcamcorder.la
+
+gtests_libmm_camcorder_LDADD = \
+       $(GMOCK_LIBS) \
+       $(top_srcdir)/src/libmmfcamcorder.la
+
diff --git a/unittest/gtests_libmm_camcorder.cpp b/unittest/gtests_libmm_camcorder.cpp
new file mode 100644 (file)
index 0000000..e98032c
--- /dev/null
@@ -0,0 +1,551 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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/gio.h>
+#include "gtests_libmm_camcorder.h"
+
+using namespace std;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+int g_ret;
+int g_frame_count;
+MMHandleType g_cam_handle;
+MMCamPreset g_info;
+GDBusConnection *g_dbus_connection;
+GMutex g_msg_lock;
+GCond g_msg_cond;
+
+static gboolean _get_video_recording_settings(int *video_encoder, int *audio_encoder, int *file_format)
+{
+       int i = 0;
+       int j = 0;
+       int tmp_v_enc;
+       int tmp_a_enc;
+       int tmp_fmt;
+       MMCamAttrsInfo info_a_enc;
+       MMCamAttrsInfo info_fmt;
+
+       if (!video_encoder || !audio_encoder || !file_format) {
+               cout << "NULL pointer" << endl;
+               return FALSE;
+       }
+
+       /* get supported audio encoder list */
+       mm_camcorder_get_attribute_info(g_cam_handle, MMCAM_AUDIO_ENCODER, &info_a_enc);
+
+       /* get supported file format list */
+       mm_camcorder_get_attribute_info(g_cam_handle, MMCAM_FILE_FORMAT, &info_fmt);
+
+       /* compatibility check */
+       tmp_v_enc = MM_VIDEO_CODEC_MPEG4;
+
+       for (i = 0 ; i < info_fmt.int_array.count ; i++) {
+               tmp_fmt = info_fmt.int_array.array[i];
+               if (mm_camcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, tmp_v_enc, tmp_fmt) == MM_ERROR_NONE) {
+                       for (j = 0 ; info_a_enc.int_array.count ; j++) {
+                               tmp_a_enc = info_a_enc.int_array.array[j];
+                               if (mm_camcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, tmp_a_enc, tmp_fmt) == MM_ERROR_NONE) {
+                                       cout << "[VIDEO RECORDING SETTING FOUND]" << endl;
+
+                                       *video_encoder = tmp_v_enc;
+                                       *audio_encoder = tmp_a_enc;
+                                       *file_format = tmp_fmt;
+
+                                       return TRUE;
+                               }
+                       }
+               }
+       }
+
+       cout << "[VIDEO RECORDING SETTING FAILED]" << endl;
+
+       return FALSE;
+}
+
+static gboolean _get_audio_recording_settings(int *audio_encoder, int *file_format)
+{
+       int i = 0;
+       int tmp_a_enc;
+       int tmp_fmt;
+       MMCamAttrsInfo info_a_enc;
+       MMCamAttrsInfo info_fmt;
+
+       if (!audio_encoder || !file_format) {
+               cout << "NULL pointer" << endl;
+               return FALSE;
+       }
+
+       /* get supported audio encoder list */
+       mm_camcorder_get_attribute_info(g_cam_handle, MMCAM_AUDIO_ENCODER, &info_a_enc);
+
+       /* get supported file format list */
+       mm_camcorder_get_attribute_info(g_cam_handle, MMCAM_FILE_FORMAT, &info_fmt);
+
+       /* compatibility check */
+       tmp_a_enc = info_a_enc.int_array.array[0];
+
+       for (i = 0 ; i < info_fmt.int_array.count ; i++) {
+               tmp_fmt = info_fmt.int_array.array[i];
+               if (mm_camcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, tmp_a_enc, tmp_fmt) == MM_ERROR_NONE) {
+                       cout << "[AUDIO RECORDING SETTING FOUND]" << endl;
+
+                       *audio_encoder = tmp_a_enc;
+                       *file_format = tmp_fmt;
+
+                       return TRUE;
+               }
+       }
+
+       cout << "[VIDEO RECORDING SETTING FAILED]" << endl;
+
+       return FALSE;
+}
+
+static int _message_callback(int id, void *param, void *user_param)
+{
+       MMMessageParamType *m = (MMMessageParamType *)param;
+
+       switch (id) {
+       case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
+               cout << "[STATE CHANGED] " << m->state.previous << " -> " << m->state.current << endl;
+               break;
+       case MM_MESSAGE_CAMCORDER_CAPTURED:
+               cout << "[CAPTURED MESSAGE] SEND SIGNAL" << endl;
+               g_mutex_lock(&g_msg_lock);
+               g_cond_signal(&g_msg_cond);
+               g_mutex_unlock(&g_msg_lock);
+               break;
+       default:
+               break;
+       }
+
+       return 1;
+}
+
+static gboolean _video_stream_callback(MMCamcorderVideoStreamDataType *stream, void *user_param)
+{
+       cout << "[VIDEO_STREAM_CALLBACK]" << endl;
+       return TRUE;
+}
+
+static gboolean _muxed_stream_callback(MMCamcorderMuxedStreamDataType *stream, void *user_param)
+{
+       cout << "[MUXED_STREAM_CALLBACK]" << endl;
+
+       g_mutex_lock(&g_msg_lock);
+
+       g_frame_count++;
+
+       if (g_frame_count > 10) {
+               cout << "[MUXED_STREAM_CALLBACK] SEND SIGNAL" << endl;
+               g_cond_signal(&g_msg_cond);
+       }
+
+       g_mutex_unlock(&g_msg_lock);
+
+       return TRUE;
+}
+
+static gboolean _video_capture_callback(MMCamcorderCaptureDataType *frame, MMCamcorderCaptureDataType *thumbnail, void *user_data)
+{
+       cout << "[CAPTURE_CALLBACK]" << endl;
+       return TRUE;
+}
+
+
+class MMCamcorderTest : public ::testing::Test {
+       protected:
+               void SetUp() {
+                       cout << "[SetUp]" << endl;
+
+                       if (g_dbus_connection) {
+                               g_object_unref(g_dbus_connection);
+                               g_dbus_connection = NULL;
+                       }
+
+                       g_dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
+
+                       if (g_cam_handle) {
+                               mm_camcorder_destroy(g_cam_handle);
+                               g_cam_handle = NULL;
+                       }
+
+                       g_info.videodev_type = MM_VIDEO_DEVICE_CAMERA0;
+
+                       g_ret = mm_camcorder_create(&g_cam_handle, &g_info);
+
+                       cout << "handle " << g_cam_handle << ", dbus connection " << g_dbus_connection << endl;
+
+                       /* set gdbus connection */
+                       if (g_cam_handle && g_dbus_connection) {
+                               mm_camcorder_set_attributes(g_cam_handle, NULL,
+                                       MMCAM_GDBUS_CONNECTION, g_dbus_connection, 4,
+                                       NULL);
+                       }
+
+                       /* set message callback */
+                       if (mm_camcorder_set_message_callback(g_cam_handle, _message_callback, g_cam_handle) != MM_ERROR_NONE)
+                               cout << "[FAILED] set message callback" << endl;
+
+                       return;
+               }
+
+               void TearDown() {
+                       cout << "[TearDown]" << endl << endl;
+
+                       if (g_cam_handle) {
+                               mm_camcorder_destroy(g_cam_handle);
+                               g_cam_handle = NULL;
+                       }
+
+                       if (g_dbus_connection) {
+                               g_object_unref(g_dbus_connection);
+                               g_dbus_connection = NULL;
+                       }
+
+                       return;
+               }
+};
+
+TEST_F(MMCamcorderTest, CreateP)
+{
+       EXPECT_EQ(g_ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMCamcorderTest, CreateN)
+{
+       int ret = mm_camcorder_create(NULL, NULL);
+
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, DestroyP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_destroy(g_cam_handle);
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       g_cam_handle = NULL;
+}
+
+TEST_F(MMCamcorderTest, DestroyN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_destroy(NULL);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, RealizeP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, RealizeN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(NULL);
+
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, UnrealizeP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       ret = mm_camcorder_unrealize(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMCamcorderTest, UnrealizeN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       ret = mm_camcorder_unrealize(NULL);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, StartP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       ret = mm_camcorder_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       mm_camcorder_stop(g_cam_handle);
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, StartN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       ret = mm_camcorder_start(NULL);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, StopP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ret |= mm_camcorder_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       if (ret == MM_ERROR_NONE) {
+               ret = mm_camcorder_stop(g_cam_handle);
+               EXPECT_EQ(ret, MM_ERROR_NONE);
+       }
+
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, StopN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ret |= mm_camcorder_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       if (ret == MM_ERROR_NONE) {
+               ret = mm_camcorder_stop(NULL);
+               EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+       }
+
+       mm_camcorder_stop(g_cam_handle);
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, CaptureStartP)
+{
+       int ret = MM_ERROR_NONE;
+       gboolean ret_wait = FALSE;
+       gint64 end_time = 0;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ret |= mm_camcorder_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       if (ret == MM_ERROR_NONE) {
+               g_mutex_lock(&g_msg_lock);
+
+               if (mm_camcorder_set_video_capture_callback(g_cam_handle, _video_capture_callback, g_cam_handle) != MM_ERROR_NONE)
+                       cout << "[FAILED] set video capture callback" << endl;
+
+               ret = mm_camcorder_capture_start(g_cam_handle);
+               EXPECT_EQ(ret, MM_ERROR_NONE);
+
+               if (ret == MM_ERROR_NONE) {
+                       end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
+
+                       ret_wait = g_cond_wait_until(&g_msg_cond, &g_msg_lock, end_time);
+
+                       EXPECT_EQ(ret_wait, TRUE);
+
+                       mm_camcorder_capture_stop(g_cam_handle);
+               }
+
+               g_mutex_unlock(&g_msg_lock);
+       }
+
+       mm_camcorder_stop(g_cam_handle);
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, CaptureStartN1)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ret |= mm_camcorder_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       if (ret == MM_ERROR_NONE) {
+               ret = mm_camcorder_capture_start(NULL);
+               EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+       }
+
+       mm_camcorder_stop(g_cam_handle);
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, CaptureStartN2)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ASSERT_EQ(ret, MM_ERROR_NONE);
+
+       ret = mm_camcorder_capture_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_STATE);
+
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+TEST_F(MMCamcorderTest, SetMessageCallbackP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_message_callback(g_cam_handle, _message_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMCamcorderTest, SetMessageCallbackN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_message_callback(NULL, _message_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, SetVideoStreamCallbackP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_video_stream_callback(g_cam_handle, _video_stream_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMCamcorderTest, SetVideoStreamCallbackN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_video_stream_callback(NULL, _video_stream_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, SetVideoCaptureCallbackP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_video_capture_callback(g_cam_handle, _video_capture_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMCamcorderTest, SetVideoCaptureCallbackN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_video_capture_callback(NULL, _video_capture_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, SetMuxedStreamCallbackP)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_muxed_stream_callback(g_cam_handle, _muxed_stream_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+}
+
+TEST_F(MMCamcorderTest, SetMuxedStreamCallbackN)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_camcorder_set_muxed_stream_callback(NULL, _muxed_stream_callback, g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+}
+
+TEST_F(MMCamcorderTest, RecordP)
+{
+       int ret = MM_ERROR_NONE;
+       int video_encoder = 0;
+       int audio_encoder = 0;
+       int file_format = 0;
+       gboolean ret_settings = FALSE;
+       gboolean ret_wait = FALSE;
+       gint64 end_time = 0;
+
+       ret = mm_camcorder_realize(g_cam_handle);
+       ret |= mm_camcorder_start(g_cam_handle);
+       EXPECT_EQ(ret, MM_ERROR_NONE);
+
+       if (ret == MM_ERROR_NONE) {
+               g_mutex_lock(&g_msg_lock);
+
+               g_frame_count = 0;
+
+               if (mm_camcorder_set_muxed_stream_callback(g_cam_handle, _muxed_stream_callback, g_cam_handle) != MM_ERROR_NONE)
+                       cout << "[FAILED] set video capture callback" << endl;
+
+               ret_settings = _get_video_recording_settings(&video_encoder, &audio_encoder, &file_format);
+               EXPECT_EQ(ret_settings, TRUE);
+
+               ret = mm_camcorder_set_attributes(g_cam_handle, NULL,
+                       MMCAM_VIDEO_ENCODER, video_encoder,
+                       MMCAM_AUDIO_ENCODER, audio_encoder,
+                       MMCAM_FILE_FORMAT, file_format,
+                       NULL);
+
+               ret = mm_camcorder_record(g_cam_handle);
+               EXPECT_EQ(ret, MM_ERROR_NONE);
+
+               if (ret == MM_ERROR_NONE) {
+                       end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
+
+                       ret_wait = g_cond_wait_until(&g_msg_cond, &g_msg_lock, end_time);
+
+                       cout << "[RECORDING] SIGNAL RECEIVED : " << ret_wait << endl;
+
+                       EXPECT_EQ(ret_wait, TRUE);
+
+                       mm_camcorder_cancel(g_cam_handle);
+               }
+
+               g_mutex_unlock(&g_msg_lock);
+       }
+
+       mm_camcorder_stop(g_cam_handle);
+       mm_camcorder_unrealize(g_cam_handle);
+}
+
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/gtests_libmm_camcorder.h b/unittest/gtests_libmm_camcorder.h
new file mode 100644 (file)
index 0000000..19444d5
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __MM_CAMCORDER_UNITTEST_H__
+#define __MM_CAMCORDER_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <mm_camcorder.h>
+
+#undef LOG_TAG
+#define LOG_TAG                "GTEST_MM_CAMCORDER"
+
+#endif /*__MM_CAMCORDER_UNITTEST_H__*/