m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_CC
AM_PROG_CC_C_O
+AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL
fi
AM_CONDITIONAL(USE_PRODUCT_TV, test "x$USE_PRODUCT_TV" = "xyes")
+# for gtests
+AC_ARG_ENABLE(tests, AC_HELP_STRING([--enable-tests], [unittest build]),
+ [
+ case "${enableval}" in
+ yes) IS_TESTS=yes ;;
+ no) IS_TESTS=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-tests) ;;
+ esac
+ ],
+[IS_TESTS=no])
+AM_CONDITIONAL([IS_TESTS], [test "x$IS_TESTS" = "xyes"])
+
+AS_IF([test "x$enable_tests" = "xyes"], [
+ PKG_CHECK_MODULES(GTESTS, gmock)
+ AC_SUBST(GTESTS_CFLAGS)
+ AC_SUBST(GTESTS_LIBS)
+])
+
#Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
+AC_SUBST(GCC_CXXFLAGS)
# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_CHECK_FUNCS([gettimeofday memset mkdir strcasecmp strstr])
AC_CONFIG_FILES([Makefile
- libmedia-utils.pc
- ])
+ unittest/Makefile
+ libmedia-utils.pc
+])
AC_OUTPUT
BuildRequires: pkgconfig(cynara-session)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(capi-system-device)
-
+%if 0%{?gtests:1}
+BuildRequires: pkgconfig(gmock)
+%endif
%if "%{tizen_profile_name}" == "tv"
BuildRequires: pkgconfig(capi-system-usbdevice)
BuildRequires: pkgconfig(power-defs)
rm -f aclocal.m4 ltmain.sh
mkdir -p m4
%reconfigure --prefix=%{_prefix} \
+%if 0%{?gtests:1}
+ --enable-tests \
+%endif
%if 0%{?product_tv}
--enable-product-tv \
%else
%{_bindir}/media-scanner
%{_bindir}/media-scanner-v2
%{_bindir}/mediadb-update
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%endif
%{_unitdir}/media-server.service
%{_unitdir}/multi-user.target.wants/media-server.service
%if !0%{?product_tv}
--- /dev/null
+/*
+ * 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 <glib.h>
+#include <tzplatform_config.h>
+
+#include "media_server_unittest.h"
+#include "media-util.h"
+
+#define TIMEOUT_SECONDS 5000
+
+//Add helper function declarations here
+static GMainLoop *g_ms_mainloop = NULL;
+static gboolean g_async_result = FALSE;
+gboolean timeout_func(gpointer data)
+{
+ g_main_loop_quit((GMainLoop *) data);
+
+ return FALSE;
+}
+
+static void wait_async_cb(void)
+{
+ int timeout_id = 0;
+ g_ms_mainloop = g_main_loop_new(NULL, FALSE);
+
+ // init
+ g_async_result = FALSE;
+
+ timeout_id = g_timeout_add(TIMEOUT_SECONDS, timeout_func, g_ms_mainloop);
+ g_main_loop_run(g_ms_mainloop);
+ g_source_remove(timeout_id);
+ g_main_loop_unref(g_ms_mainloop);
+ g_ms_mainloop = NULL;
+}
+
+void signal_async(gboolean async_result)
+{
+ g_async_result = async_result;
+
+ if (g_ms_mainloop != NULL) {
+ g_main_loop_quit(g_ms_mainloop);
+ }
+}
+
+void _scan_complete_cb(media_request_result_s *result, void *user_data)
+{
+ signal_async(TRUE);
+}
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+class media_server_Test : public ::testing::Test {
+ protected:
+ void SetUp() {
+ std::cout << "SetUp()" << std::endl;
+ }
+
+ void TearDown() {
+ std::cout << "TearDown()" << std::endl;
+ }
+};
+
+TEST(media_server_Test, media_directory_scanning_async_p)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = media_directory_scanning_async(tzplatform_getenv(TZ_USER_CONTENT), "media", false, _scan_complete_cb, NULL, getuid());
+ EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+
+ wait_async_cb();
+ EXPECT_TRUE(g_async_result);
+}
+
+TEST(media_server_Test, media_directory_scanning_async_n)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = media_directory_scanning_async(NULL, NULL, false, NULL, NULL, getuid());
+ EXPECT_EQ(ret, MS_MEDIA_ERR_INVALID_PATH);
+}
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/*
+ * 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 __MEDIA_SERVER_UNITTEST_H__
+#define __MEDIA_SERVER_UNITTEST_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#undef LOG_TAG
+#define LOG_TAG "GTEST_MEDIA_SERVER"
+
+#endif /*__MEDIA_SERVER_UNITTEST_H__*/