[glom/glom-1-20] test_document_load: Check that a field is on a layout.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-20] test_document_load: Check that a field is on a layout.
- Date: Tue, 29 Nov 2011 12:15:17 +0000 (UTC)
commit 0a173a178c881f7c9ca66d77a355526862252d69
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Nov 29 11:23:03 2011 +0100
test_document_load: Check that a field is on a layout.
* glom/libglom/data_structure/layout/layoutgroup.[h|cc]:
Added has_field() that can find a related field.
* tests/test_document_load.cc: Check that an expected field is found on
the layout.
ChangeLog | 9 ++++++
glom/libglom/data_structure/layout/layoutgroup.cc | 29 +++++++++++++++++++++
glom/libglom/data_structure/layout/layoutgroup.h | 16 +++++++++--
tests/test_document_load.cc | 27 +++++++++++++++++++
4 files changed, 78 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a79daf0..2a76486 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2011-11-29 Murray Cumming <murrayc murrayc com>
+ test_document_load: Check that a field is on a layout.
+
+ * glom/libglom/data_structure/layout/layoutgroup.[h|cc]:
+ Added has_field() that can find a related field.
+ * tests/test_document_load.cc: Check that an expected field is found on
+ the layout.
+
+2011-11-29 Murray Cumming <murrayc murrayc com>
+
Add a test for changing of a field name.
* tests/Makefile.am:
diff --git a/glom/libglom/data_structure/layout/layoutgroup.cc b/glom/libglom/data_structure/layout/layoutgroup.cc
index b5318b8..5d6229a 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.cc
+++ b/glom/libglom/data_structure/layout/layoutgroup.cc
@@ -110,6 +110,35 @@ bool LayoutGroup::has_field(const Glib::ustring& field_name) const
return false;
}
+bool LayoutGroup::has_field(const Glib::ustring& parent_table_name, const Glib::ustring& table_name, const Glib::ustring& field_name) const
+{
+ for(type_list_items::const_iterator iter = m_list_items.begin(); iter != m_list_items.end(); ++iter)
+ {
+ sharedptr<LayoutItem> item = *iter;
+ sharedptr<LayoutItem_Field> field_item = sharedptr<LayoutItem_Field>::cast_dynamic(item);
+ if(field_item)
+ {
+ if( (field_item->get_name() == field_name) &&
+ (field_item->get_table_used(parent_table_name) == table_name))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ //Recurse into the child groups:
+ sharedptr<LayoutGroup> group_item = sharedptr<LayoutGroup>::cast_dynamic(item);
+ if(group_item)
+ {
+ if(group_item->has_field(parent_table_name, table_name, field_name))
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
bool LayoutGroup::has_any_fields() const
{
for(type_list_items::const_iterator iter = m_list_items.begin(); iter != m_list_items.end(); ++iter)
diff --git a/glom/libglom/data_structure/layout/layoutgroup.h b/glom/libglom/data_structure/layout/layoutgroup.h
index 75b9e7e..eb972ce 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.h
+++ b/glom/libglom/data_structure/layout/layoutgroup.h
@@ -40,12 +40,22 @@ public:
virtual LayoutItem* clone() const;
- /** Discover whether the layout group contains the specified field.
- * @param field_name The name of the field to seach for.
+ //TODO: Unify the has_field() and remove_field() method overloads,
+ //probably like so: has_field(parent_table_name, table_name, field_name);
+
+ /** Discover whether the layout group contains the specified related field,
+ * @param field_name The name of the field to search for.
* @result True if the field is in the layout group (or its child groups).
*/
bool has_field(const Glib::ustring& field_name) const;
+ /** Discover whether the layout group contains the specified field (from the current table).
+ * @param field_name The name of the field to search for.
+ * @result True if the field is in the layout group (or its child groups).
+ */
+ bool has_field(const Glib::ustring& parent_table_name, const Glib::ustring& table_name, const Glib::ustring& field_name) const;
+
+
/** Discover whether the layout group contains any fields.
* @result True if the field is in the layout group (or its child groups).
*/
@@ -65,7 +75,7 @@ public:
/** Remove a layout item from the group
* @param item The item to remove.
*/
- void remove_item (const sharedptr<LayoutItem>& item);
+ void remove_item(const sharedptr<LayoutItem>& item);
/** Remove any instance of the field (from the current table) from the layout.
*/
diff --git a/tests/test_document_load.cc b/tests/test_document_load.cc
index 8a1bae1..e0f8b7f 100644
--- a/tests/test_document_load.cc
+++ b/tests/test_document_load.cc
@@ -122,6 +122,33 @@ int main()
g_assert(relationship->get_to_table() == "artists");
g_assert(relationship->get_to_field() == "artist_id");
+
+ //Check that expected fields can be found on a layout.
+ const Glib::ustring layout_table_name = "albums";
+ const Glom::Document::type_list_layout_groups groups =
+ document.get_data_layout_groups("details", layout_table_name);
+ bool found_on_layout = false;
+ bool found_related_on_layout = false;
+ for(Glom::Document::type_list_layout_groups::const_iterator iter = groups.begin(); iter != groups.end(); ++iter)
+ {
+ const Glom::sharedptr<Glom::LayoutGroup> group = *iter;
+ if(group->has_field("album_id"))
+ {
+ found_on_layout = true;
+ break;
+ }
+
+ if(group->has_field(layout_table_name, "artists", "name"))
+ {
+ found_related_on_layout = true;
+ break;
+ }
+ }
+
+ g_assert(found_on_layout);
+ g_assert(found_related_on_layout);
+
+
Glom::libglom_deinit();
return EXIT_SUCCESS;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]