Add file check at sst_sound_call_rintone 88/236788/8 accepted/tizen/unified/20200630.131403 submit/tizen/20200629.142743
authorJinWang An <jinwang.an@samsung.com>
Mon, 22 Jun 2020 15:02:43 +0000 (00:02 +0900)
committerJinWang An <jinwang.an@samsung.com>
Mon, 29 Jun 2020 14:09:10 +0000 (23:09 +0900)
Change-Id: I1c4d541acf0cdbd49fd2ffef4b369eb67dc9b35c
Signed-off-by: JinWang An <jinwang.an@samsung.com>
packaging/capi-system-system-settings.spec
src/sst_sound.c
tests/CMakeLists.txt
tests/mocks/libc.c
tests/scripts/ringtone_files.sh [new file with mode: 0755]
tests/sstt_test.c

index 26a5b6f..a93457b 100644 (file)
@@ -138,10 +138,13 @@ genhtml %{name}.info -o out --legend --show-details
 %post -p /sbin/ldconfig
 %post util-lib -p /sbin/ldconfig
 %post unittests
+bash %{sys_setting_test_dir}/ringtone_files.sh create
 XDG_RUNTIME_DIR=/run %{sys_setting_test_dir}/sys-settings-test
 
 %postun -p /sbin/ldconfig
 %postun util-lib -p /sbin/ldconfig
+%postun unittests
+bash %{sys_setting_test_dir}/ringtone_files.sh del
 
 %files
 %manifest %{name}.manifest
index fecc3df..c4260c2 100644 (file)
@@ -169,14 +169,12 @@ int sst_sound_add_call_ringtone(system_settings_key_e key, const char *value)
                return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
        }
 
-       //Todo: check utc_system_settings_add_ringtone_list_p1
-       /*
-       if (false == sst_is_valid_file(path)) {
-               ERR("Invalid ringtone file(%s)", path);
+       if (false == sst_misc_file_exists(path)) {
+               ERR("sst_misc_file_exists(%s) Fail", path);
                sst_json_unref(handle);
                return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
        }
-       */
+
        sst_json_add_ringtone(handle, path, path);
        sst_json_unref(handle);
 
index 4ad01a1..35072b3 100644 (file)
@@ -16,3 +16,4 @@ INSTALL(TARGETS ${UNITTEST} DESTINATION ${TEST_INSTALL_DIR})
 
 FILE(GLOB TEST_RES res/*)
 INSTALL(FILES ${TEST_RES} DESTINATION ${TEST_INSTALL_DIR})
+INSTALL(FILES scripts/ringtone_files.sh DESTINATION ${TEST_INSTALL_DIR})
index c564ae4..b381e11 100644 (file)
 
 API int access(const char *pathname, int mode)
 {
-       if (0 == strcmp(pathname, "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"))
+       if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/ringtone_sdk.mp3"))
                return 0;
-       if (0 == strcmp(pathname, "/opt/usr/data/settings/Alerts/Over the horizon.mp3"))
+       if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/Over the horizon.mp3"))
                return 0;
-       if (0 == strcmp(pathname, "/usr/bin/sys-settings/ringtone_sdk.mp3"))
+       if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/big_buck_bunny.mp3"))
                return 0;
-       if (0 == strcmp(pathname, "/opt/usr/test/big_buck_bunny.mp4"))
+       if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/daliTestVideo.mp3"))
                return 0;
-       if (0 == strcmp(pathname, "/opt/usr/test/daliTestVideo.mp4"))
+       if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/sound_5.mp3"))
                return 0;
-       if (0 == strcmp(pathname, "/opt/usr/test/sound_5.wav"))
-               return 0;
-       if (0 == strcmp(pathname, "/opt/usr/test/tct-content-tizen-tests_video.mp4"))
+       if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/tct-content-tizen-tests_video.mp3"))
                return 0;
 
        int (*org_fn)(const char *, int);
diff --git a/tests/scripts/ringtone_files.sh b/tests/scripts/ringtone_files.sh
new file mode 100755 (executable)
index 0000000..6230f01
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+ARG=$1
+CURRENT_DIR="$( cd "$(dirname $(readlink -f "$0"))" ; pwd -P )"
+RINGTONE_FILENAME="$CURRENT_DIR/ringtone_sdk.mp3"
+
+echo $ARG
+echo $BASE_PATH
+
+if [[ $ARG == "create" ]]; then
+       cp -rf "$RINGTONE_FILENAME" "$CURRENT_DIR/Over the horizon.mp3"
+       cp -rf "$RINGTONE_FILENAME" "$CURRENT_DIR/big_buck_bunny.mp3"
+       cp -rf "$RINGTONE_FILENAME" "$CURRENT_DIR/daliTestVideo.mp3"
+       cp -rf "$RINGTONE_FILENAME" "$CURRENT_DIR/sound_5.mp3"
+       cp -rf "$RINGTONE_FILENAME" "$CURRENT_DIR/tct-content-tizen-tests_video.mp3"
+fi
+
+if [[ $ARG == "del" ]]; then
+       rm "$CURRENT_DIR/Over the horizon.mp3"
+       rm "$CURRENT_DIR/big_buck_bunny.mp3"
+       rm "$CURRENT_DIR/daliTestVideo.mp3"
+       rm "$CURRENT_DIR/sound_5.mp3"
+       rm "$CURRENT_DIR/tct-content-tizen-tests_video.mp3"
+fi
index f0fe221..1c5f800 100644 (file)
@@ -120,6 +120,13 @@ static int my_assert_ret_eq_bool(int retcode, bool a, bool b)
 } while (0)
 #endif
 
+static char *sst_ringtone_test_files[] = {
+       SYS_SETTINGS_TEST_DIR"/Over the horizon.mp3",
+       SYS_SETTINGS_TEST_DIR"/big_buck_bunny.mp3",
+       SYS_SETTINGS_TEST_DIR"/daliTestVideo.mp3",
+       SYS_SETTINGS_TEST_DIR"/sound_5.mp3",
+       SYS_SETTINGS_TEST_DIR"/tct-content-tizen-tests_video.mp3"
+};
 
 system_settings_changed_cb get_system_settings_test_callback()
 {
@@ -2659,71 +2666,44 @@ RETTYPE utc_system_settings_unset_changed_cb_p32(void)
        RETURN(0);
 }
 
-static int cb_count;
 static bool system_setting_get_ringtone_list_cb(int index, const char* data, void *user_data)
 {
-       cb_count += 1;
-       //printf("%s\n", (char*)data);
+       int *ringtone_num = user_data;
+       *ringtone_num += 1;
        return true;
 }
 
 RETTYPE utc_system_settings_add_ringtone_list_p1(void)
 {
        int retcode = -1;
-       cb_count = 0;
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/big_buck_bunny.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/daliTestVideo.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/sound_5.wav");
-       my_assert_ret(retcode);
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/tct-content-tizen-tests_video.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_foreach_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, system_setting_get_ringtone_list_cb, NULL);
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/tct-content-tizen-tests_video.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/sound_5.wav");
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/daliTestVideo.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/big_buck_bunny.mp4");
-
+       int files_cnt = sizeof(sst_ringtone_test_files)/sizeof(char*);
+       int ringtone_num = 0;
+       for (int i = 0; i < files_cnt; i++) {
+               retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, sst_ringtone_test_files[i]);
+               my_assert_ret(retcode);
+       }
+       retcode = system_settings_foreach_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, system_setting_get_ringtone_list_cb, &ringtone_num);
        my_assert_ret(retcode);
-       assert_eq(cb_count, 5);
-
+       for (int i = files_cnt - 1; i >= 0; i--) {
+               retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, sst_ringtone_test_files[i]);
+               my_assert_ret(retcode);
+       }
+       assert_eq(ringtone_num, files_cnt + 1);
        RETURN(0);
 }
 
-/**
- * @function           utc_system_settings_delete_ringtone_list_p1_startup
- * @description                Called before each test
- * @parameter          NA
- * @return                     NA
- */
-
-/* system_settings - del ringtone list */
 RETTYPE utc_system_settings_delete_ringtone_list_p1(void)
 {
        int retcode = -1;
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/big_buck_bunny.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/daliTestVideo.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/sound_5.wav");
-       my_assert_ret(retcode);
-       retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/tct-content-tizen-tests_video.mp4");
-       my_assert_ret(retcode);
-
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/tct-content-tizen-tests_video.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/sound_5.wav");
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/daliTestVideo.mp4");
-       my_assert_ret(retcode);
-       retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/usr/test/big_buck_bunny.mp4");
-       my_assert_ret(retcode);
-
+       int files_cnt = sizeof(sst_ringtone_test_files)/sizeof(char*);
+       for (int i = 0; i < files_cnt; i++) {
+               retcode = system_settings_add_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, sst_ringtone_test_files[i]);
+               my_assert_ret(retcode);
+       }
+       for (int i = files_cnt - 1; i >= 0; i--) {
+               retcode = system_settings_delete_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, sst_ringtone_test_files[i]);
+               my_assert_ret(retcode);
+       }
        RETURN(0);
 }