static void
test_copy_one_empty_directory (void)
{
    g_autoptr (GFile) root = NULL;
    g_autoptr (GFile) first_dir = NULL;
    g_autoptr (GFile) second_dir = NULL;
    g_autoptr (GFile) file = NULL;
    g_autoptr (GFile) result_file = NULL;
    g_autolist (GFile) files = NULL;

    create_one_empty_directory ("copy");

    root = g_file_new_for_path (g_get_tmp_dir ());
    g_assert_true (root != NULL);
    first_dir = g_file_get_child (root, "copy_first_dir");
    g_assert_true (first_dir != NULL);

    file = g_file_get_child (first_dir, "copy_first_dir_child");
    g_assert_true (file != NULL);
    files = g_list_prepend (files, g_object_ref (file));

    second_dir = g_file_get_child (root, "copy_second_dir");
    g_assert_true (second_dir != NULL);

    nautilus_file_operations_copy_sync (files,
                                        second_dir);

    result_file = g_file_get_child (second_dir, "copy_first_dir_child");
    g_assert_true (g_file_query_exists (result_file, NULL));
    g_assert_true (g_file_query_exists (file, NULL));

    empty_directory_by_prefix (root, "copy");
}
예제 #2
0
파일: autoptr.c 프로젝트: endlessm/glib
static void
test_autolist (void)
{
  char data[1] = {0};
  gboolean freed1 = FALSE;
  gboolean freed2 = FALSE;
  gboolean freed3 = FALSE;
  GBytes *b1 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed1);
  GBytes *b2 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed2);
  GBytes *b3 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed3);

  {
    g_autolist(GBytes) l = NULL;

    l = g_list_prepend (l, b1);
    l = g_list_prepend (l, b3);
  }

  /* Only assert if autoptr works */
#ifdef __GNUC__
  g_assert (freed1);
  g_assert (freed3);
#endif
  g_assert (!freed2);

  g_bytes_unref (b2);
  g_assert (freed2);
}
static void
test_copy_directories_medium_undo (void)
{
    g_autoptr (GFile) root = NULL;
    g_autoptr (GFile) file = NULL;
    g_autoptr (GFile) dir = NULL;
    g_autolist (GFile) files = NULL;
    gchar *file_name;

    create_multiple_directories ("copy", 1000);

    root = g_file_new_for_path (g_get_tmp_dir ());
    g_assert_true (root != NULL);

    for (int i = 0; i < 1000; i++)
    {
        file_name = g_strdup_printf ("copy_file_%i", i);
        file = g_file_get_child (root, file_name);
        g_free (file_name);
        g_assert_true (file != NULL);
        files = g_list_prepend (files, g_object_ref (file));
    }

    dir = g_file_get_child (root, "copy_dir");
    g_assert_true (dir != NULL);

    nautilus_file_operations_copy_sync (files,
                                        dir);

    test_operation_undo ();

    for (int i = 0; i < 1000; i++)
    {
        file_name = g_strdup_printf ("copy_file_%i", i);
        file = g_file_get_child (dir, file_name);
        g_assert_false (g_file_query_exists (file, NULL));
        file = g_file_get_child (root, file_name);
        g_free (file_name);
        g_assert_true (g_file_query_exists (file, NULL));
    }

    g_assert_true (g_file_query_exists (dir, NULL));

    empty_directory_by_prefix (root, "copy");
}