summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-19 17:09:03 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-19 17:09:03 +0900
commit7e8c5f57cea63e7f3b06a8f801993671a9e42590 (patch)
tree6e4fb90fca3240ca35bc0c0996611701867131e1 /test
parentf3071015148fc02ee2135ac071623f1dd350bdb3 (diff)
downloadlibmedia-service-7e8c5f57cea63e7f3b06a8f801993671a9e42590.tar.gz
libmedia-service-7e8c5f57cea63e7f3b06a8f801993671a9e42590.tar.bz2
libmedia-service-7e8c5f57cea63e7f3b06a8f801993671a9e42590.zip
sync with master
Diffstat (limited to 'test')
-rwxr-xr-xtest/CMakeLists.txt18
-rw-r--r--test/media-service-test.c249
2 files changed, 267 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100755
index 0000000..bc924e5
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,18 @@
+SET(fw_name "media-service")
+SET(fw_test "${fw_name}-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog libmedia-utils)
+FOREACH(flag ${${fw_test}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+ GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+ MESSAGE("${src_name}")
+ ADD_EXECUTABLE(${src_name} ${src})
+ TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
diff --git a/test/media-service-test.c b/test/media-service-test.c
new file mode 100644
index 0000000..5410f21
--- /dev/null
+++ b/test/media-service-test.c
@@ -0,0 +1,249 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <media-svc.h>
+#include <media-svc-noti.h>
+
+GMainLoop *g_loop = NULL;
+MediaSvcHandle *g_db_handle = NULL;
+
+void _noti_cb(int pid,
+ media_item_type_e update_item,
+ media_item_update_type_e update_type,
+ char *path,
+ char *uuid,
+ media_type_e content_type,
+ char *mime_type,
+ void *user_data)
+{
+ media_svc_debug("Noti from PID(%d)", pid);
+
+ if (update_item == MS_MEDIA_ITEM_FILE) {
+ media_svc_debug("Noti item : MS_MEDIA_ITEM_FILE");
+ } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
+ media_svc_debug("Noti item : MS_MEDIA_ITEM_DIRECTORY");
+ }
+
+ if (update_type == MS_MEDIA_ITEM_INSERT) {
+ media_svc_debug("Noti type : MS_MEDIA_ITEM_INSERT");
+ } else if (update_type == MS_MEDIA_ITEM_DELETE) {
+ media_svc_debug("Noti type : MS_MEDIA_ITEM_DELETE");
+ } else if (update_type == MS_MEDIA_ITEM_UPDATE) {
+ media_svc_debug("Noti type : MS_MEDIA_ITEM_UPDATE");
+ }
+
+ //media_svc_debug("content type : %d", content_type);
+ printf("content type : %d\n", content_type);
+
+ if (path)
+ printf("path : %s\n", path);
+ else
+ printf("path not");
+
+ if (mime_type)
+ printf("mime_type : %s", mime_type);
+ else
+ printf("mime not");
+
+ if (user_data) printf("String : %s\n", (char *)user_data);
+ else
+ printf("user not");
+
+ return;
+}
+
+#if 1
+gboolean _send_noti_batch_operations(gpointer data)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ /* First of all, noti subscription */
+ char *user_str = strdup("hi");
+ media_db_update_subscribe(_noti_cb, (void*)user_str);
+
+ /* 1. media_svc_insert_item_immediately */
+ char *path = "/opt/usr/media/test/image1.jpg";
+
+ media_svc_media_type_e media_type;
+ media_svc_storage_type_e storage_type;
+ char mime_type[255] = {0, };
+
+ ret = media_svc_get_storage_type(path, &storage_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_mime_type(path, mime_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_media_type(path, mime_type, &media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_media_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ int i;
+ char *file_list[10];
+
+ ret = media_svc_insert_item_begin(g_db_handle, 100, TRUE, getpid());
+ //ret = media_svc_insert_item_begin(g_db_handle, 100);
+ for (i = 0; i < 16; i++) {
+ char filepath[255] = {0,};
+ snprintf(filepath, sizeof(filepath), "%s%d.jpg", "/opt/usr/media/test/image", i+1);
+ media_svc_debug("File : %s\n", filepath);
+ file_list[i] = strdup(filepath);
+ ret = media_svc_insert_item_bulk(g_db_handle, storage_type, file_list[i], mime_type, media_type, FALSE);
+ if (ret != 0) {
+ media_svc_error("media_svc_insert_item_bulk[%d] failed", i);
+ } else {
+ media_svc_debug("media_svc_insert_item_bulk[%d] success", i);
+ }
+ }
+
+ ret = media_svc_insert_item_end(g_db_handle);
+
+ return FALSE;
+}
+#endif
+
+gboolean _send_noti_operations(gpointer data)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ /* First of all, noti subscription */
+ char *user_str = strdup("hi");
+ media_db_update_subscribe(_noti_cb, (void*)user_str);
+
+ /* 1. media_svc_insert_item_immediately */
+ char *path = "/opt/usr/media/test/image1.jpg";
+
+ media_svc_media_type_e media_type;
+ media_svc_storage_type_e storage_type;
+ char mime_type[255] = {0, };
+
+ ret = media_svc_get_storage_type(path, &storage_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_mime_type(path, mime_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_media_type(path, mime_type, &media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_media_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_insert_item_immediately(g_db_handle, storage_type, path, mime_type, media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_insert_item_immediately failed : %d", ret);
+ return FALSE;
+ }
+
+ media_svc_debug("media_svc_insert_item_immediately success");
+
+ /* 2. media_svc_refresh_item */
+ ret = media_svc_refresh_item(g_db_handle, storage_type, path, media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_refresh_item failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_refresh_item success");
+
+ /* 2. media_svc_move_item */
+ const char *dst_path = "/opt/usr/media/test/image11.jpg";
+ ret = media_svc_move_item(g_db_handle, storage_type, path, storage_type, dst_path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_move_item failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_move_item success");
+
+ ret = media_svc_move_item(g_db_handle, storage_type, dst_path, storage_type, path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_move_item failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_move_item success");
+
+ /* 4. media_svc_delete_item_by_path */
+ ret = media_svc_delete_item_by_path(g_db_handle, path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_delete_item_by_path failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_delete_item_by_path success");
+
+ /* Rename folder */
+ const char *src_folder_path = "/opt/usr/media/test";
+ const char *dst_folder_path = "/opt/usr/media/test_test";
+ ret = media_svc_rename_folder(g_db_handle, src_folder_path, dst_folder_path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_rename_folder failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_rename_folder success");
+
+ /* Rename folder again */
+ ret = media_svc_rename_folder(g_db_handle, dst_folder_path, src_folder_path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_rename_folder failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_rename_folder success");
+
+ return FALSE;
+}
+
+int test_noti()
+{
+ GSource *source = NULL;
+ GMainContext *context = NULL;
+
+ g_loop = g_main_loop_new(NULL, FALSE);
+ context = g_main_loop_get_context(g_loop);
+ source = g_idle_source_new();
+#if 0
+ g_source_set_callback (source, _send_noti_operations, NULL, NULL);
+#else
+ g_source_set_callback (source, _send_noti_batch_operations, NULL, NULL);
+#endif
+ g_source_attach (source, context);
+
+ g_main_loop_run(g_loop);
+
+ g_main_loop_unref(g_loop);
+ media_db_update_unsubscribe();
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int main()
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ ret = media_svc_connect(&g_db_handle);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_connect failed : %d", ret);
+ } else {
+ media_svc_debug("media_svc_connect success");
+ }
+
+ ret = test_noti();
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("test_noti failed : %d", ret);
+ } else {
+ media_svc_debug("test_noti success");
+ }
+
+ media_svc_disconnect(g_db_handle);
+ return ret;
+}
+