[glom] tests: Add: test_selfhosting_new_from_example_float.cc
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] tests: Add: test_selfhosting_new_from_example_float.cc
- Date: Sun, 6 Jan 2013 16:44:18 +0000 (UTC)
commit 3b5a6393ad4ba2f8365a654df3d3628d54ce1514
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Jan 6 14:40:10 2013 +0100
tests: Add: test_selfhosting_new_from_example_float.cc
* Makefile_tests.am:
* tests/test_selfhosting_utils.[h|cc]:
Add test_check_numeric_value_type().
* tests/test_selfhosting_new_from_example_float.cc: Add
this simple test that gets a float value, to check that
we do not lose precision. It seems to fail with MySQL.
It also seems to cause a crash or hang with PostgreSQL
during cleanup.
ChangeLog | 13 +++
Makefile_tests.am | 6 +
glom/libglom/db_utils.cc | 5 +-
tests/test_selfhosting_new_from_example_float.cc | 119 ++++++++++++++++++++++
tests/test_selfhosting_new_then_lookup.cc | 9 +-
tests/test_selfhosting_utils.cc | 13 +++
6 files changed, 159 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1490430..b94ffa2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2013-01-06 Murray Cumming <murrayc murrayc com>
+
+ tests: Add: test_selfhosting_new_from_example_float.cc
+
+ * Makefile_tests.am:
+ * tests/test_selfhosting_utils.[h|cc]:
+ Add test_check_numeric_value_type().
+ * tests/test_selfhosting_new_from_example_float.cc: Add
+ this simple test that gets a float value, to check that
+ we do not lose precision. It seems to fail with MySQL.
+ It also seems to cause a crash or hang with PostgreSQL
+ during cleanup.
+
2013-01-03 Murray Cumming <murrayc murrayc com>
tests: Avoid some copy/pasting.
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 3ee1a4b..e47b238 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -37,6 +37,7 @@ check_PROGRAMS = \
tests/test_selfhosting_new_empty_change_sysprefs \
tests/test_selfhosting_new_empty_then_users \
tests/test_selfhosting_new_from_example \
+ tests/test_selfhosting_new_from_example_float \
tests/test_selfhosting_new_from_example_operator \
tests/test_selfhosting_new_from_example_strangepath \
tests/test_selfhosting_new_then_report \
@@ -76,6 +77,7 @@ TESTS = tests/test_document_load \
tests/test_selfhosting_new_empty_change_sysprefs \
tests/test_selfhosting_new_empty_then_users \
tests/test_selfhosting_new_from_example \
+ tests/test_selfhosting_new_from_example_float \
tests/test_selfhosting_new_from_example_operator \
tests/test_selfhosting_new_from_example_in_locales.sh \
tests/test_selfhosting_new_from_example_strangepath \
@@ -258,6 +260,10 @@ tests_test_selfhosting_new_from_example_SOURCES = tests/test_selfhosting_new_fro
tests_test_selfhosting_new_from_example_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_from_example_CPPFLAGS = $(tests_cppflags)
+tests_test_selfhosting_new_from_example_float_SOURCES = tests/test_selfhosting_new_from_example_float.cc $(sources_test_selfhosting_utils)
+tests_test_selfhosting_new_from_example_float_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_from_example_float_CPPFLAGS = $(tests_cppflags)
+
tests_test_selfhosting_new_from_example_operator_SOURCES = tests/test_selfhosting_new_from_example_operator.cc $(sources_test_selfhosting_utils)
tests_test_selfhosting_new_from_example_operator_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_from_example_operator_CPPFLAGS = $(tests_cppflags)
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index dcdc2b8..559ab11 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1267,7 +1267,10 @@ bool create_table(const sharedptr<const TableInfo>& table_info, const Document::
{
//TODO: Escape the table name?
//TODO: Use GDA_SERVER_OPERATION_CREATE_TABLE instead?
- table_creation_succeeded = query_execute_string( "CREATE TABLE " + escape_sql_id(table_info->get_name()) + " (" + sql_fields + ");" );
+ const Glib::ustring query = "CREATE TABLE " + escape_sql_id(table_info->get_name()) + " (" + sql_fields + ");";
+ //std::cout << G_STRFUNC << ": debug: CREATE TABLE query:" << std::endl;
+ //std::cout << " " << query << std::endl;
+ table_creation_succeeded = query_execute_string(query);
if(!table_creation_succeeded)
std::cerr << G_STRFUNC << ": CREATE TABLE failed." << std::endl;
}
diff --git a/tests/test_selfhosting_new_from_example_float.cc b/tests/test_selfhosting_new_from_example_float.cc
new file mode 100644
index 0000000..30079f0
--- /dev/null
+++ b/tests/test_selfhosting_new_from_example_float.cc
@@ -0,0 +1,119 @@
+/* Glom
+ *
+ * Copyright (C) 2010 Openismus GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+71 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include "tests/test_selfhosting_utils.h"
+#include <libglom/init.h>
+#include <libglom/utils.h>
+#include <libglom/db_utils.h>
+#include <libglom/connectionpool.h>
+#include <libglom/data_structure/glomconversions.h>
+#include <glibmm/fileutils.h>
+#include <glibmm/miscutils.h>
+#include <glib.h> //For g_assert()
+#include <iostream>
+#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
+
+static bool test(Glom::Document::HostingMode hosting_mode)
+{
+ std::cout << "debug: hosting_mode=" << hosting_mode << std::endl;
+
+ Glom::Document document;
+ const bool recreated =
+ test_create_and_selfhost_from_example("example_smallbusiness.glom", document, hosting_mode);
+ if(!recreated)
+ {
+ std::cerr << "Recreation failed." << std::endl;
+ return false;
+ }
+
+ const Glib::ustring table_name = "products";
+ Glom::sharedptr<const Glom::Field> primary_key_field = document.get_field_primary_key(table_name);
+ if(!primary_key_field)
+ {
+ std::cerr << "Failure: primary_key_field is empty." << std::endl;
+ return false;
+ }
+
+ //Check that some data is as expected:
+ const Gnome::Gda::Value pk_value(2.0f);
+ const Gnome::Gda::SqlExpr where_clause =
+ Glom::Utils::build_simple_where_expression(table_name, primary_key_field, pk_value);
+
+ Glom::Utils::type_vecLayoutFields fieldsToGet;
+ Glom::sharedptr<const Glom::Field> field = document.get_field(table_name, "price");
+ Glom::sharedptr<Glom::LayoutItem_Field> layoutitem = Glom::sharedptr<Glom::LayoutItem_Field>::create();
+ layoutitem->set_full_field_details(field);
+ fieldsToGet.push_back(layoutitem);
+
+ const Glib::RefPtr<const Gnome::Gda::SqlBuilder> builder =
+ Glom::Utils::build_sql_select_with_where_clause(table_name,
+ fieldsToGet, where_clause);
+ const Glib::RefPtr<const Gnome::Gda::DataModel> data_model =
+ Glom::DbUtils::query_execute_select(builder);
+ if(!test_model_expected_size(data_model, 1, 1))
+ {
+ std::cerr << G_STRFUNC << "Failure: Unexpected data model size with query: " <<
+ Glom::Utils::sqlbuilder_get_full_query(builder) << std::endl;
+ return false;
+ }
+
+ const int count = Glom::DbUtils::count_rows_returned_by(builder);
+ if(count != 1 )
+ {
+ std::cerr << G_STRFUNC << "Failure: The COUNT query returned an unexpected value: " << count << std::endl;
+ return false;
+ }
+
+
+ //Get the value from the result:
+ const Gnome::Gda::Value value = data_model->get_value_at(0, 0);
+
+ if(!test_check_numeric_value_type(hosting_mode, value))
+ {
+ std::cerr << "Failure: The value has an unexpected type: " <<
+ g_type_name(value.get_value_type()) << std::endl;
+ return false;
+ }
+
+ if(Glom::Conversions::get_double_for_gda_value_numeric(value) != 3.5f)
+ {
+ std::cerr << "Failure: The value has an unexpected value: " << value.to_string() << " instead of 3.5" << std::endl;
+ std::cerr << " value as string: " << value.to_string() << std::endl;
+ std::cerr << " value GType: " << g_type_name(value.get_value_type()) << std::endl;
+ return false;
+ }
+
+ test_selfhosting_cleanup();
+
+ std::cout << "debug: end hosting_mode=" << hosting_mode << std::endl;
+
+ return true;
+}
+
+int main()
+{
+ Glom::libglom_init();
+
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
+
+ Glom::libglom_deinit();
+
+ return result;
+}
diff --git a/tests/test_selfhosting_new_then_lookup.cc b/tests/test_selfhosting_new_then_lookup.cc
index 97f468d..73e83fa 100644
--- a/tests/test_selfhosting_new_then_lookup.cc
+++ b/tests/test_selfhosting_new_then_lookup.cc
@@ -176,15 +176,12 @@ static bool test(Glom::Document::HostingMode hosting_mode)
}
//Lookup the value from the related record.
- //TODO:
const Glom::sharedptr<Glom::Field> field_source =
document.get_field(relationship->get_to_table(), field->get_lookup_field());
const Gnome::Gda::Value value = Glom::DbUtils::get_lookup_value(&document,
table_name, relationship, field_source, Gnome::Gda::Value(2));
- const GType expected_type =
- (hosting_mode != Glom::Document::HOSTING_MODE_SQLITE ? GDA_TYPE_NUMERIC : G_TYPE_DOUBLE);
- if(value.get_value_type() != expected_type)
+ if(!test_check_numeric_value_type(hosting_mode, value))
{
std::cerr << "Failure: The value has an unexpected type: " <<
g_type_name(value.get_value_type()) << std::endl;
@@ -193,7 +190,9 @@ static bool test(Glom::Document::HostingMode hosting_mode)
if(Glom::Conversions::get_double_for_gda_value_numeric(value) != 3.5f)
{
- std::cerr << "Failure: The value has an unexpected value: " << value.to_string() << std::endl;
+ std::cerr << "Failure: The value has an unexpected value: " << value.to_string() << " instead of 3.5" << std::endl;
+ std::cerr << " value as string: " << value.to_string() << std::endl;
+ std::cerr << " value GType: " << g_type_name(value.get_value_type()) << std::endl;
return false;
}
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index db0e9da..b777faf 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -543,3 +543,16 @@ int test_all_hosting_modes(const SlotTest& slot)
return EXIT_SUCCESS;
}
+bool test_check_numeric_value_type(Glom::Document::HostingMode hosting_mode, const Gnome::Gda::Value& value)
+{
+ const GType gtype = value.get_value_type();
+ //std::cout << "debug: gtype=" << g_type_name(gtype) << std::endl;
+ if(hosting_mode == Glom::Document::HOSTING_MODE_SQLITE)
+ {
+ if(gtype == G_TYPE_DOUBLE)
+ return true;
+ }
+
+ //The normal type for PostgreSQL:
+ return (gtype == GDA_TYPE_NUMERIC);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]