[glom] Reenable test_load_document.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Reenable test_load_document.
- Date: Mon, 26 Apr 2010 19:48:49 +0000 (UTC)
commit 033469bb94063041b14fb4292b02bb791fb3464c
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Apr 26 21:47:54 2010 +0200
Reenable test_load_document.
* Makefile_tests.am: Reenable test_load_document.cc
* tests/test_load_document/test_load_document.cc: Restore (rewrite) this
missing file.
ChangeLog | 8 ++
Makefile_tests.am | 9 +-
tests/test_document_load/test_document_load.cc | 129 ++++++++++++++++++++++++
3 files changed, 141 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8e38d87..9d704f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,14 @@
2010-04-26 Murray Cumming <murrayc murrayc com>
+ Reenable test_load_document.
+
+ * Makefile_tests.am: Reenable test_load_document.cc
+ * tests/test_load_document/test_load_document.cc: Restore (rewrite) this
+ missing file.
+
+2010-04-26 Murray Cumming <murrayc murrayc com>
+
* configure.ac: Remove the dist-bzip2 option that was added by mistake.
2010-04-26 Murray Cumming <murrayc murrayc com>
diff --git a/Makefile_tests.am b/Makefile_tests.am
index af96533..a2f07ca 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -21,6 +21,7 @@ check_PROGRAMS = \
glom/libglom/test_sharedptr_layoutitem \
glom/utility_widgets/test_flowtable \
glom/test_pyembed \
+ tests/test_document_load/test_document_load \
tests/test_parsing_time \
tests/test_signal_reemit \
tests/test_load_python_library\
@@ -34,10 +35,8 @@ check_PROGRAMS = \
tests/glade_toplevels_instantiation \
tests/test_selfhosting_new_empty/test_selfhosting_new_empty
-# Source file missing:
-# tests/test_document_load/test_document_load
-
-TESTS = tests/test_parsing_time \
+TESTS = tests/test_document_load/test_document_load \
+ tests/test_parsing_time \
tests/test_signal_reemit \
tests/test_dtd_file_validation.sh \
tests/test_glade_file_validation.sh \
@@ -70,7 +69,7 @@ glom_libglom_example_document_load_SOURCES = glom/libglom/example_document_load.
glom_libglom_test_sharedptr_layoutitem_SOURCES = glom/libglom/test_sharedptr_layoutitem.cc
glom_test_pyembed_SOURCES = glom/test_pyembed.cc
-#tests_test_document_load_test_document_load_SOURCES = tests/test_document_load/test_document_load.cc
+tests_test_document_load_test_document_load_SOURCES = tests/test_document_load/test_document_load.cc
tests_test_parsing_time_SOURCES = tests/test_parsing_time.cc
tests_test_signal_reemit_SOURCES = tests/test_signal_reemit.cc
tests_test_load_python_library_SOURCES = tests/test_load_python_library.cc
diff --git a/tests/test_document_load/test_document_load.cc b/tests/test_document_load/test_document_load.cc
new file mode 100644
index 0000000..9510ad8
--- /dev/null
+++ b/tests/test_document_load/test_document_load.cc
@@ -0,0 +1,129 @@
+/* Glom
+ *
+ * Copyright (C) 2010 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
+71 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <libglom/document/document.h>
+#include <libglom/init.h>
+#include <giomm/file.h>
+
+template<typename T_Container>
+bool contains(const T_Container& container, const Glib::ustring& name)
+{
+ typename T_Container::const_iterator iter =
+ std::find(container.begin(), container.end(), name);
+ return iter != container.end();
+}
+
+template<typename T_Container>
+bool contains_named(const T_Container& container, const Glib::ustring& name)
+{
+ typedef typename T_Container::value_type::object_type type_item;
+ typename T_Container::const_iterator iter =
+ std::find_if(container.begin(), container.end(),
+ Glom::predicate_FieldHasName<type_item>(name));
+ return iter != container.end();
+}
+
+int main()
+{
+ Glom::libglom_init();
+
+ // Get a URI for a test file:
+ Glib::ustring uri;
+
+ #ifdef GLIBMM_EXCEPTIONS_ENABLED
+ try
+ {
+ const std::string path =
+ Glib::build_filename(GLOM_DOCDIR_EXAMPLES_NOTINSTALLED,
+ "example_music_collection.glom");
+ uri = Glib::filename_to_uri(path);
+ }
+ catch(const Glib::ConvertError& ex)
+ {
+ std::cerr << "Exception from Glib::filename_to_uri(): " << ex.what();
+ return EXIT_FAILURE;
+ }
+ #else
+ std::auto_ptr<Glib::Error> ex;
+ uri = Glib::filename_to_uri("/usr/share/glom/doc/examples/example_music_collection.glom", ex);
+ #endif
+
+ //std::cout << "URI=" << uri << std::endl;
+
+
+ // Load the document:
+ Glom::Document document;
+ document.set_file_uri(uri);
+ int failure_code = 0;
+ const bool test = document.load(failure_code);
+ //std::cout << "Document load result=" << test << std::endl;
+
+ if(!test)
+ {
+ std::cerr << "Document::load() failed with failure_code=" << failure_code << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ //Test some known details:
+ g_assert(document.get_is_example_file());
+ g_assert(document.get_database_title() == "Music Collection");
+
+ 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"));
+
+ //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"));
+ 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"));
+
+ //Check some fields:
+ Glom::sharedptr<const Glom::Field> field = document.get_field("albums", "album_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");
+ 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");
+ 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");
+
+ Glom::libglom_deinit();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]