[glom] Add missing file.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Add missing file.
- Date: Thu, 5 Nov 2015 22:23:37 +0000 (UTC)
commit 7a3faf5e8f23c4a1026c1e8a62c0268a1f18d37d
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Nov 5 23:21:56 2015 +0100
Add missing file.
tests/test_layout_item_field.cc | 171 +++++++++++++++++++++++++++++++++++++++
1 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_layout_item_field.cc b/tests/test_layout_item_field.cc
new file mode 100644
index 0000000..ccb48ac
--- /dev/null
+++ b/tests/test_layout_item_field.cc
@@ -0,0 +1,171 @@
+/* Glom
+ *
+ * Copyright (C) 2015 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
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include <glom/libglom/init.h>
+#include <glom/libglom/data_structure/layout/layoutitem_field.h>
+#include <iostream>
+#include <cstdlib>
+
+static
+bool test_compare_empty_instances()
+{
+ auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
+ auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
+ if(!layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with empty instances." <<
std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+static
+bool test_compare_same_named_instances()
+{
+ auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
+ auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
+ layout_item1->set_name("one");
+ layout_item2->set_name("two");
+ if(layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with named field instances."
<< std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+static
+bool test_compare_same_named_instances_unrelated_differences()
+{
+ auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
+ auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
+ layout_item1->set_name("one");
+ layout_item2->set_name("one");
+ layout_item2->set_hidden(); //is_same_field() should ignore this.
+ if(!layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with named field instances
with unrelated differences." << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+
+static
+bool test_compare_same_named_instances_with_relationship()
+{
+ auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
+ auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
+ layout_item1->set_name("one");
+ layout_item2->set_name("one");
+
+ auto relationship1 = std::make_shared<Glom::Relationship>();
+ relationship1->set_name("relationship1");
+ layout_item1->set_relationship(relationship1);
+
+ auto relationship2 = std::make_shared<Glom::Relationship>();
+ relationship2->set_name("relationship2");
+ layout_item2->set_relationship(relationship2);
+
+ if(layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with
different relationships." << std::endl;
+ return false;
+ }
+
+ layout_item2->set_relationship(relationship1);
+ if(!layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with
same relationships." << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+static
+bool test_compare_same_named_instances_with_related_relationship()
+{
+ auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
+ auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
+ layout_item1->set_name("one");
+ layout_item2->set_name("one");
+
+ auto relationship1 = std::make_shared<Glom::Relationship>();
+ relationship1->set_name("relationship1");
+ layout_item1->set_relationship(relationship1);
+ layout_item2->set_relationship(relationship1);
+
+ auto relationship_related1 = std::make_shared<Glom::Relationship>();
+ relationship_related1->set_name("relationship_related1");
+ layout_item1->set_related_relationship(relationship_related1);
+
+ if(layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with
different (one unset) related relationships." << std::endl;
+ return false;
+ }
+
+ auto relationship_related2 = std::make_shared<Glom::Relationship>();
+ relationship_related2->set_name("relationship_related2");
+ layout_item2->set_related_relationship(relationship_related2);
+
+ if(layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with
different related relationships." << std::endl;
+ return false;
+ }
+
+ layout_item2->set_related_relationship(relationship_related1);
+ if(!layout_item1->is_same_field(layout_item2))
+ {
+ std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with
same related relationships." << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+int main()
+{
+ Glom::libglom_init();
+
+ if(!test_compare_empty_instances())
+ return EXIT_FAILURE;
+
+ if(!test_compare_same_named_instances())
+ return EXIT_FAILURE;
+
+ if(!test_compare_same_named_instances_unrelated_differences())
+ return EXIT_FAILURE;
+
+ if(!test_compare_same_named_instances_with_relationship())
+ return EXIT_FAILURE;
+
+ if(!test_compare_same_named_instances_with_related_relationship())
+ return EXIT_FAILURE;
+
+ Glom::libglom_deinit();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]