[glom/import_csv_refactored] Import: made the tests runnable again.



commit d9a45317139942d0ff2481f41038ed053d01ca9a
Author: Michael Hasselmann <michaelh openismus com>
Date:   Wed Sep 23 14:05:33 2009 +0200

    Import: made the tests runnable again.

 Makefile_tests.am                    |   12 ++++++------
 glom/import_csv/csv_parser.h         |    4 ++++
 glom/import_csv/dialog_import_csv.cc |    2 +-
 tests/import/test_parsing.cc         |   10 +++++++---
 tests/import/test_signals.cc         |    5 ++++-
 tests/import/utils.cc                |    4 ++--
 tests/import/utils.h                 |    2 +-
 7 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/Makefile_tests.am b/Makefile_tests.am
index f6441b8..e8ca5a1 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -48,14 +48,14 @@ tests_test_parsing_time_SOURCES = tests/test_parsing_time.cc
 tests_test_signal_reemit_SOURCES = tests/test_signal_reemit.cc
 tests_test_load_python_library_SOURCES = tests/test_load_python_library.cc
 tests_import_test_parsing_SOURCES =	\
-	glom/import/csv_parser.cc	\
-	glom/import/csv_parser.h	\
+	glom/import_csv/csv_parser.cc	\
+	glom/import_csv/csv_parser.h	\
 	tests/import/utils.cc\
 	tests/import/utils.h\
 	tests/import/test_parsing.cc
 tests_import_test_signals_SOURCES =	\
-	glom/import/csv_parser.cc	\
-	glom/import/csv_parser.h	\
+	glom/import_csv/csv_parser.cc	\
+	glom/import_csv/csv_parser.h	\
 	tests/import/utils.cc\
 	tests/import/utils.h\
 	tests/import/test_signals.cc
@@ -84,5 +84,5 @@ tests_test_parsing_time_LDADD = $(tests_ldadd)
 tests_test_signal_reemit_LDADD = $(LIBGLOM_LIBS)
 tests_test_load_python_library_LDADD = $(LIBGLOM_LIBS)
 tests_test_python_module_LDADD = $(LIBGLOM_LIBS) $(PYTHON_LIBS) glom/libglom/libglom-$(GLOM_ABI_VERSION).la
-tests_import_test_parsing_LDADD = $(LIBGLOM_LIBS)
-tests_import_test_signals_LDADD = $(LIBGLOM_LIBS)
+tests_import_test_parsing_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
+tests_import_test_signals_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
diff --git a/glom/import_csv/csv_parser.h b/glom/import_csv/csv_parser.h
index fcb0893..41f77e3 100644
--- a/glom/import_csv/csv_parser.h
+++ b/glom/import_csv/csv_parser.h
@@ -133,8 +133,10 @@ private:
 
   // In order to not make the UI feel sluggish during larger imports we parse
   // on chunk at a time in the idle handler.
+public:  // public because it is needed for testing => no main loop
   bool on_idle_parse();
 
+private:
   void begin_parse();
 
   static const gunichar DELIMITER = ',';
@@ -145,8 +147,10 @@ private:
   void do_line_scanned(const Glib::ustring& current_line, guint line_number);
 
   //TODO: Document this:
+public: // public because it is needed for testing => no main loop
   static Glib::ustring::const_iterator advance_field(const Glib::ustring::const_iterator& iter, const Glib::ustring::const_iterator& end, Glib::ustring& field);
 
+private:
   void on_file_read(const Glib::RefPtr<Gio::AsyncResult>& result);
   void on_stream_read(const Glib::RefPtr<Gio::AsyncResult>& result);
   void on_file_query_info(const Glib::RefPtr<Gio::AsyncResult>& result);
diff --git a/glom/import_csv/dialog_import_csv.cc b/glom/import_csv/dialog_import_csv.cc
index e10bac3..c00d118 100644
--- a/glom/import_csv/dialog_import_csv.cc
+++ b/glom/import_csv/dialog_import_csv.cc
@@ -466,7 +466,7 @@ void Dialog_Import_CSV::on_parser_encoding_error()
 /*
  * No, this is wrong. Creating the tree model and handling a line from the CSV file are two separate steps. Proposal: Construct tree model *after* parsing, using row[0].
  */
-void Dialog_Import_CSV::on_parser_line_scanned(const Glib::ustring& line, guint row_number)
+void Dialog_Import_CSV::on_parser_line_scanned(const Glib::ustring& /*line*/, guint row_number)
 {
   // This is the first line read if there is no model yet:
   if(!m_sample_model)
diff --git a/tests/import/test_parsing.cc b/tests/import/test_parsing.cc
index 117868c..733acbd 100644
--- a/tests/import/test_parsing.cc
+++ b/tests/import/test_parsing.cc
@@ -1,7 +1,7 @@
 #include <glom/import_csv/csv_parser.h>
 #include <tests/import/utils.h>
 //#include <glibmm/regex.h>
-#include <glibmm/regex.h>
+#include <gtkmm.h>
 #include <iostream>
 #include <cstdlib>
 
@@ -38,7 +38,7 @@ bool check_tokens(const std::string& regex)
   #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-    check = Glib::Regex::create(regex)
+    check = Glib::Regex::create(regex);
   }
   catch(const Glib::Error& ex)
   {
@@ -91,8 +91,10 @@ void on_line_scanned(const Glib::ustring& line, guint /*line_number*/)
 } // namespace
 
 // Testcases
-int main()
+int main(int argc, char* argv[])
 {
+  Gtk::Main gtk(argc, argv);
+
   Glom::CsvParser parser("UTF-8");
   parser.signal_line_scanned().connect(sigc::ptr_fun(&on_line_scanned));
 
@@ -104,6 +106,8 @@ int main()
     const char raw_line[] = "\"a \"\"quoted\"\" token\",\"sans quotes\"\n";
     ImportTests::set_parser_contents(parser, raw_line, sizeof(raw_line));
 
+    parser.set_file_and_start_parsing("./tests/import/data/dquoted_string.csv");
+
     while(parser.on_idle_parse())
     {}
 
diff --git a/tests/import/test_signals.cc b/tests/import/test_signals.cc
index 2b61b4a..25ddbe7 100644
--- a/tests/import/test_signals.cc
+++ b/tests/import/test_signals.cc
@@ -1,6 +1,7 @@
 #include <glom/import_csv/csv_parser.h>
 #include <tests/import/utils.h>
 //#include <glibmm/regex.h>
+#include <gtkmm.h>
 #include <iostream>
 #include <stdexcept>
 #include <cstdlib>
@@ -46,8 +47,10 @@ void print_signal_counts()
 } // namespace
 
 // Testcases
-int main()
+int main(int argc, char* argv[])
 {
+  Gtk::Main gtk(argc, argv);
+
   Glom::CsvParser parser("UTF-8");
   parser.signal_line_scanned().connect(sigc::hide(sigc::hide(&on_line_scanned)));
   parser.signal_encoding_error().connect(sigc::ptr_fun(&on_encoding_error));
diff --git a/tests/import/utils.cc b/tests/import/utils.cc
index 0a9f868..16de7af 100644
--- a/tests/import/utils.cc
+++ b/tests/import/utils.cc
@@ -11,10 +11,10 @@ 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)
+void set_parser_contents(Glom::CsvParser& /*parser*/, const char* /*input*/, guint /*size*/)
 {
   // Do not read terminating null byte.
-  parser.m_raw = std::vector<char>(input, input + size -1);
+  //parser.m_raw = std::vector<char>(input, input + size -1);
 }
 
 } //namespace ImportTests
diff --git a/tests/import/utils.h b/tests/import/utils.h
index 4088b5c..778dc1d 100644
--- a/tests/import/utils.h
+++ b/tests/import/utils.h
@@ -1,7 +1,7 @@
 #ifndef TEST_IMPORT_UTILS_H
 #define TEST_IMPORT_UTILS_H
 
-#include <glom/import_csv.h>
+#include <glom/import_csv/csv_parser.h>
 #include <iostream>
 
 namespace ImportTests



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