[gtksourceview/wip/loader-saver] Adapt FileLoader unit tests



commit df8d878bbcad17cef0536a30fc2077d8b31cb47a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Mar 26 21:00:03 2014 +0100

    Adapt FileLoader unit tests

 tests/Makefile.am        |   12 +++---
 tests/test-file-loader.c |   78 +++++++++++++++++++--------------------------
 2 files changed, 39 insertions(+), 51 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8b246b9..e4b13ba 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,12 +100,12 @@ test_completion_words_LDADD =                                     \
        $(DEP_LIBS)                                             \
        $(TESTS_LIBS)
 
-#UNIT_TEST_PROGS += test-file-loader
-#test_file_loader_SOURCES = test-file-loader.c
-#test_file_loader_LDADD =                                      \
-#      $(top_builddir)/gtksourceview/libgtksourceview-3.0.la   \
-#      $(DEP_LIBS)                                             \
-#      $(TESTS_LIBS)
+UNIT_TEST_PROGS += test-file-loader
+test_file_loader_SOURCES = test-file-loader.c
+test_file_loader_LDADD =                                       \
+       $(top_builddir)/gtksourceview/libgtksourceview-3.0.la   \
+       $(DEP_LIBS)                                             \
+       $(TESTS_LIBS)
 
 UNIT_TEST_PROGS += test-file-saver
 test_file_saver_SOURCES = test-file-saver.c
diff --git a/tests/test-file-loader.c b/tests/test-file-loader.c
index 5b4143c..6f4ac84 100644
--- a/tests/test-file-loader.c
+++ b/tests/test-file-loader.c
@@ -29,52 +29,26 @@ typedef struct
        gint newline_type;
 } LoaderTestData;
 
-static GtkSourceFile *
-create_file (const gchar *filename,
-            const gchar *contents)
-{
-       GError *error = NULL;
-       GFile *location;
-       GtkSourceBuffer *buffer;
-       GtkSourceFile *file;
-
-       g_file_set_contents (filename, contents, -1, &error);
-       g_assert_no_error (error);
-
-       location = g_file_new_for_path (filename);
-       buffer = gtk_source_buffer_new (NULL);
-
-       file = gtk_source_file_new (location, buffer);
-       g_object_unref (location);
-       g_object_unref (buffer);
-
-       return file;
-}
-
 static void
-delete_file (GtkSourceFile *file)
+delete_file (GFile *file)
 {
-       GFile *location = gtk_source_file_get_location (file);
-
-       if (g_file_query_exists (location, NULL))
+       if (g_file_query_exists (file, NULL))
        {
                GError *error = NULL;
 
-               g_file_delete (location, NULL, &error);
+               g_file_delete (file, NULL, &error);
                g_assert_no_error (error);
        }
-
-       g_object_unref (location);
 }
 
 static void
-load_file_cb (GtkSourceFile  *file,
-             GAsyncResult   *result,
-             LoaderTestData *data)
+load_file_cb (GtkSourceFileLoader *loader,
+             GAsyncResult        *result,
+             LoaderTestData      *data)
 {
        GError *error = NULL;
 
-       gtk_source_file_load_finish (file, result, &error);
+       gtk_source_file_loader_load_finish (loader, result, &error);
        g_assert_no_error (error);
 
        if (data->expected_buffer_contents != NULL)
@@ -84,7 +58,7 @@ load_file_cb (GtkSourceFile  *file,
                GtkTextIter end;
                gchar *buffer_contents;
 
-               buffer = GTK_TEXT_BUFFER (gtk_source_file_get_buffer (file));
+               g_object_get (loader, "buffer", &buffer, NULL);
 
                gtk_text_buffer_get_bounds (buffer, &start, &end);
                buffer_contents = gtk_text_iter_get_slice (&start, &end);
@@ -96,7 +70,7 @@ load_file_cb (GtkSourceFile  *file,
 
        if (data->newline_type != -1)
        {
-               g_assert_cmpint (gtk_source_file_get_newline_type (file),
+               g_assert_cmpint (gtk_source_file_loader_get_newline_type (loader),
                                 ==,
                                 data->newline_type);
        }
@@ -111,30 +85,44 @@ test_loader (const gchar *filename,
              const gchar *expected_buffer_contents,
              gint         newline_type)
 {
-       GtkSourceFile *file;
+       GFile *file;
+       GtkSourceBuffer *buffer;
+       GtkSourceFileLoader *loader;
+       GSList *candidate_encodings;
        LoaderTestData *data;
+       GError *error = NULL;
 
-       file = create_file (filename, contents);
+       g_file_set_contents (filename, contents, -1, &error);
+       g_assert_no_error (error);
+
+       file = g_file_new_for_path (filename);
+       buffer = gtk_source_buffer_new (NULL);
 
-       gtk_source_file_set_encoding (file, gtk_source_encoding_get_utf8 ());
+       loader = gtk_source_file_loader_new (buffer, file);
+
+       candidate_encodings = g_slist_prepend (NULL, (gpointer) gtk_source_encoding_get_utf8 ());
+       gtk_source_file_loader_set_candidate_encodings (loader, candidate_encodings);
 
        data = g_slice_new (LoaderTestData);
        data->expected_buffer_contents = expected_buffer_contents;
        data->newline_type = newline_type;
 
-       gtk_source_file_load_async (file,
-                                   G_PRIORITY_DEFAULT,
-                                   NULL,
-                                   NULL,
-                                   NULL,
-                                   (GAsyncReadyCallback) load_file_cb,
-                                   data);
+       gtk_source_file_loader_load_async (loader,
+                                          G_PRIORITY_DEFAULT,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          (GAsyncReadyCallback) load_file_cb,
+                                          data);
 
        gtk_main ();
 
        g_slice_free (LoaderTestData, data);
        delete_file (file);
        g_object_unref (file);
+       g_object_unref (buffer);
+       g_object_unref (loader);
+       g_slist_free (candidate_encodings);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]