[glom] Add a test for Image fields.



commit a16f1ffab00894b3bb1b9dac59eaecec6498eb95
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Oct 28 14:47:15 2011 +0200

    Add a test for Image fields.
    
    	* Makefile_tests.am:
    	* tests/test_selfhosting_new_then_image.cc: Add a test to read an image field
    	value, though this currently fails.
    	I will later add a write-then-read test.

 ChangeLog                                |    9 +++++++
 Makefile_tests.am                        |    6 +++++
 tests/test_selfhosting_new_then_image.cc |   36 ++++++++++++++---------------
 3 files changed, 32 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9dee41b..de8dd18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2011-10-28  Murray Cumming  <murrayc murrayc com>
 
+	Add a test for Image fields.
+
+	* Makefile_tests.am:
+	* tests/test_selfhosting_new_then_image.cc: Add a test to read an image field
+	value, though this currently fails.
+	I will later add a write-then-read test.
+
+2011-10-28  Murray Cumming  <murrayc murrayc com>
+
 	Fix make check by correcting the DTD.
 
 	* glom/glom_document.dtd: Corrections relating to the print layout definitions.
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 3e4d428..5ca7324 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -28,6 +28,7 @@ check_PROGRAMS =						\
 	tests/test_selfhosting_new_empty \
 	tests/test_selfhosting_new_from_example \
 	tests/test_selfhosting_new_then_report \
+	tests/test_selfhosting_new_then_image \
 	tests/test_selfhosting_sqlinjection \
 	tests/import/test_parsing \
 	tests/import/test_signals
@@ -44,6 +45,7 @@ TESTS =	tests/test_document_load	\
 	tests/test_selfhosting_new_empty \
 	tests/test_selfhosting_new_from_example \
 	tests/test_selfhosting_new_then_report \
+	tests/test_selfhosting_new_then_image \
 	tests/test_selfhosting_sqlinjection \
 	tests/import/test_parsing \
 	tests/import/test_signals
@@ -139,6 +141,10 @@ tests_test_selfhosting_new_then_report_SOURCES = tests/test_selfhosting_new_then
 tests_test_selfhosting_new_then_report_LDADD = $(tests_ldadd)
 tests_test_selfhosting_new_then_report_CPPFLAGS = $(tests_cppflags)
 
+tests_test_selfhosting_new_then_image_SOURCES = tests/test_selfhosting_new_then_image.cc $(sources_test_selfhosting_utils)
+tests_test_selfhosting_new_then_image_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_then_image_CPPFLAGS = $(tests_cppflags)
+
 tests_test_selfhosting_sqlinjection_SOURCES = tests/test_selfhosting_sqlinjection.cc $(sources_test_selfhosting_utils)
 tests_test_selfhosting_sqlinjection_LDADD = $(tests_ldadd)
 tests_test_selfhosting_sqlinjection_CPPFLAGS = $(tests_cppflags)
diff --git a/tests/test_selfhosting_new_then_image.cc b/tests/test_selfhosting_new_then_image.cc
index c2c81b0..d02a701 100644
--- a/tests/test_selfhosting_new_then_image.cc
+++ b/tests/test_selfhosting_new_then_image.cc
@@ -30,34 +30,36 @@ static bool test(Glom::Document::HostingMode hosting_mode)
 {
   Glom::Document document;
   const bool recreated = 
-    test_create_and_selfhost("example_music_collection.glom", document, hosting_mode);
+    test_create_and_selfhost("example_smallbusiness.glom", document, hosting_mode);
   if(!recreated)
   {
     std::cerr << "Recreation failed." << std::endl;
     return false;
   }
   
-  //Check that some data is as expected:
-  const Gnome::Gda::Value value("Born To Run");
+  //Where clause:
+  const Glom::sharedptr<const Glom::Field> key_field = document.get_field("contacts", "contact_id");
+  if(!key_field)
+  {
+    std::cerr << "Failure: Could not get key field." << std::endl;
+    return false;
+  }
+  
   const Gnome::Gda::SqlExpr where_clause = 
-    Glom::Utils::get_find_where_clause_quick(&document, "albums", value);
+    Glom::Utils::build_simple_where_expression("contacts", key_field, Gnome::Gda::Value(1));
   
   Glom::Utils::type_vecLayoutFields fieldsToGet;
-  Glom::sharedptr<const Glom::Field> field = document.get_field("albums", "album_id");
+  Glom::sharedptr<const Glom::Field> field = document.get_field("contacts", "picture");
   Glom::sharedptr<Glom::LayoutItem_Field> layoutitem = Glom::sharedptr<Glom::LayoutItem_Field>::create();
   layoutitem->set_full_field_details(field);
   fieldsToGet.push_back(layoutitem);
-  field = document.get_field("albums", "name");
-  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("albums",
+    Glom::Utils::build_sql_select_with_where_clause("contacts",
       fieldsToGet, where_clause);
   Glib::RefPtr<Gnome::Gda::DataModel> data_model = 
     Glom::DbUtils::query_execute_select(builder);
-  if(!test_model_expected_size(data_model, 2, 1))
+  if(!test_model_expected_size(data_model, 1, 1))
   {
     std::cerr << "Failure: Unexpected data model size for main query." << std::endl;
     return false;
@@ -69,15 +71,11 @@ static bool test(Glom::Document::HostingMode hosting_mode)
     std::cerr << "Failure: The COUNT query returned an unexpected value: " << count << std::endl;
     return false;
   }
-
-  if(!test_table_exists("songs", document))
-  {
-    return false;
-  }
-
-  if(!test_table_exists("publishers", document))
+  
+  const Gnome::Gda::Value value_read = data_model->get_value_at(0, 0);
+  if(value_read.get_value_type() != GDA_TYPE_NUMERIC)
   {
-    return false;
+    std::cerr << "Failure: The value read was not of the expected type: " << g_type_name( value_read.get_value_type() ) << std::endl;
   }
 
   test_selfhosting_cleanup();



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