[glom/glom-1-32] tests: Add simple test of adding tables and reading the list back.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-32] tests: Add simple test of adding tables and reading the list back.
- Date: Wed, 5 Dec 2018 09:22:22 +0000 (UTC)
commit d8fdb451e8a9b87a77f5534ed3085ab6519bc9b8
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Dec 5 10:05:40 2018 +0100
tests: Add simple test of adding tables and reading the list back.
So that when this fails, we get a more obvious clue that this is
what failed.
This seems to fail currently due to this libgda bug:
ttps://gitlab.gnome.org/GNOME/libgda/issues/24
Makefile_tests.am | 6 ++
tests/.gitignore | 1 +
.../test_selfhosting_new_empty_then_add_tables.cc | 104 +++++++++++++++++++++
3 files changed, 111 insertions(+)
---
diff --git a/Makefile_tests.am b/Makefile_tests.am
index c16ce139..be560d0c 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -35,6 +35,7 @@ check_PROGRAMS = \
tests/test_script_check_for_problems \
tests/test_selfhosting_new_empty \
tests/test_selfhosting_new_empty_change_sysprefs \
+ tests/test_selfhosting_new_empty_then_add_tables \
tests/test_selfhosting_new_empty_then_users \
tests/test_selfhosting_new_from_example \
tests/test_selfhosting_new_from_example_defaultvalues \
@@ -83,6 +84,7 @@ TESTS = tests/test_document_load \
tests/test_script_check_for_problems \
tests/test_selfhosting_new_empty \
tests/test_selfhosting_new_empty_change_sysprefs \
+ tests/test_selfhosting_new_empty_then_add_tables \
tests/test_selfhosting_new_empty_then_users \
tests/test_selfhosting_new_from_example \
tests/test_selfhosting_new_from_example_defaultvalues \
@@ -289,6 +291,10 @@ tests_test_selfhosting_new_empty_change_sysprefs_SOURCES = tests/test_selfhostin
tests_test_selfhosting_new_empty_change_sysprefs_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_empty_change_sysprefs_CPPFLAGS = $(tests_cppflags)
+tests_test_selfhosting_new_empty_then_add_tables_SOURCES =
tests/test_selfhosting_new_empty_then_add_tables.cc $(sources_test_selfhosting_utils)
+tests_test_selfhosting_new_empty_then_add_tables_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_empty_then_add_tables_CPPFLAGS = $(tests_cppflags)
+
tests_test_selfhosting_new_empty_then_users_SOURCES = tests/test_selfhosting_new_empty_then_users.cc
$(sources_test_selfhosting_utils)
tests_test_selfhosting_new_empty_then_users_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_empty_then_users_CPPFLAGS = $(tests_cppflags)
diff --git a/tests/.gitignore b/tests/.gitignore
index 22489bf1..d8282349 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -28,6 +28,7 @@
/test_script_check_for_problems
/test_selfhosting_new_empty
/test_selfhosting_new_empty_change_sysprefs
+/test_selfhosting_new_empty_then_add_tables
/test_selfhosting_new_empty_then_users
/test_selfhosting_new_from_example
/test_selfhosting_new_from_example_defaultvalues
diff --git a/tests/test_selfhosting_new_empty_then_add_tables.cc
b/tests/test_selfhosting_new_empty_then_add_tables.cc
new file mode 100644
index 00000000..da04f649
--- /dev/null
+++ b/tests/test_selfhosting_new_empty_then_add_tables.cc
@@ -0,0 +1,104 @@
+/* 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
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include "tests/test_selfhosting_utils.h"
+#include <libglom/algorithms_utils.h>
+#include <libglom/init.h>
+#include <libglom/utils.h>
+#include <libglom/db_utils.h>
+#include <libglom/connectionpool.h>
+#include <libglom/privs.h>
+#include <glib.h> //For g_assert()
+#include <iostream>
+#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
+
+template<typename T_Container, typename T_Value>
+bool contains(const T_Container& container, const T_Value& name)
+{
+ return Glom::Utils::find_exists(container, name);
+}
+
+static bool test(Glom::Document::HostingMode hosting_mode)
+{
+ //Create and self-host the document:
+ auto document = std::make_shared<Glom::Document>();
+ if(!(test_create_and_selfhost_new_database(document, hosting_mode, "test_db")))
+ {
+ std::cerr << G_STRFUNC << ": test_create_and_selfhost_new_database() failed\n";
+ return false;
+ }
+
+
+ std::vector<Glib::ustring> table_names( {
+ "sometable",
+ } );
+
+ //MySQL has a 64-character limit on SQL identifiers:
+ /*
+ if(hosting_mode != Glom::Document::HostingMode::MYSQL_SELF)
+ {
+
table_names.emplace_back("sometablewithaverylongnameyaddayaddayaddayaddayaddyaddayaddayaddayaddayaddayaddayaddayaddayaddayaddayaddayadda");
+ }
+ */
+
+ //Add some tables, for the groups to have rights for:
+ for(const auto& table_name : table_names)
+ {
+ if(!Glom::DbUtils::create_table_with_default_fields(document, table_name))
+ {
+ std::cerr << G_STRFUNC << ": Failure: create_table_with_default_fields() failed.\n";
+ return false;
+ }
+ }
+
+
+ // Check that the tables really exist.
+ // If they don't then the newly-added groups won't have default arguments for those tables:
+ const auto tables_created = Glom::DbUtils::get_table_names_from_database(false /* plus system prefs */);
+ if(tables_created.empty())
+ {
+ std::cerr << "The added tables don't seem to exist (No tables exist).\n";
+ return false;
+ }
+
+ for(const auto& table_name : table_names)
+ {
+ if(!contains(tables_created, table_name))
+ {
+ std::cerr << "The added table doesn't seem to exist (Not in list of tables): " << table_name << "\n";
+ return false;
+ }
+ }
+
+ test_selfhosting_cleanup(false /* do not delete the file. */);
+
+ return true;
+}
+
+int main()
+{
+ Glom::libglom_init();
+
+ const auto result = test_all_hosting_modes(sigc::ptr_fun(&test));
+
+ Glom::libglom_deinit();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]