[glom/maemo5] import tests: Fix the no-exceptions build.



commit e9a3437c767f1c475fa14c554152c89b58594fab
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Sep 21 17:55:19 2009 +0200

    import tests: Fix the no-exceptions build.
    
    * tests/import/test_parsing.cc:
    * tests/import/test_signals.cc: Fix the build without exceptions.

 ChangeLog                      |    7 +++++
 glom/libglom/connectionpool.cc |    2 +-
 tests/import/test_parsing.cc   |   48 ++++++++++++++++++++++++++++++---------
 tests/import/test_signals.cc   |   21 +++++++++++-----
 4 files changed, 59 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bd468c1..63d9f36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-09-21  Murray Cumming  <murrayc murrayc com>
+
+	import tests: Fix the no-exceptions build.
+	
+	* tests/import/test_parsing.cc:
+	* tests/import/test_signals.cc: Fix the build without exceptions.
+
 2009-09-21  Johannes Schmid <jschmid openismus com>
 
 	* Makefile_tests.am:
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 73a7bf1..b5bf139 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -644,7 +644,7 @@ bool ConnectionPool::startup(const SlotProgress& slot_progress, bool network_sha
 
   //If we crash while running (unlikely, hopefully), then try to cleanup.
   //Comment this out if you want to see the backtrace in a debugger.
-  //previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
+  previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
 
   return true;
 }
diff --git a/tests/import/test_parsing.cc b/tests/import/test_parsing.cc
index cfec07d..30bdb3f 100644
--- a/tests/import/test_parsing.cc
+++ b/tests/import/test_parsing.cc
@@ -7,11 +7,11 @@
 namespace
 {
 
-typedef std::vector<std::string> Tokens;
+typedef std::vector<std::string> type_tokens;
 
-Tokens& get_tokens_instance()
+type_tokens& get_tokens_instance()
 {
-  static Tokens tokens;
+  static type_tokens tokens;
   return tokens;
 }
 
@@ -20,7 +20,7 @@ void on_line_scanned(const Glib::ustring& line, guint line_number);
 
 void print_tokens()
 {
-  for(Tokens::const_iterator iter = get_tokens_instance().begin();
+  for(type_tokens::const_iterator iter = get_tokens_instance().begin();
        iter != get_tokens_instance().end();
        ++iter)
   {
@@ -30,13 +30,39 @@ void print_tokens()
   std::cout << std::endl;
 }
 
-bool check_tokens(Glib::RefPtr<Glib::Regex> check)
+bool check_tokens(const std::string& regex)
 {
-  for(Tokens::const_iterator iter = get_tokens_instance().begin();
+  Glib::RefPtr<Glib::Regex> check;
+  
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+  {
+    check = Glib::Regex::create(regex)
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cerr << "Glib::Regex::create() failed: " << ex.what() << std::endl;
+    return false;
+  } 
+  #else
+  std::auto_ptr<Glib::Error> ex;
+  check = Glib::Regex::create(regex, static_cast<Glib::RegexCompileFlags>(0), static_cast<Glib::RegexMatchFlags>(0), ex);
+  if(ex.get())
+  {
+    std::cerr << "Glib::Regex::create() failed: " << ex->what() << std::endl;
+    return false;
+  }
+  #endif
+ 
+  if(!check)
+    return false;
+     
+  for(type_tokens::const_iterator iter = get_tokens_instance().begin();
        iter != get_tokens_instance().end();
        ++iter)
   {
-    if(!check->match(*iter)) return false;
+    if(!check->match(*iter))
+      return false;
   }
 
   return true;
@@ -80,7 +106,7 @@ int main()
     while(parser.on_idle_parse())
     {}
 
-    bool passed = check_tokens(Glib::Regex::create("^(a \"quoted\" token|,|sans quotes)$"));
+    bool passed = check_tokens("^(a \"quoted\" token|,|sans quotes)$");
     if(!ImportTests::check("test_dquoted_string", passed, report))
       result = false;
 
@@ -112,7 +138,7 @@ int main()
     while(parser.on_idle_parse())
     {}
 
-    bool passed = check_tokens(Glib::Regex::create("^(|,)$"));
+    bool passed = check_tokens("^(|,)$");
     if(!ImportTests::check("test_skip_on_no_quotes_around_token", passed, report))
       result = false;
 
@@ -144,7 +170,7 @@ int main()
     while(parser.on_idle_parse())
     {}
 
-    bool passed = check_tokens(Glib::Regex::create("^cannottokenizethis$"));
+    bool passed = check_tokens("^cannottokenizethis$");
     if(!ImportTests::check("test_fail_on_non_comma_separators", passed, report))
       result = false;
 
@@ -160,7 +186,7 @@ int main()
     while(parser.on_idle_parse())
     {}
 
-    bool passed = check_tokens(Glib::Regex::create("^(cell with\nnewline|token on next line)$"));
+    bool passed = check_tokens("^(cell with\nnewline|token on next line)$");
     if(!ImportTests::check("test_parse_newline_inside_quotes", passed, report))
       result = false;
 
diff --git a/tests/import/test_signals.cc b/tests/import/test_signals.cc
index 1a45d17..b1df045 100644
--- a/tests/import/test_signals.cc
+++ b/tests/import/test_signals.cc
@@ -7,7 +7,7 @@
 
 namespace {
 
-typedef std::vector<std::string> Encodings;
+typedef std::vector<std::string> type_encodings;
 
 guint& get_line_scanned_count_instance()
 {
@@ -83,7 +83,7 @@ int main()
     while(parser.on_idle_parse())
     {}
 
-    bool passed = (2 == get_line_scanned_count_instance() &&
+    const bool passed = (2 == get_line_scanned_count_instance() &&
                    0 == get_encoding_error_count_instance());
 
     if(!ImportTests::check("test_ignore_empty_lines", passed, report))
@@ -96,16 +96,17 @@ int main()
   // test_wrong_encoding
   {
     const char* const encoding_arr[] = {"UTF-8", "UCS-2"};
-    Encodings encodings(encoding_arr, encoding_arr + G_N_ELEMENTS(encoding_arr));
+    type_encodings encodings(encoding_arr, encoding_arr + G_N_ELEMENTS(encoding_arr));
 
     // An invalid Unicode sequence.
     const char raw[] = "\0xc0\0x00\n";
     ImportTests::set_parser_contents(parser, raw, sizeof(raw));
 
-    for (Encodings::const_iterator iter = encodings.begin();
+    for (type_encodings::const_iterator iter = encodings.begin();
          iter != encodings.end();
          ++iter)
     {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
       try
       {
         while(parser.on_idle_parse())
@@ -113,16 +114,22 @@ int main()
 
         parser.clear();
       }
-      catch (Glib::ConvertError& exception)
+      catch(const Glib::ConvertError& exception)
       {
         std::cout << exception.what() << std::endl;
       }
+      #else
+      while(parser.on_idle_parse())
+      {}
+
+      parser.clear();
+      #endif
 
       parser.set_encoding((*iter).c_str());
     }
 
 
-    bool passed = (2 == get_encoding_error_count_instance() &&
+    const bool passed = (2 == get_encoding_error_count_instance() &&
                    0 == get_line_scanned_count_instance());
 
     if(!ImportTests::check("test_wrong_encoding", passed, report))
@@ -141,7 +148,7 @@ int main()
     while(parser.on_idle_parse())
     {}
 
-    bool passed = (1 == get_encoding_error_count_instance() &&
+    const bool passed = (1 == get_encoding_error_count_instance() &&
                    0 == get_line_scanned_count_instance());
 
     if(!ImportTests::check("test_incomplete_chars", passed, report))



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