[glom] Self hosting test: Check that other tables exist.



commit 6d1c4843af23fb176ed5202cea2e7458fe08a1c6
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 18 22:07:17 2011 +0200

    Self hosting test: Check that other tables exist.
    
    	* glom/libglom/document/document.[h|cc]: Added get_field_primary_key(),
    	for use by:
    	* tests/test_selfhosting_utils.[h|cc]: Added test_table_exists().
    	* tests/test_selfhosting_new_from_example.cc: Add quick checks that
    	some other tables exist.

 ChangeLog                                  |   10 ++++++++++
 glom/libglom/document/document.cc          |   13 +++++++++++++
 glom/libglom/document/document.h           |    2 ++
 tests/test_selfhosting_new_from_example.cc |   12 ++++++++++++
 tests/test_selfhosting_utils.cc            |   23 +++++++++++++++++++++++
 tests/test_selfhosting_utils.h             |    1 +
 6 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ad59e77..cfc5562 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2011-10-18  Murray Cumming  <murrayc murrayc com>
 
+	Self hosting test: Check that other tables exist.
+
+	* glom/libglom/document/document.[h|cc]: Added get_field_primary_key(),
+	for use by:
+	* tests/test_selfhosting_utils.[h|cc]: Added test_table_exists().
+	* tests/test_selfhosting_new_from_example.cc: Add quick checks that 
+	some other tables exist.
+
+2011-10-18  Murray Cumming  <murrayc murrayc com>
+
 	Test some query functions.
 
 	* tests/test_selfhosting_utils.[h|cc]: Added test_model_expected_size().
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 706c876..d9c873d 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -904,6 +904,19 @@ sharedptr<Field> Document::get_field(const Glib::ustring& table_name, const Glib
   return sharedptr<Field>();
 }
 
+sharedptr<Field> Document::get_field_primary_key(const Glib::ustring& table_name) const
+{
+  type_vec_fields vecFields = get_table_fields(table_name);
+  for(type_vec_fields::const_iterator iter = vecFields.begin(); iter != vecFields.end(); ++iter)
+  {
+    sharedptr<Field> field = *iter;
+    if(field && field->get_primary_key())
+      return field;
+  }
+
+  return sharedptr<Field>();
+}
+
 void Document::change_field_name(const Glib::ustring& table_name, const Glib::ustring& strFieldNameOld, const Glib::ustring& strFieldNameNew)
 {
   type_tables::iterator iterFindTable = m_tables.find(table_name);
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 5dd5506..6d6a473 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -193,6 +193,8 @@ public:
 
   sharedptr<Field> get_field(const Glib::ustring& table_name, const Glib::ustring& strFieldName) const;
 
+  sharedptr<Field> get_field_primary_key(const Glib::ustring& table_name) const;
+
   /** Use this after removing a field from a table,
    * so that it is not used anymore in relationships, layouts, reports, etc.
    */
diff --git a/tests/test_selfhosting_new_from_example.cc b/tests/test_selfhosting_new_from_example.cc
index 6c92599..41fee96 100644
--- a/tests/test_selfhosting_new_from_example.cc
+++ b/tests/test_selfhosting_new_from_example.cc
@@ -93,6 +93,18 @@ int main()
     return EXIT_FAILURE;
   }
 
+  if(test_table_exists("songs", document))
+  {
+    test_selfhosting_cleanup();
+    return EXIT_FAILURE;
+  }
+
+  if(test_table_exists("publishers", document))
+  {
+    test_selfhosting_cleanup();
+    return EXIT_FAILURE;
+  }
+
   test_selfhosting_cleanup();
 
   Glom::libglom_deinit();
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index d6e76dd..3cf9265 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -26,6 +26,7 @@
 #include <libglom/init.h>
 #include <libglom/privs.h>
 #include <libglom/db_utils.h>
+#include <libglom/utils.h>
 #include <giomm/file.h>
 #include <iostream>
 
@@ -224,4 +225,26 @@ bool test_model_expected_size(const Glib::RefPtr<Gnome::Gda::DataModel>& data_mo
   return true;
 }
 
+bool test_table_exists(const Glib::ustring& table_name, const Glom::Document& document)
+{
+  //Try to get more rows than intended:
+  Glom::Utils::type_vecLayoutFields fieldsToGet;
+  Glom::sharedptr<const Glom::Field> field = document.get_field_primary_key(table_name); //To to get some field.
+  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);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = 
+    Glom::DbUtils::query_execute_select(builder);
+  if(!data_model || !(data_model->get_n_columns()))
+  {
+    std::cerr << "Failure: table does not exist: " << table_name << std::endl;
+    return false;
+  }
+
+  return true;
+}
 
diff --git a/tests/test_selfhosting_utils.h b/tests/test_selfhosting_utils.h
index 638e445..1bd5945 100644
--- a/tests/test_selfhosting_utils.h
+++ b/tests/test_selfhosting_utils.h
@@ -28,6 +28,7 @@
 bool test_create_and_selfhost(const std::string& example_filename, Glom::Document& document);
 
 bool test_model_expected_size(const Glib::RefPtr<Gnome::Gda::DataModel>& data_model, guint columns_count, guint rows_count);
+bool test_table_exists(const Glib::ustring& table_name, const Glom::Document& document);
 
 void test_selfhosting_cleanup();
 



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