[glom/import_csv_refactored] More minor cleanup, such as removing non-public functions from the header.



commit 3ad3d0c3d47b0db086c1ccfecfdc7a5d28371c66
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Sep 25 15:33:39 2009 +0200

    More minor cleanup, such as removing non-public functions from the header.

 tests/import/utils.cc |   46 +++++++++++++++++++++++++---------------------
 tests/import/utils.h  |   10 ----------
 2 files changed, 25 insertions(+), 31 deletions(-)
---
diff --git a/tests/import/utils.cc b/tests/import/utils.cc
index 341ea9f..e946e0b 100644
--- a/tests/import/utils.cc
+++ b/tests/import/utils.cc
@@ -11,17 +11,14 @@ bool check(const std::string& name, bool test, std::stringstream& report)
   return test;
 }
 
-void set_parser_contents(Glom::CsvParser& /*parser*/, const char* /*input*/, guint /*size*/)
+// Returns the file name of the temporary created file, which will contain the buffer's contents.
+static std::string create_file_from_buffer(const char* input, guint size)
 {
-}
-
-std::string create_file_from_buffer(const char* input, guint size)
-{
-  // use Glib's file utilities to get an unique tmp filename
+  // Use Glib's file utilities to get a unique temporary filename:
   std::string tmp_filename;
-  int tmp_file_handle = Glib::file_open_tmp(tmp_filename, "glom_testdata");
+  const int tmp_file_handle = Glib::file_open_tmp(tmp_filename, "glom_testdata");
 
-  if (0 < tmp_file_handle)
+  if(0 < tmp_file_handle)
   {
     ssize_t result = write(tmp_file_handle, input, size);
     g_assert(-1 != result); // g_return_with_val would still be wrong here, I think?
@@ -32,52 +29,59 @@ std::string create_file_from_buffer(const char* input, guint size)
   return Glib::filename_to_uri(tmp_filename);
 }
 
-Glib::RefPtr<Glib::MainLoop>& get_mainloop_instance()
+static Glib::RefPtr<Glib::MainLoop>& get_mainloop_instance()
 {
   static Glib::RefPtr<Glib::MainLoop> mainloop(0);
   return mainloop;
 }
 
-bool& get_result_instance()
+static bool& get_result_instance()
 {
   static bool result = true;
   return result;
 }
 
-void on_mainloop_killed_by_watchdog()
+static void on_mainloop_killed_by_watchdog()
 {
   get_result_instance() = false; // Comment out if you want to run tests and get useful results even with a non-working finished_parsing signal.
   get_mainloop_instance()->quit();
 }
 
-typedef sigc::slot<void, Glom::CsvParser&> FuncConnectParserSignals;
-
+static void on_parser_finished()
+{
+  //Quit the mainloop that we ran because the parser uses an idle handler.
+  get_mainloop_instance()->quit();
+}
 
 bool run_parser_from_buffer(const FuncConnectParserSignals& connect_parser_signals, const char* input, guint size)
 {
   get_result_instance() = true;
 
+  //Start a mainloop because the parser uses an idle handler.
+  //TODO: Stop the parser from doing that.
   get_mainloop_instance().reset();
   get_mainloop_instance() = Glib::MainLoop::create();
 
   Glom::CsvParser parser("UTF-8");
 
-  parser.signal_finished_parsing().connect(sigc::mem_fun(*get_mainloop_instance().operator->(), &Glib::MainLoop::quit));
+  parser.signal_finished_parsing().connect(&on_parser_finished);
 
-  // Install a watchdog for the mainloop, no test should need longer than 3
-  // seconds. Also, we need to guard against being stuck in the mainloop.
+  // Install a watchdog for the mainloop. No test should need longer than 3
+  // seconds. Also, we need to avoid being stuck in the mainloop.
   // Infinitely running tests are useless.
-  get_mainloop_instance()->get_context()->signal_timeout().connect_seconds_once(sigc::ptr_fun(&on_mainloop_killed_by_watchdog), 3);
+  get_mainloop_instance()->get_context()->signal_timeout().connect_seconds_once(
+    sigc::ptr_fun(&on_mainloop_killed_by_watchdog), 3);
 
   connect_parser_signals(parser);
 
-  const std::string file_name = create_file_from_buffer(input, size);
-  parser.set_file_and_start_parsing(file_name);
+  const std::string file_uri = create_file_from_buffer(input, size);
+  parser.set_file_and_start_parsing(file_uri);
 
   get_mainloop_instance()->run();
 
-  int result = unlink(Glib::filename_from_uri(file_name).c_str());
-  g_assert(-1 != result);
+  Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(file_uri);
+  const bool removed = file->remove();
+  g_assert(removed);
 
   return get_result_instance();
 }
diff --git a/tests/import/utils.h b/tests/import/utils.h
index ee24b85..40bf321 100644
--- a/tests/import/utils.h
+++ b/tests/import/utils.h
@@ -12,18 +12,8 @@ namespace ImportTests
 
 bool check(const std::string& name, bool test, std::stringstream& report);
 
-/// This takes a @a size argument so we can test parsing of null bytes.
-void set_parser_contents(Glom::CsvParser& parser, const char* input, guint size);
-
-// Returns the file name of the temporary created file, which will contain the buffer's contents.
-std::string create_file_from_buffer(const char* input, guint size);
-
 typedef sigc::slot<void, Glom::CsvParser&> FuncConnectParserSignals;
 bool run_parser_from_buffer(const FuncConnectParserSignals& connect_parser_signals, const char* input, guint size);
 
-void on_mainloop_killed_by_watchdog();
-Glib::RefPtr<Glib::MainLoop>& get_mainloop_instance();
-bool& get_result_instance();
-
 } //namespace ImportTests
 #endif



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