[glom/origin/import_csv_refactored: 2/2] import tests: Fix the no-exceptions build.
- From: Michael Hasselmann <mikhas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom/origin/import_csv_refactored: 2/2] import tests: Fix the no-exceptions build.
- Date: Wed, 23 Sep 2009 08:52:06 +0000 (UTC)
commit 10626ab70a8dd469ce692e23ef9d02910baeab86
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 ++++++
tests/import/test_parsing.cc | 48 ++++++++++++++++++++++++++++++++---------
tests/import/test_signals.cc | 21 ++++++++++++------
3 files changed, 58 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 334d4e2..9d56c49 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-18 Michael Hasselmann <michaelh openismus com>
Import tests: made them quiet
diff --git a/tests/import/test_parsing.cc b/tests/import/test_parsing.cc
index 27a2a2f..117868c 100644
--- a/tests/import/test_parsing.cc
+++ b/tests/import/test_parsing.cc
@@ -8,11 +8,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;
}
@@ -21,7 +21,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)
{
@@ -31,13 +31,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;
@@ -81,7 +107,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;
@@ -113,7 +139,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;
@@ -145,7 +171,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;
@@ -161,7 +187,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 7126d34..2b61b4a 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]