[glom/glom-1-20] test_document_load: Test field formatting.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-20] test_document_load: Test field formatting.
- Date: Mon, 5 Dec 2011 15:12:47 +0000 (UTC)
commit 49c1a34e674de1811e3010a87ddcd35ab5a148f6
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Nov 30 09:47:38 2011 +0100
test_document_load: Test field formatting.
* tests/test_document_load.cc: Also use a different example, to
widen the range of examples that we test.
ChangeLog | 7 +++
tests/test_document_load.cc | 125 ++++++++++++++++++++++++++++++-------------
2 files changed, 94 insertions(+), 38 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 930382f..9be7c9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-11-30 Murray Cumming <murrayc murrayc com>
+
+ test_document_load: Test field formatting.
+
+ * tests/test_document_load.cc: Also use a different example, to
+ widen the range of examples that we test.
+
1.20.1:
2011-11-29 Murray Cumming <murrayc murrayc com>
diff --git a/tests/test_document_load.cc b/tests/test_document_load.cc
index 87121ff..7be8684 100644
--- a/tests/test_document_load.cc
+++ b/tests/test_document_load.cc
@@ -26,8 +26,8 @@
#include <iostream>
-template<typename T_Container>
-bool contains(const T_Container& container, const Glib::ustring& name)
+template<typename T_Container, typename T_Value>
+bool contains(const T_Container& container, const T_Value& name)
{
typename T_Container::const_iterator iter =
std::find(container.begin(), container.end(), name);
@@ -44,6 +44,37 @@ bool contains_named(const T_Container& container, const Glib::ustring& name)
return iter != container.end();
}
+static Glom::sharedptr<const Glom::LayoutItem_Field> get_field_on_layout(const Glom::Document& document, const Glib::ustring& layout_table_name, const Glib::ustring& table_name, const Glib::ustring& field_name)
+{
+ const Glom::Document::type_list_layout_groups groups =
+ document.get_data_layout_groups("details", layout_table_name);
+
+ for(Glom::Document::type_list_layout_groups::const_iterator iter = groups.begin(); iter != groups.end(); ++iter)
+ {
+ const Glom::sharedptr<const Glom::LayoutGroup> group = *iter;
+ if(!group)
+ continue;
+
+ const Glom::LayoutGroup::type_list_const_items items = group->get_items_recursive();
+ for(Glom::LayoutGroup::type_list_const_items::const_iterator iter = items.begin(); iter != items.end(); ++iter)
+ {
+ const Glom::sharedptr<const Glom::LayoutItem> layout_item = *iter;
+ const Glom::sharedptr<const Glom::LayoutItem_Field> layout_item_field =
+ Glom::sharedptr<const Glom::LayoutItem_Field>::cast_dynamic(layout_item);
+ if(!layout_item_field)
+ continue;
+
+ if( (layout_item_field->get_table_used(layout_table_name) == table_name) &&
+ (layout_item_field->get_name() == field_name) )
+ {
+ return layout_item_field;
+ }
+ }
+ }
+
+ return Glom::sharedptr<const Glom::LayoutItem_Field>();
+}
+
int main()
{
Glom::libglom_init();
@@ -55,7 +86,7 @@ int main()
{
const std::string path =
Glib::build_filename(GLOM_DOCDIR_EXAMPLES_NOTINSTALLED,
- "example_music_collection.glom");
+ "example_film_manager.glom");
uri = Glib::filename_to_uri(path);
}
catch(const Glib::ConvertError& ex)
@@ -82,63 +113,81 @@ int main()
//Test some known details:
g_assert(document.get_is_example_file());
- g_assert(document.get_database_title() == "Music Collection");
+ g_assert(document.get_database_title() == "Openismus Film Manager");
const std::vector<Glib::ustring> table_names = document.get_table_names();
- g_assert(contains(table_names, "albums"));
- g_assert(contains(table_names, "artists"));
- g_assert(contains(table_names, "publishers"));
- g_assert(contains(table_names, "songs"));
- g_assert(!contains(table_names, "nosuchtable"));
+ g_assert(contains(table_names, "accommodation"));
+ g_assert(contains(table_names, "cars"));
+ g_assert(contains(table_names, "characters"));
+ g_assert(contains(table_names, "companies"));
+ g_assert(contains(table_names, "contacts"));
+ g_assert(contains(table_names, "locations"));
+ g_assert(contains(table_names, "scenes"));
+ g_assert(!contains(table_names, "Scenes")); //The title, not the name.
//Test known details of one table:
- const Glom::Document::type_vec_fields fields = document.get_table_fields("albums");
- g_assert(contains_named(fields, "album_id"));
- g_assert(contains_named(fields, "name"));
- g_assert(contains_named(fields, "artist_id"));
- g_assert(contains_named(fields, "year"));
+ const Glom::Document::type_vec_fields fields = document.get_table_fields("scenes");
+ g_assert(contains_named(fields, "scene_id"));
+ g_assert(contains_named(fields, "comments"));
+ g_assert(contains_named(fields, "description"));
+ g_assert(contains_named(fields, "date"));
g_assert(!contains_named(fields, "nosuchfield"));
- const Glom::Document::type_vec_relationships relationships = document.get_relationships("albums");
- g_assert(contains_named(relationships, "artist"));
- g_assert(contains_named(relationships, "publisher"));
- g_assert(contains_named(relationships, "songs"));
+ const Glom::Document::type_vec_relationships relationships = document.get_relationships("scenes");
+ g_assert(contains_named(relationships, "location"));
+ g_assert(contains_named(relationships, "scene_crew"));
+ g_assert(contains_named(relationships, "scene_cast"));
//Check some fields:
- Glom::sharedptr<const Glom::Field> field = document.get_field("albums", "album_id");
+ Glom::sharedptr<const Glom::Field> field = document.get_field("contacts", "contact_id");
g_assert(field);
g_assert(field->get_glom_type() == Glom::Field::TYPE_NUMERIC);
g_assert(field->get_auto_increment());
- field = document.get_field("albums", "year");
+ field = document.get_field("locations", "rent");
g_assert(field);
g_assert(field->get_glom_type() == Glom::Field::TYPE_NUMERIC);
g_assert(!field->get_auto_increment());
g_assert(!field->get_unique_key());
//Check a relationship:
- const Glom::sharedptr<const Glom::Relationship> relationship = document.get_relationship("albums", "artist");
+ const Glom::sharedptr<const Glom::Relationship> relationship = document.get_relationship("characters", "contacts_actor");
g_assert(relationship);
- g_assert(relationship->get_from_field() == "artist_id");
- g_assert(relationship->get_to_table() == "artists");
- g_assert(relationship->get_to_field() == "artist_id");
+ g_assert(relationship->get_from_field() == "contact_id");
+ g_assert(relationship->get_to_table() == "contacts");
+ g_assert(relationship->get_to_field() == "contact_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;
- 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(layout_table_name, "artists", "name"))
- {
- found_on_layout = true;
- break;
- }
- }
+ Glom::sharedptr<const Glom::LayoutItem_Field> field_on_layout =
+ get_field_on_layout(document, "scenes", "locations", "address_town");
+ g_assert(field_on_layout);
+ g_assert(field_on_layout->get_table_used("scenes") == "locations");
+ g_assert(field_on_layout->get_name() == "address_town");
+
+
+ //Check Field Formatting:
+ field = document.get_field("contacts", "name_title");
+ g_assert(field);
+ g_assert(field->get_glom_type() == Glom::Field::TYPE_TEXT);
+ const Glom::FieldFormatting& formatting = field->m_default_formatting;
+ g_assert(formatting.get_horizontal_alignment() == Glom::FieldFormatting::HORIZONTAL_ALIGNMENT_AUTO);
+
+ g_assert(formatting.get_has_choices());
+ g_assert(formatting.get_has_custom_choices());
+ g_assert(!formatting.get_has_related_choices());
+ Glom::FieldFormatting::type_list_values choices = formatting.get_choices_custom();
+ g_assert(!choices.empty());
+ g_assert(contains(choices, Gnome::Gda::Value("Mr")));
+ g_assert(contains(choices, Gnome::Gda::Value("Mrs")));
- g_assert(found_on_layout);
+ //Check that the default formatting is used on the layout:
+ field_on_layout =
+ get_field_on_layout(document, "contacts", "contacts", "name_title");
+ g_assert(field_on_layout);
+ g_assert(field_on_layout->get_table_used("contacts") == "contacts");
+ g_assert(field_on_layout->get_name() == "name_title");
+ g_assert(field_on_layout->get_formatting_use_default());
+ g_assert(field_on_layout->get_formatting_used() == formatting);
Glom::libglom_deinit();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]