[glom/glom-1-20] Added a test of field choices.



commit 67fbddebb06f4c6099be9d1f40a56710e5d2afad
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Dec 5 14:07:48 2011 +0100

    Added a test of field choices.
    
    	* Makefile_tests.am:
    	* tests/test_selfhosting_new_then_choices.cc:
    	Test Utils::get_choice_values_all().
    
    Conflicts:
    
    	Makefile_tests.am

 ChangeLog                                  |    8 ++
 Makefile_tests.am                          |    6 ++
 tests/.gitignore                           |    3 +
 tests/test_selfhosting_new_then_choices.cc |   97 ++++++++++++++++++++++++++++
 4 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0416eda..73c4e2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-12-05  Murray Cumming  <murrayc murrayc com>
+
+	Added a test of field choices.
+
+	* Makefile_tests.am: 
+	* tests/test_selfhosting_new_then_choices.cc:
+	Test Utils::get_choice_values_all().
+
 2011-12-04  Murray Cumming  <murrayc murray com>
 
 	Document DTD: adapt to the format we actually use.
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 737496e..eee7740 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -36,6 +36,7 @@ check_PROGRAMS =						\
 	tests/test_selfhosting_new_from_example_strangepath \
 	tests/test_selfhosting_new_then_report \
 	tests/test_selfhosting_new_then_image \
+	tests/test_selfhosting_new_then_choices \
 	tests/test_selfhosting_new_then_backup_restore \
 	tests/test_selfhosting_new_then_get_privs \
 	tests/test_selfhosting_new_then_alter_table \
@@ -63,6 +64,7 @@ TESTS =	tests/test_document_load	\
 	tests/test_selfhosting_new_then_report \
 	tests/test_selfhosting_new_then_backup_restore \
 	tests/test_selfhosting_new_then_image \
+	tests/test_selfhosting_new_then_choices \
 	tests/test_selfhosting_new_then_get_privs \
 	tests/test_selfhosting_new_then_alter_table \
 	tests/test_selfhosting_new_then_change_columns \
@@ -188,6 +190,10 @@ tests_test_selfhosting_new_then_image_SOURCES = tests/test_selfhosting_new_then_
 tests_test_selfhosting_new_then_image_LDADD = $(tests_ldadd)
 tests_test_selfhosting_new_then_image_CPPFLAGS = $(tests_cppflags) $(glom_test_image_defines)
 
+tests_test_selfhosting_new_then_choices_SOURCES = tests/test_selfhosting_new_then_choices.cc $(sources_test_selfhosting_utils) $(sources_test_utils)
+tests_test_selfhosting_new_then_choices_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_then_choices_CPPFLAGS = $(tests_cppflags)
+
 tests_test_selfhosting_new_then_backup_restore_SOURCES = tests/test_selfhosting_new_then_backup_restore.cc $(sources_test_selfhosting_utils)
 tests_test_selfhosting_new_then_backup_restore_LDADD = $(tests_ldadd)
 tests_test_selfhosting_new_then_backup_restore_CPPFLAGS = $(tests_cppflags)
diff --git a/tests/.gitignore b/tests/.gitignore
index 870d528..a645524 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -9,6 +9,7 @@
 /test_document_load
 /test_document_load_and_change
 /test_document_change
+/test_document_load_translations
 /test_glade_derived_instantiation
 /test_selfhosting_new_empty
 /test_selfhosting_new_from_example
@@ -17,6 +18,8 @@
 /test_selfhosting_new_then_get_privs
 /test_selfhosting_new_then_image
 /test_selfhosting_new_then_report
+/test_selfhosting_new_then_choices
+/test_selfhosting_new_then_lookup
 /test_selfhosting_sqlinjection
 /test_fake_connection
 /test_selfhosting_new_from_example_strangepath
diff --git a/tests/test_selfhosting_new_then_choices.cc b/tests/test_selfhosting_new_then_choices.cc
new file mode 100644
index 0000000..0e2cc71
--- /dev/null
+++ b/tests/test_selfhosting_new_then_choices.cc
@@ -0,0 +1,97 @@
+/* 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "tests/test_selfhosting_utils.h"
+#include "tests/test_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)
+{
+  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 = "invoice_lines";
+ 
+  const Glom::sharedptr<const Glom::LayoutItem_Field> field_with_choice = 
+    get_field_on_layout(document, table_name, table_name, "product_id");
+  if(!field_with_choice)
+  {
+    std::cerr << "Failure: Could not get the field with choice from the layout." << std::endl;
+    return false;
+  }
+
+  const Glom::Utils::type_list_values_with_second values_with_second = 
+    Glom::Utils::get_choice_values_all(&document, field_with_choice);
+  if(values_with_second.size() != 3)
+  {
+    std::cerr << "Failure: There were an unexpected number of choices." << std::endl;
+    return false;
+  }
+  
+  const std::pair<Gnome::Gda::Value, Glom::Utils::type_list_values> pair_values = *(values_with_second.begin());
+  if(pair_values.second.size() != 1)
+  {
+    std::cerr << "Failure: There were an unexpected number of field values in each choice." << std::endl;
+    return false;
+  }
+
+  test_selfhosting_cleanup();
+ 
+  return true; 
+}
+
+int main()
+{
+  Glom::libglom_init();
+
+  if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
+  {
+    std::cerr << "Failed with PostgreSQL" << std::endl;
+    test_selfhosting_cleanup();
+    return EXIT_FAILURE;
+  }
+  
+  if(!test(Glom::Document::HOSTING_MODE_SQLITE))
+  {
+    std::cerr << "Failed with SQLite" << std::endl;
+    test_selfhosting_cleanup();
+    return EXIT_FAILURE;
+  }
+
+  Glom::libglom_deinit();
+
+  return EXIT_SUCCESS;
+}



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