fileselector: Make selected_set actually select the file
authorRyuan Choi <ryuan.choi@gmail.com>
Tue, 1 Jul 2014 22:55:53 +0000 (07:55 +0900)
committerRyuan Choi <ryuan.choi@gmail.com>
Tue, 1 Jul 2014 22:58:45 +0000 (07:58 +0900)
This patch comes from Kai Huuhko.

Added test case for selected_set/get.

@fix

legacy/elementary/src/lib/elc_fileselector.c
legacy/elementary/src/tests/elm_test_fileselector.c

index 0f6903c..106b910 100644 (file)
@@ -1902,7 +1902,7 @@ _elm_fileselector_elm_interface_fileselector_selected_set(Eo *obj, Elm_Fileselec
           }
 
         selected = ecore_file_dir_get(path);
-        _populate(obj, selected, NULL, NULL);
+        _populate(obj, selected, NULL, path);
         eina_stringshare_replace(&sd->selection, path);
         free(selected);
      }
index 5d09430..e5dd067 100644 (file)
@@ -27,8 +27,67 @@ START_TEST (elm_atspi_role_get)
 }
 END_TEST
 
+static void
+_directory_open_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+    Eina_Bool *ret = data;
+    *ret = EINA_TRUE;
+}
+
+START_TEST (elm_fileselector_selected)
+{
+   Evas_Object *win, *fileselector;
+   Eina_Tmpstr *tmp_path;
+   Eina_Stringshare *exist, *no_exist;
+   FILE *fp;
+   char *path;
+   Eina_Bool selected;
+
+   elm_init(1, NULL);
+
+   if (!eina_file_mkdtemp("elm_test-XXXXXX", &tmp_path))
+     {
+        /* can not test */
+        ck_assert(EINA_FALSE);
+        return;
+     }
+
+   path = strdup(tmp_path);
+   eina_tmpstr_del(tmp_path);
+
+   exist = eina_stringshare_printf("%s/exist", path);
+   no_exist = eina_stringshare_printf("%s/no_exist", path);
+   fp = fopen(exist, "w");
+   fclose(fp);
+
+   win = elm_win_add(NULL, "fileselector", ELM_WIN_BASIC);
+
+   fileselector = elm_fileselector_add(win);
+   evas_object_smart_callback_add(fileselector, "directory,open", _directory_open_cb, &selected);
+
+   ck_assert(!elm_fileselector_selected_set(fileselector, no_exist));
+
+   selected = EINA_FALSE;
+   ck_assert(elm_fileselector_selected_set(fileselector, path));
+   while (!selected) ecore_main_loop_iterate();
+   ck_assert_str_eq(elm_fileselector_selected_get(fileselector), path);
+
+   selected = EINA_FALSE;
+   ck_assert(elm_fileselector_selected_set(fileselector, exist));
+   while (!selected) ecore_main_loop_iterate();
+   ck_assert_str_eq(elm_fileselector_selected_get(fileselector), exist);
+
+   eina_stringshare_del(exist);
+   eina_stringshare_del(no_exist);
+   free(path);
+
+   elm_shutdown();
+}
+END_TEST
+
 void elm_test_fileselector(TCase *tc)
 {
- tcase_add_test(tc, elm_atspi_role_get);
+   tcase_add_test(tc, elm_atspi_role_get);
+   tcase_add_test(tc, elm_fileselector_selected);
 }