[glom] Tests: Add a shared get_field_on_layout() function.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Tests: Add a shared get_field_on_layout() function.
- Date: Sat, 3 Dec 2011 14:01:09 +0000 (UTC)
commit 6c8bf360e12f2fd17c058ca27ca537b3d6e08952
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Dec 3 14:42:15 2011 +0100
Tests: Add a shared get_field_on_layout() function.
* tests/test_document_load.cc: Move get_field_on_layout() to
* Makefile_tests.am:
* tests/test_utils.[h|cc]: here.
ChangeLog | 9 +++++++
Makefile_tests.am | 5 +++-
tests/test_document_load.cc | 32 +------------------------
tests/test_utils.cc | 54 +++++++++++++++++++++++++++++++++++++++++++
tests/test_utils.h | 31 ++++++++++++++++++++++++
5 files changed, 99 insertions(+), 32 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ec62df9..3bc8093 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-12-03 Murray Cumming <murrayc murrayc com>
+
+ Tests: Add a shared get_field_on_layout() function.
+
+ * tests/test_document_load.cc: Move get_field_on_layout() to
+ * Makefile_tests.am:
+ * tests/test_utils.[h|cc]: here.
+
+
2011-12-02 Murray Cumming <murrayc murrayc com>
Added test_document_load_translations
diff --git a/Makefile_tests.am b/Makefile_tests.am
index aef30d9..1e7d6f4 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -100,7 +100,7 @@ glom_libglom_test_sharedptr_layoutitem_SOURCES = glom/libglom/test_sharedptr_lay
glom_libglom_test_sharedptr_layoutitem_LDADD = $(tests_ldadd)
glom_libglom_test_sharedptr_layoutitem_CPPFLAGS = $(tests_cppflags)
-tests_test_document_load_SOURCES = tests/test_document_load.cc
+tests_test_document_load_SOURCES = tests/test_document_load.cc $(sources_test_utils)
tests_test_document_load_LDADD = $(tests_ldadd)
tests_test_document_load_CPPFLAGS = $(tests_cppflags)
@@ -166,6 +166,9 @@ tests_import_test_signals_LDADD = $(tests_ldadd)
tests_import_test_signals_CPPFLAGS = $(tests_cppflags)
+sources_test_utils = tests/test_utils.h \
+ tests/test_utils.cc
+
sources_test_selfhosting_utils = tests/test_selfhosting_utils.h \
tests/test_selfhosting_utils.cc
diff --git a/tests/test_document_load.cc b/tests/test_document_load.cc
index fd01d39..4d8838a 100644
--- a/tests/test_document_load.cc
+++ b/tests/test_document_load.cc
@@ -18,6 +18,7 @@
* Boston, MA 02111-1307, USA.
*/
+#include "tests/test_utils.h"
#include <libglom/document/document.h>
#include <libglom/init.h>
#include <libglom/db_utils.h>
@@ -53,37 +54,6 @@ static bool groups_contain_named(const Glom::Document::type_list_groups& contain
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>();
-}
-
static bool needs_navigation(Glom::Document& document, const Glib::ustring& table_name, const Glib::ustring& field_name)
{
Glom::sharedptr<Glom::LayoutItem_Field> layout_item = Glom::sharedptr<Glom::LayoutItem_Field>::create();
diff --git a/tests/test_utils.cc b/tests/test_utils.cc
new file mode 100644
index 0000000..ada0ea5
--- /dev/null
+++ b/tests/test_utils.cc
@@ -0,0 +1,54 @@
+/* Glom
+ *
+ * Copyright (C) 2011 Murray Cumming
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "tests/test_utils.h"
+
+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>();
+}
+
+
diff --git a/tests/test_utils.h b/tests/test_utils.h
new file mode 100644
index 0000000..8284090
--- /dev/null
+++ b/tests/test_utils.h
@@ -0,0 +1,31 @@
+/* Glom
+ *
+ * Copyright (C) 2011 Murray Cumming
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLOM_TEST_UTILS_H
+#define GLOM_TEST_UTILS_H
+
+#include <libglom/document/document.h>
+#include <string>
+
+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);
+
+
+#endif //GLOM_TEST_UTILS_H
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]