[tepl] File loading: move function useful for unit tests to FileContent



commit 6a9ab8ff957dd35786169149c70454e411363692
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Oct 22 12:55:15 2017 +0200

    File loading: move function useful for unit tests to FileContent

 tepl/tepl-file-content.c     |   19 ++++++++++++++++++-
 tepl/tepl-file-content.h     |    3 +++
 tepl/tepl-file-loader.c      |   18 ------------------
 tepl/tepl-file-loader.h      |    3 ---
 testsuite/test-file-loader.c |    3 ++-
 5 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/tepl/tepl-file-content.c b/tepl/tepl-file-content.c
index 785d3f0..66f8a43 100644
--- a/tepl/tepl-file-content.c
+++ b/tepl/tepl-file-content.c
@@ -27,6 +27,9 @@ struct _TeplFileContentPrivate
        GQueue *chunks;
 };
 
+/* Take the default buffer-size of TeplEncodingConverter. */
+#define ENCODING_CONVERTER_BUFFER_SIZE (-1)
+
 G_DEFINE_TYPE_WITH_PRIVATE (TeplFileContent, _tepl_file_content, G_TYPE_OBJECT)
 
 static gboolean
@@ -221,7 +224,7 @@ _tepl_file_content_convert_to_utf8 (TeplFileContent                 *content,
        g_return_val_if_fail (from_encoding != NULL, FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-       converter = _tepl_encoding_converter_new (-1);
+       converter = _tepl_encoding_converter_new (ENCODING_CONVERTER_BUFFER_SIZE);
        _tepl_encoding_converter_set_callback (converter, callback, callback_user_data);
 
        if (!_tepl_encoding_converter_open (converter,
@@ -258,3 +261,17 @@ out:
        g_object_unref (converter);
        return success;
 }
+
+/* For the unit tests. */
+gint64
+_tepl_file_content_get_encoding_converter_buffer_size (void)
+{
+       TeplEncodingConverter *converter;
+       gint64 buffer_size;
+
+       converter = _tepl_encoding_converter_new (ENCODING_CONVERTER_BUFFER_SIZE);
+       buffer_size = _tepl_encoding_converter_get_buffer_size (converter);
+       g_object_unref (converter);
+
+       return buffer_size;
+}
diff --git a/tepl/tepl-file-content.h b/tepl/tepl-file-content.h
index 74456ae..9afa5f1 100644
--- a/tepl/tepl-file-content.h
+++ b/tepl/tepl-file-content.h
@@ -69,6 +69,9 @@ gboolean              _tepl_file_content_convert_to_utf8      (TeplFileContent              
   *c
                                                                 gpointer                         
callback_user_data,
                                                                 GError                         **error);
 
+G_GNUC_INTERNAL
+gint64                 _tepl_file_content_get_encoding_converter_buffer_size (void);
+
 G_END_DECLS
 
 #endif /* TEPL_FILE_CONTENT_H */
diff --git a/tepl/tepl-file-loader.c b/tepl/tepl-file-loader.c
index 4d00b80..b1b3e5c 100644
--- a/tepl/tepl-file-loader.c
+++ b/tepl/tepl-file-loader.c
@@ -25,7 +25,6 @@
 #include "tepl-file-content.h"
 #include "tepl-file-content-loader.h"
 #include "tepl-encoding.h"
-#include "tepl-encoding-converter.h"
 
 /**
  * SECTION:file-loader
@@ -112,9 +111,6 @@ enum
        N_PROPERTIES
 };
 
-/* Take the default buffer-size of TeplEncodingConverter. */
-#define ENCODING_CONVERTER_BUFFER_SIZE (-1)
-
 static GParamSpec *properties[N_PROPERTIES];
 
 G_DEFINE_TYPE_WITH_PRIVATE (TeplFileLoader, tepl_file_loader, G_TYPE_OBJECT)
@@ -1210,17 +1206,3 @@ tepl_file_loader_get_newline_type (TeplFileLoader *loader)
        priv = tepl_file_loader_get_instance_private (loader);
        return priv->detected_newline_type;
 }
-
-/* For the unit tests. */
-gint64
-_tepl_file_loader_get_encoding_converter_buffer_size (void)
-{
-       TeplEncodingConverter *converter;
-       gint64 buffer_size;
-
-       converter = _tepl_encoding_converter_new (ENCODING_CONVERTER_BUFFER_SIZE);
-       buffer_size = _tepl_encoding_converter_get_buffer_size (converter);
-       g_object_unref (converter);
-
-       return buffer_size;
-}
diff --git a/tepl/tepl-file-loader.h b/tepl/tepl-file-loader.h
index d999aaf..1f8e333 100644
--- a/tepl/tepl-file-loader.h
+++ b/tepl/tepl-file-loader.h
@@ -98,9 +98,6 @@ const TeplEncoding *  tepl_file_loader_get_encoding                           
(TeplFileLoader *loader);
 
 TeplNewlineType                tepl_file_loader_get_newline_type                       (TeplFileLoader 
*loader);
 
-G_GNUC_INTERNAL
-gint64                 _tepl_file_loader_get_encoding_converter_buffer_size    (void);
-
 G_END_DECLS
 
 #endif /* TEPL_FILE_LOADER_H */
diff --git a/testsuite/test-file-loader.c b/testsuite/test-file-loader.c
index 4746146..f7e6998 100644
--- a/testsuite/test-file-loader.c
+++ b/testsuite/test-file-loader.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <tepl/tepl.h>
+#include "tepl/tepl-file-content.h"
 
 #define DEFAULT_CONTENTS "My shiny content!"
 #define MAX_SIZE 10000
@@ -331,7 +332,7 @@ test_split_cr_lf (void)
        gchar *content;
        gint expected_line_count;
 
-       block_size = _tepl_file_loader_get_encoding_converter_buffer_size ();
+       block_size = _tepl_file_content_get_encoding_converter_buffer_size ();
        /* Remove terminating nul byte */
        block_size--;
 


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