[glom] Test report building.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Test report building.
- Date: Tue, 18 Oct 2011 18:40:04 +0000 (UTC)
commit eca8c786fbce10f9f4c50f598d5180e695d4b4ef
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Oct 17 22:08:52 2011 +0200
Test report building.
* tests/test_selfhosting_new_from_example.cc: Move most code into
utility functions in:
* tests/test_selfhosting_utils.[h|cc]:
* tests/test_selfhosting_new_then_report.cc: Add a new test that also
generates a HTML report.
* Makefile_tests: Mention the new files.
ChangeLog | 11 ++
Makefile_tests.am | 14 ++-
glom/mode_data/box_data_list.cc | 1 -
tests/test_selfhosting_new_from_example.cc | 196 +--------------------------
tests/test_selfhosting_new_then_report.cc | 65 +++++++++
tests/test_selfhosting_utils.cc | 203 ++++++++++++++++++++++++++++
tests/test_selfhosting_utils.h | 31 +++++
7 files changed, 328 insertions(+), 193 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ae6623d..2347875 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -52,6 +52,17 @@
2011-10-17 Murray Cumming <murrayc murrayc com>
+ Test report building.
+
+ * tests/test_selfhosting_new_from_example.cc: Move most code into
+ utility functions in:
+ * tests/test_selfhosting_utils.[h|cc]:
+ * tests/test_selfhosting_new_then_report.cc: Add a new test that also
+ generates a HTML report.
+ * Makefile_tests: Mention the new files.
+
+2011-10-17 Murray Cumming <murrayc murrayc com>
+
Move ReportBuilder to libglom, to make testing easier.
* glom/report_builder.[h|cc]:
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 292d1d0..33209c0 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -27,11 +27,12 @@ check_PROGRAMS = \
tests/python/test_python_module \
tests/test_selfhosting_new_empty \
tests/test_selfhosting_new_from_example \
+ tests/test_selfhosting_new_then_report \
tests/import/test_parsing \
tests/import/test_signals
TESTS = tests/test_document_load \
- tests/test_document_autosave \
+ tests/test_document_autosave \
tests/test_parsing_time \
tests/test_signal_reemit \
tests/test_dtd_file_validation.sh \
@@ -41,6 +42,7 @@ TESTS = tests/test_document_load \
tests/python/test_python_module \
tests/test_selfhosting_new_empty \
tests/test_selfhosting_new_from_example \
+ tests/test_selfhosting_new_then_report \
tests/import/test_parsing \
tests/import/test_signals
@@ -119,14 +121,22 @@ tests_import_test_signals_SOURCES = \
tests_import_test_signals_LDADD = $(GLOM_LIBS)
tests_import_test_signals_CPPFLAGS = $(tests_cppflags)
+
+sources_test_selfhosting_utils = tests/test_selfhosting_utils.h \
+ tests/test_selfhosting_utils.cc
+
tests_test_selfhosting_new_empty_SOURCES = tests/test_selfhosting_new_empty.cc
tests_test_selfhosting_new_empty_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_empty_CPPFLAGS = $(tests_cppflags)
-tests_test_selfhosting_new_from_example_SOURCES = tests/test_selfhosting_new_from_example.cc
+tests_test_selfhosting_new_from_example_SOURCES = tests/test_selfhosting_new_from_example.cc $(sources_test_selfhosting_utils)
tests_test_selfhosting_new_from_example_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_from_example_CPPFLAGS = $(tests_cppflags)
+tests_test_selfhosting_new_then_report_SOURCES = tests/test_selfhosting_new_then_report.cc $(sources_test_selfhosting_utils)
+tests_test_selfhosting_new_then_report_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_then_report_CPPFLAGS = $(tests_cppflags)
+
# UI Tests:
diff --git a/glom/mode_data/box_data_list.cc b/glom/mode_data/box_data_list.cc
index b691e49..6b17f09 100644
--- a/glom/mode_data/box_data_list.cc
+++ b/glom/mode_data/box_data_list.cc
@@ -21,7 +21,6 @@
#include "box_data_list.h"
#include <libglom/data_structure/glomconversions.h>
#include <glom/glade_utils.h>
-#include <libglom/report_builder.h>
#include <glom/mode_design/layout/dialog_layout_list.h>
#include <libglom/privs.h>
#include <libglom/db_utils.h>
diff --git a/tests/test_selfhosting_new_from_example.cc b/tests/test_selfhosting_new_from_example.cc
index c405e2b..e8864c8 100644
--- a/tests/test_selfhosting_new_from_example.cc
+++ b/tests/test_selfhosting_new_from_example.cc
@@ -18,206 +18,22 @@
* Boston, MA 02111-1307, USA.
*/
-#include <libglom/document/document.h>
-#include <libglom/connectionpool.h>
-#include <libglom/connectionpool_backends/postgres_self.h>
+#include "tests/test_selfhosting_utils.h"
#include <libglom/init.h>
-#include <libglom/privs.h>
-#include <libglom/db_utils.h>
-#include <giomm/file.h>
+#include <glib.h> //For g_assert()
#include <iostream>
-
-static void on_initialize_progress()
-{
- std::cout << "Database initialization progress" << std::endl;
-}
-
-static void on_startup_progress()
-{
- std::cout << "Database startup progress" << std::endl;
-}
-
-static void on_recreate_progress()
-{
- std::cout << "Database re-creation progress" << std::endl;
-}
-
-static void on_cleanup_progress()
-{
- std::cout << "Database cleanup progress" << std::endl;
-}
-
-/** Delete a directory, if it exists, and its contents.
- * Unlike g_file_delete(), this does not fail if the directory is not empty.
- */
-static bool delete_directory(const Glib::RefPtr<Gio::File>& directory)
-{
- if(!(directory->query_exists()))
- return true;
-
- //(Recursively) Delete any child files and directories,
- //so we can delete this directory.
- Glib::RefPtr<Gio::FileEnumerator> enumerator = directory->enumerate_children();
-
- Glib::RefPtr<Gio::FileInfo> info = enumerator->next_file();
- while(info)
- {
- Glib::RefPtr<Gio::File> child = directory->get_child(info->get_name());
- bool removed_child = false;
- if(child->query_file_type() == Gio::FILE_TYPE_DIRECTORY)
- removed_child = delete_directory(child);
- else
- removed_child = child->remove();
-
- if(!removed_child)
- return false;
-
- info = enumerator->next_file();
- }
-
- //Delete the actual directory:
- if(!directory->remove())
- return false;
-
- return true;
-}
-
-/** Delete a directory, if it exists, and its contents.
- * Unlike g_file_delete(), this does not fail if the directory is not empty.
- */
-static bool delete_directory(const std::string& uri)
-{
- Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
- return delete_directory(file);
-}
-
-std::string temp_filepath_dir;
-
-void cleanup()
-{
- Glom::ConnectionPool* connection_pool = Glom::ConnectionPool::get_instance();
-
- const bool stopped = connection_pool->cleanup( sigc::ptr_fun(&on_cleanup_progress) );
- g_assert(stopped);
-
- //Make sure the directory is removed at the end,
- {
- const Glib::ustring uri = Glib::filename_to_uri(temp_filepath_dir);
- delete_directory(uri);
- }
-}
+#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
int main()
{
Glom::libglom_init();
- // Get a URI for a test file:
- Glib::ustring uri;
-
- 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 << G_STRFUNC << ": " << ex.what();
- return EXIT_FAILURE;
- }
-
- //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;
- }
-
- g_assert(document.get_is_example_file());;
-
- Glom::ConnectionPool* connection_pool = Glom::ConnectionPool::get_instance();
-
- //Save a copy, specifying the path to file in a directory:
- //For instance, /tmp/testfileglom/testfile.glom");
- const std::string temp_filename = "testglom";
- temp_filepath_dir = Glib::build_filename(Glib::get_tmp_dir(),
- temp_filename);
- const std::string temp_filepath = Glib::build_filename(temp_filepath_dir, temp_filename);
-
- //Make sure that the file does not exist yet:
- {
- const Glib::ustring uri = Glib::filename_to_uri(temp_filepath_dir);
- delete_directory(uri);
- }
-
- //Save the example as a real file:
- const Glib::ustring file_uri = Glib::filename_to_uri(temp_filepath);
- document.set_file_uri(file_uri);
-
- document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_SELF);
- document.set_is_example_file(false);
- document.set_network_shared(false);
- const bool saved = document.save();
- g_assert(saved);
-
- //Specify the backend and backend-specific details to be used by the connectionpool.
- connection_pool->setup_from_document(&document);
-
- //We must specify a default username and password:
- Glib::ustring password;
- const Glib::ustring user = Glom::Privs::get_default_developer_user_name(password);
- connection_pool->set_user(user);
- connection_pool->set_password(password);
-
- //Create the self-hosting files:
- const Glom::ConnectionPool::InitErrors initialized_errors =
- connection_pool->initialize( sigc::ptr_fun(&on_initialize_progress) );
- g_assert(initialized_errors == Glom::ConnectionPool::Backend::INITERROR_NONE);
-
- //Start self-hosting:
- //TODO: Let this happen automatically on first connection?
- const Glom::ConnectionPool::StartupErrors started = connection_pool->startup( sigc::ptr_fun(&on_startup_progress) );
- if(started != Glom::ConnectionPool::Backend::STARTUPERROR_NONE)
- {
- std::cerr << "connection_pool->startup(): result=" << started << std::endl;
- cleanup();
- }
- g_assert(started == Glom::ConnectionPool::Backend::STARTUPERROR_NONE);
-
- const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, sigc::ptr_fun(&on_recreate_progress) );
- if(!recreated)
- cleanup();
+ const bool recreated =
+ test_create_and_selfhost("example_music_collection.glom", document);
g_assert(recreated);
-
-
- //Test the standard print layout:
- /* Actually, we can't do this without depending on more than libglom:
- Also we should not use GTK_PRINT_OPERATION_ACTION_PRINT when testing.
- const Glib::ustring test_table_name = "albums";
- Glib::RefPtr<Gtk::PageSetup> page_setup = Gtk::PageSetup::create(); //TODO: m_canvas.get_page_setup();
- sharedptr<PrintLayout> print_layout =
- PrintLayoutUtils::create_standard(page_setup, "albums", document);
-
- //Show the print preview window:
- FoundSet foundset;
- foundset.m_table_name = test_table_name;
- foundset.m_where_clause = Utils::build_simple_where_expression(
- test_table_name, "album_id", Gnome::Gda::Value("1"));
- PrintLayoutUtils::do_print_layout(print_layout, found_set,
- false, document, &window);
- */
- cleanup();
+ test_selfhosting_cleanup();
Glom::libglom_deinit();
diff --git a/tests/test_selfhosting_new_then_report.cc b/tests/test_selfhosting_new_then_report.cc
new file mode 100644
index 0000000..398ef7c
--- /dev/null
+++ b/tests/test_selfhosting_new_then_report.cc
@@ -0,0 +1,65 @@
+/* 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 "tests/test_selfhosting_utils.h"
+#include <libglom/init.h>
+#include <libglom/report_builder.h>
+#include <glib.h> //For g_assert()
+#include <iostream>
+#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
+
+int main()
+{
+ Glom::libglom_init();
+
+ Glom::Document document;
+ const bool recreated =
+ test_create_and_selfhost("example_music_collection.glom", document);
+ g_assert(recreated);
+
+ const Glom::sharedptr<const Glom::Report> report_temp =
+ Glom::ReportBuilder::create_standard_list_report(&document, "albums");
+
+ Glom::FoundSet found_set; //TODO: Test a where clause.
+ found_set.m_table_name = "albums";
+ Glom::ReportBuilder report_builder;
+ report_builder.set_document(&document);
+ const std::string filepath =
+ report_builder.report_build(found_set, report_temp);
+ if(filepath.empty())
+ {
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ /*
+ if(filecontents.find("Bruce Springsteen") == std::string::npos)
+ {
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+ */
+
+ test_selfhosting_cleanup();
+
+ Glom::libglom_deinit();
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
new file mode 100644
index 0000000..0bc5406
--- /dev/null
+++ b/tests/test_selfhosting_utils.cc
@@ -0,0 +1,203 @@
+/* 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_selfhosting_utils.h"
+
+#include <libglom/document/document.h>
+#include <libglom/connectionpool.h>
+#include <libglom/connectionpool_backends/postgres_self.h>
+#include <libglom/init.h>
+#include <libglom/privs.h>
+#include <libglom/db_utils.h>
+#include <giomm/file.h>
+#include <iostream>
+
+static void on_initialize_progress()
+{
+ std::cout << "Database initialization progress" << std::endl;
+}
+
+static void on_startup_progress()
+{
+ std::cout << "Database startup progress" << std::endl;
+}
+
+static void on_recreate_progress()
+{
+ std::cout << "Database re-creation progress" << std::endl;
+}
+
+static void on_cleanup_progress()
+{
+ std::cout << "Database cleanup progress" << std::endl;
+}
+
+/** Delete a directory, if it exists, and its contents.
+ * Unlike g_file_delete(), this does not fail if the directory is not empty.
+ */
+static bool delete_directory(const Glib::RefPtr<Gio::File>& directory)
+{
+ if(!(directory->query_exists()))
+ return true;
+
+ //(Recursively) Delete any child files and directories,
+ //so we can delete this directory.
+ Glib::RefPtr<Gio::FileEnumerator> enumerator = directory->enumerate_children();
+
+ Glib::RefPtr<Gio::FileInfo> info = enumerator->next_file();
+ while(info)
+ {
+ Glib::RefPtr<Gio::File> child = directory->get_child(info->get_name());
+ bool removed_child = false;
+ if(child->query_file_type() == Gio::FILE_TYPE_DIRECTORY)
+ removed_child = delete_directory(child);
+ else
+ removed_child = child->remove();
+
+ if(!removed_child)
+ return false;
+
+ info = enumerator->next_file();
+ }
+
+ //Delete the actual directory:
+ if(!directory->remove())
+ return false;
+
+ return true;
+}
+
+/** Delete a directory, if it exists, and its contents.
+ * Unlike g_file_delete(), this does not fail if the directory is not empty.
+ */
+static bool delete_directory(const std::string& uri)
+{
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+ return delete_directory(file);
+}
+
+std::string temp_filepath_dir;
+
+void test_selfhosting_cleanup()
+{
+ Glom::ConnectionPool* connection_pool = Glom::ConnectionPool::get_instance();
+
+ const bool stopped = connection_pool->cleanup( sigc::ptr_fun(&on_cleanup_progress) );
+ g_assert(stopped);
+
+ //Make sure the directory is removed at the end,
+ {
+ const Glib::ustring uri = Glib::filename_to_uri(temp_filepath_dir);
+ delete_directory(uri);
+ }
+}
+
+
+bool test_create_and_selfhost(const std::string& example_filename, Glom::Document& document)
+{
+ // Get a URI for a test file:
+ Glib::ustring uri;
+
+ try
+ {
+ const std::string path =
+ Glib::build_filename(GLOM_DOCDIR_EXAMPLES_NOTINSTALLED,
+ example_filename);
+ uri = Glib::filename_to_uri(path);
+ }
+ catch(const Glib::ConvertError& ex)
+ {
+ std::cerr << G_STRFUNC << ": " << ex.what();
+ return EXIT_FAILURE;
+ }
+
+ //std::cout << "URI=" << uri << std::endl;
+
+
+ // Load the 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;
+ }
+
+ g_assert(document.get_is_example_file());;
+
+ Glom::ConnectionPool* connection_pool = Glom::ConnectionPool::get_instance();
+
+ //Save a copy, specifying the path to file in a directory:
+ //For instance, /tmp/testfileglom/testfile.glom");
+ const std::string temp_filename = "testglom";
+ temp_filepath_dir = Glib::build_filename(Glib::get_tmp_dir(),
+ temp_filename);
+ const std::string temp_filepath = Glib::build_filename(temp_filepath_dir, temp_filename);
+
+ //Make sure that the file does not exist yet:
+ {
+ const Glib::ustring uri = Glib::filename_to_uri(temp_filepath_dir);
+ delete_directory(uri);
+ }
+
+ //Save the example as a real file:
+ const Glib::ustring file_uri = Glib::filename_to_uri(temp_filepath);
+ document.set_file_uri(file_uri);
+
+ document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_SELF);
+ document.set_is_example_file(false);
+ document.set_network_shared(false);
+ const bool saved = document.save();
+ g_assert(saved);
+
+ //Specify the backend and backend-specific details to be used by the connectionpool.
+ connection_pool->setup_from_document(&document);
+
+ //We must specify a default username and password:
+ Glib::ustring password;
+ const Glib::ustring user = Glom::Privs::get_default_developer_user_name(password);
+ connection_pool->set_user(user);
+ connection_pool->set_password(password);
+
+ //Create the self-hosting files:
+ const Glom::ConnectionPool::InitErrors initialized_errors =
+ connection_pool->initialize( sigc::ptr_fun(&on_initialize_progress) );
+ g_assert(initialized_errors == Glom::ConnectionPool::Backend::INITERROR_NONE);
+
+ //Start self-hosting:
+ //TODO: Let this happen automatically on first connection?
+ const Glom::ConnectionPool::StartupErrors started = connection_pool->startup( sigc::ptr_fun(&on_startup_progress) );
+ if(started != Glom::ConnectionPool::Backend::STARTUPERROR_NONE)
+ {
+ std::cerr << "connection_pool->startup(): result=" << started << std::endl;
+ test_selfhosting_cleanup();
+ }
+ g_assert(started == Glom::ConnectionPool::Backend::STARTUPERROR_NONE);
+
+ const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, sigc::ptr_fun(&on_recreate_progress) );
+ if(!recreated)
+ test_selfhosting_cleanup();
+
+ return recreated;
+}
+
diff --git a/tests/test_selfhosting_utils.h b/tests/test_selfhosting_utils.h
new file mode 100644
index 0000000..412d83b
--- /dev/null
+++ b/tests/test_selfhosting_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_SELFHOSTING_UTILS_H
+#define GLOM_TEST_SELFHOSTING_UTILS_H
+
+#include <libglom/document/document.h>
+#include <string>
+
+bool test_create_and_selfhost(const std::string& example_filename, Glom::Document& document);
+void test_selfhosting_cleanup();
+
+#endif //GLOM_TEST_SELFHOSTING_UTILS_H
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]