[glom/import_csv_refactored] Import tests: Handle encoding errors.



commit 8870f34e19b545c1f5d1b2b838dd31bcf12cb7bf
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Sep 25 16:14:28 2009 +0200

    Import tests: Handle encoding errors.
    
    * tests/import/utils.cc: Handle signal_encoding_error too, because this
    is one way that the parser can stop.
    Increase the timeout because an infinite loop is unlikely (and not
    currently happening).

 ChangeLog                     |    9 +++++++++
 glom/import_csv/csv_parser.cc |   13 +++++++------
 tests/import/test_parsing.cc  |    5 +++--
 tests/import/utils.cc         |   13 ++++++++++++-
 4 files changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 842b146..99f2148 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-09-25  Murray Cumming  <murrayc murrayc-desktop>
+
+	Import tests: Handle encoding errors.
+
+	* tests/import/utils.cc: Handle signal_encoding_error too, because this
+	is one way that the parser can stop.
+	Increase the timeout because an infinite loop is unlikely (and not 
+	currently happening).
+
 2009-09-25  Murray Cumming  <murrayc murrayc com>
 
 	tests/import/: Small cleanup.
diff --git a/glom/import_csv/csv_parser.cc b/glom/import_csv/csv_parser.cc
index ccb1f5d..5e4943a 100644
--- a/glom/import_csv/csv_parser.cc
+++ b/glom/import_csv/csv_parser.cc
@@ -271,7 +271,7 @@ bool CsvParser::on_idle_parse()
       // Invalid text in the current encoding.
       set_state(STATE_ENCODING_ERROR);
       signal_encoding_error().emit();
-      return false;
+      return false; //Stop calling the idle handler.
     }
 
     // If EINVAL is set, this means that an incomplete multibyte sequence was at
@@ -285,7 +285,7 @@ bool CsvParser::on_idle_parse()
         // should not end with an incomplete multibyte sequence.
         set_state(STATE_ENCODING_ERROR);
         signal_encoding_error().emit();
-        return false;
+        return false; //Stop calling the idle handler.
       }
       else
       {
@@ -332,7 +332,7 @@ bool CsvParser::on_idle_parse()
       // it just contains lots of nullbytes). We therefore produce an error here.
       set_state(STATE_ENCODING_ERROR);
       signal_encoding_error().emit();
-      return false;
+      return false;  //Stop calling the idle handler.
     }
     else if(in_quotes)
     {
@@ -399,7 +399,7 @@ bool CsvParser::on_idle_parse()
   }
 
   // Continue if there are more bytes to process
-  return more_to_process;
+  return more_to_process; //false means stop calling the idle handler.
 }
 
 void CsvParser::do_line_scanned(const Glib::ustring& line, guint line_number)
@@ -439,7 +439,8 @@ void CsvParser::on_file_read(const Glib::RefPtr<Gio::AsyncResult>& result)
   // TODO: Introduce CsvParser::is_idle_handler_connected() instead?
   if(!m_idle_connection.connected())
   {
-    m_idle_connection = Glib::signal_idle().connect(sigc::mem_fun(*this, &CsvParser::on_idle_parse));
+    m_idle_connection = Glib::signal_idle().connect(
+      sigc::mem_fun(*this, &CsvParser::on_idle_parse));
   }
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -499,7 +500,7 @@ void CsvParser::on_buffer_read(const Glib::RefPtr<Gio::AsyncResult>& result)
   }
   catch(const Glib::Exception& ex)
   {
-     signal_file_read_error().emit(ex.what());
+    signal_file_read_error().emit(ex.what());
     clear();
   }
 #else
diff --git a/tests/import/test_parsing.cc b/tests/import/test_parsing.cc
index 30f64ff..0a71670 100644
--- a/tests/import/test_parsing.cc
+++ b/tests/import/test_parsing.cc
@@ -19,13 +19,13 @@ type_tokens& get_tokens_instance()
 
 void on_line_scanned(const std::vector<Glib::ustring>& row, guint /*line_number*/)
 {
-  std::cout << "debug: on_line_scanned(): row.size()=" << row.size() << std::endl;
+  //std::cout << "debug: on_line_scanned(): row.size()=" << row.size() << std::endl;
  
   for(std::vector<Glib::ustring>::const_iterator iter = row.begin();
       iter != row.end();
       ++iter)
   {
-    std::cout << "  debug: on_line_scanned(): item=" << *iter << std::endl;
+    //std::cout << "  debug: on_line_scanned(): item=" << *iter << std::endl;
 
     get_tokens_instance().push_back(*iter);
   }
@@ -84,6 +84,7 @@ bool check_tokens(const std::string& regex)
 void connect_signals(Glom::CsvParser& parser)
 {
   parser.signal_line_scanned().connect(sigc::ptr_fun(&on_line_scanned));
+  //parser.signal_encoding_error().connect(sigc::ptr_fun(&on_encoding_error));
 }
 
 } // namespace
diff --git a/tests/import/utils.cc b/tests/import/utils.cc
index e946e0b..17718c3 100644
--- a/tests/import/utils.cc
+++ b/tests/import/utils.cc
@@ -47,6 +47,16 @@ static void on_mainloop_killed_by_watchdog()
   get_mainloop_instance()->quit();
 }
 
+static void on_parser_encoding_error()
+{
+  std::cerr << "debug: utils.cc: on_parser_encoding_error()" << std::endl;
+
+  get_result_instance() = false;
+  //Quit the mainloop that we ran because the parser uses an idle handler.
+  get_mainloop_instance()->quit();
+}
+
+
 static void on_parser_finished()
 {
   //Quit the mainloop that we ran because the parser uses an idle handler.
@@ -64,13 +74,14 @@ bool run_parser_from_buffer(const FuncConnectParserSignals& connect_parser_signa
 
   Glom::CsvParser parser("UTF-8");
 
+  parser.signal_encoding_error().connect(&on_parser_encoding_error);
   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 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);
+    sigc::ptr_fun(&on_mainloop_killed_by_watchdog), 300);
 
   connect_parser_signals(parser);
 



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