[glom] Report Tests: Use a specific locale, so these work everywhere.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Report Tests: Use a specific locale, so these work everywhere.
- Date: Thu, 28 Nov 2013 21:42:42 +0000 (UTC)
commit b37ca1d0f858e90d6f2ba7d9be5a422ac51182d0
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Nov 28 13:23:49 2013 +0100
Report Tests: Use a specific locale, so these work everywhere.
* glom/libglom/data_structure/glomconversions.[h|cc]:
Add a get_text_for_gda_value() overload that takes a locale name,
so we do not need to just use the current locale.
* glom/report_builder.cc: Use the new overload instead of ignoring
the provided locale for this.
* tests/test_selfhosting_new_then_report.cc
* tests/test_selfhosting_new_then_report_summary.cc:
Pass the en_US.UTF-8 locale name to the ReportBuilder constructor,
instead of depending on the system's current locale,
so this tests can pass regardless of the current locale.
glom/libglom/data_structure/glomconversions.cc | 5 +++++
glom/libglom/data_structure/glomconversions.h | 1 +
glom/libglom/report_builder.cc | 6 +++---
tests/test_selfhosting_new_then_report.cc | 2 +-
tests/test_selfhosting_new_then_report_summary.cc | 2 +-
5 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/glom/libglom/data_structure/glomconversions.cc b/glom/libglom/data_structure/glomconversions.cc
index 9a407ce..7b4dbed 100644
--- a/glom/libglom/data_structure/glomconversions.cc
+++ b/glom/libglom/data_structure/glomconversions.cc
@@ -339,6 +339,11 @@ double Conversions::get_double_for_gda_value_numeric(const Gnome::Gda::Value& va
return numeric.get_double();
}
+Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value&
value, const Glib::ustring& locale, const NumericFormat& numeric_format, bool iso_format)
+{
+ return get_text_for_gda_value(glom_type, value, std::locale(locale.c_str()), numeric_format, iso_format);
+}
+
Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value&
value, const std::locale& locale, const NumericFormat& numeric_format, bool iso_format)
{
if(value.is_null()) //The type can be null for any of the actual field types.
diff --git a/glom/libglom/data_structure/glomconversions.h b/glom/libglom/data_structure/glomconversions.h
index 87e25b2..88152bb 100644
--- a/glom/libglom/data_structure/glomconversions.h
+++ b/glom/libglom/data_structure/glomconversions.h
@@ -35,6 +35,7 @@ namespace Conversions
///Get text for display to the user.
Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value,
const NumericFormat& numeric_format = NumericFormat());
Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value,
const std::locale& locale, const NumericFormat& numeric_format = NumericFormat(), bool iso_format = false);
+ Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value,
const Glib::ustring& locale, const NumericFormat& numeric_format = NumericFormat(), bool iso_format = false);
//This is easier than using the GdaNumeric API,
//which normally involves text-to-number parsing.
diff --git a/glom/libglom/report_builder.cc b/glom/libglom/report_builder.cc
index 7c78642..f19188e 100644
--- a/glom/libglom/report_builder.cc
+++ b/glom/libglom/report_builder.cc
@@ -261,7 +261,7 @@ bool ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
nodeGroupBy->set_attribute("group_field", field_group_by->get_title_or_name(m_locale));
nodeGroupBy->set_attribute("group_value",
- Conversions::get_text_for_gda_value(field_group_by->get_glom_type(), group_value,
field_group_by->get_formatting_used().m_numeric_format) );
+ Conversions::get_text_for_gda_value(field_group_by->get_glom_type(), group_value, m_locale,
field_group_by->get_formatting_used().m_numeric_format) );
//TODO: Use a SQL parameter instead of using sql().
Gnome::Gda::SqlExpr where_clause =
@@ -510,14 +510,14 @@ bool ReportBuilder::report_build_records_field(const FoundSet& found_set, xmlpp:
nodeField->set_attribute("image_uri", Utils::create_local_image_uri(value));
else
{
- Glib::ustring text_value = Conversions::get_text_for_gda_value(field_type, value,
field->get_formatting_used().m_numeric_format);
+ Glib::ustring text_value = Conversions::get_text_for_gda_value(field_type, value, m_locale,
field->get_formatting_used().m_numeric_format);
//The Postgres summary functions return NULL when summarising NULL records, but 0 is more sensible:
if(text_value.empty() && sharedptr<const LayoutItem_FieldSummary>::cast_dynamic(field) && (field_type ==
Field::TYPE_NUMERIC))
{
//Use get_text_for_gda_value() instead of "0" so we get the correct numerical formatting:
const Gnome::Gda::Value value = Conversions::parse_value(0);
- text_value = Conversions::get_text_for_gda_value(field_type, value,
field->get_formatting_used().m_numeric_format);
+ text_value = Conversions::get_text_for_gda_value(field_type, value, m_locale,
field->get_formatting_used().m_numeric_format);
}
nodeField->set_attribute("value", text_value);
diff --git a/tests/test_selfhosting_new_then_report.cc b/tests/test_selfhosting_new_then_report.cc
index 1b592a7..0d3953b 100644
--- a/tests/test_selfhosting_new_then_report.cc
+++ b/tests/test_selfhosting_new_then_report.cc
@@ -43,7 +43,7 @@ static bool test(Glom::Document::HostingMode hosting_mode)
Glom::FoundSet found_set; //TODO: Test a where clause.
found_set.m_table_name = "albums";
- const Glib::ustring locale = ""; /* original locale */
+ const Glib::ustring locale = "en_US.UTF-8"; //Instead of just "" (current locale) so we get the same
results each time.
Glom::ReportBuilder report_builder(locale);
report_builder.set_document(&document);
const Glib::ustring html =
diff --git a/tests/test_selfhosting_new_then_report_summary.cc
b/tests/test_selfhosting_new_then_report_summary.cc
index 41bd080..490606b 100644
--- a/tests/test_selfhosting_new_then_report_summary.cc
+++ b/tests/test_selfhosting_new_then_report_summary.cc
@@ -48,7 +48,7 @@ static bool test(Glom::Document::HostingMode hosting_mode)
Glom::FoundSet found_set; //TODO: Test a where clause.
found_set.m_table_name = "invoices";
- const Glib::ustring locale = ""; /* original locale */
+ const Glib::ustring locale = "en_US.UTF-8"; //Instead of just "" (current locale) so we know what numeric
representations to expect and check for.
Glom::ReportBuilder report_builder(locale);
report_builder.set_document(&document);
const Glib::ustring html =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]