[glom/mysql: 11/21] tests: Avoid some copy/pasting.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/mysql: 11/21] tests: Avoid some copy/pasting.
- Date: Fri, 11 Jan 2013 11:32:09 +0000 (UTC)
commit b22653257d1256a6206503608da678d4c6cfd4b5
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Jan 4 00:24:43 2013 +0100
tests: Avoid some copy/pasting.
* tests/test_selfhosting_utils.[h|cc]:
Add test_all_hosting_modes().
* tests/test_selfhosting_new_empty.cc:
* tests/test_selfhosting_new_empty_change_sysprefs.cc:
* tests/test_selfhosting_new_empty_then_users.cc:
* tests/test_selfhosting_new_from_example.cc:
* tests/test_selfhosting_new_from_example_operator.cc:
* tests/test_selfhosting_new_from_example_strangepath.cc:
* tests/test_selfhosting_new_then_alter_table.cc:
* tests/test_selfhosting_new_then_change_columns.cc:
* tests/test_selfhosting_new_then_choices.cc:
* tests/test_selfhosting_new_then_image.cc:
* tests/test_selfhosting_new_then_lookup.cc:
* tests/test_selfhosting_new_then_report.cc:
* tests/test_selfhosting_non_numeric_primary_keys.cc:
* tests/test_selfhosting_sqlinjection.cc: Use this,
passing a callback slot, instead of having the same repeated
code in each file.
ChangeLog | 23 +++++++++++++++
tests/test_selfhosting_new_empty.cc | 23 +--------------
.../test_selfhosting_new_empty_change_sysprefs.cc | 16 +---------
tests/test_selfhosting_new_empty_then_users.cc | 29 +++++++------------
tests/test_selfhosting_new_from_example.cc | 16 +---------
.../test_selfhosting_new_from_example_operator.cc | 29 +++++++------------
...est_selfhosting_new_from_example_strangepath.cc | 25 +++++++----------
tests/test_selfhosting_new_then_alter_table.cc | 16 +---------
tests/test_selfhosting_new_then_change_columns.cc | 16 +---------
tests/test_selfhosting_new_then_choices.cc | 16 +---------
tests/test_selfhosting_new_then_image.cc | 16 +---------
tests/test_selfhosting_new_then_lookup.cc | 16 +---------
tests/test_selfhosting_new_then_report.cc | 16 +---------
tests/test_selfhosting_non_numeric_primary_keys.cc | 18 ++----------
tests/test_selfhosting_sqlinjection.cc | 16 +---------
tests/test_selfhosting_utils.cc | 27 ++++++++++++++++++
tests/test_selfhosting_utils.h | 7 +++++
17 files changed, 112 insertions(+), 213 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7b2a3c3..f5c2029 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
2013-01-03 Murray Cumming <murrayc murrayc com>
+ tests: Avoid some copy/pasting.
+
+ * tests/test_selfhosting_utils.[h|cc]:
+ Add test_all_hosting_modes().
+ * tests/test_selfhosting_new_empty.cc:
+ * tests/test_selfhosting_new_empty_change_sysprefs.cc:
+ * tests/test_selfhosting_new_empty_then_users.cc:
+ * tests/test_selfhosting_new_from_example.cc:
+ * tests/test_selfhosting_new_from_example_operator.cc:
+ * tests/test_selfhosting_new_from_example_strangepath.cc:
+ * tests/test_selfhosting_new_then_alter_table.cc:
+ * tests/test_selfhosting_new_then_change_columns.cc:
+ * tests/test_selfhosting_new_then_choices.cc:
+ * tests/test_selfhosting_new_then_image.cc:
+ * tests/test_selfhosting_new_then_lookup.cc:
+ * tests/test_selfhosting_new_then_report.cc:
+ * tests/test_selfhosting_non_numeric_primary_keys.cc:
+ * tests/test_selfhosting_sqlinjection.cc: Use this,
+ passing a callback slot, instead of having the same repeated
+ code in each file.
+
+2013-01-03 Murray Cumming <murrayc murrayc com>
+
MySQL: Use the new PROTOCOL connection parameter with libgda.
* glom/libglom/connectionpool_backends/mysql.cc: attempt_connect():
diff --git a/tests/test_selfhosting_new_empty.cc b/tests/test_selfhosting_new_empty.cc
index 4f47086..7536da9 100644
--- a/tests/test_selfhosting_new_empty.cc
+++ b/tests/test_selfhosting_new_empty.cc
@@ -57,28 +57,9 @@ int main()
{
Glom::libglom_init();
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_MYSQL_SELF))
- {
- std::cerr << "Failed with MySQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_empty_change_sysprefs.cc b/tests/test_selfhosting_new_empty_change_sysprefs.cc
index 141f5d8..e6584c1 100644
--- a/tests/test_selfhosting_new_empty_change_sysprefs.cc
+++ b/tests/test_selfhosting_new_empty_change_sysprefs.cc
@@ -70,21 +70,9 @@ int main()
{
Glom::libglom_init();
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_empty_then_users.cc b/tests/test_selfhosting_new_empty_then_users.cc
index bb60a42..5bb5c82 100644
--- a/tests/test_selfhosting_new_empty_then_users.cc
+++ b/tests/test_selfhosting_new_empty_then_users.cc
@@ -114,6 +114,14 @@ static bool change_privileges(const Glib::ustring& group_name, const Glib::ustri
static bool test(Glom::Document::HostingMode hosting_mode)
{
+ /* SQLite does not have user/group access levels,
+ * so the SQL queries would fail.
+ */
+ if(hosting_mode == Glom::Document::HOSTING_MODE_SQLITE)
+ {
+ return true;
+ }
+
//Create and self-host the document:
Glom::Document document;
if(!(test_create_and_selfhost_new_database(document, hosting_mode, "test_db")))
@@ -261,25 +269,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- /* SQLite does not have user/group access levels,
- * so the SQL queries woudl fail.
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- */
+
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_from_example.cc b/tests/test_selfhosting_new_from_example.cc
index ffe7538..2a10059 100644
--- a/tests/test_selfhosting_new_from_example.cc
+++ b/tests/test_selfhosting_new_from_example.cc
@@ -83,21 +83,9 @@ int main()
//so we do this so the locale will really be used:
setlocale(LC_ALL, "");
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_from_example_operator.cc b/tests/test_selfhosting_new_from_example_operator.cc
index 671c146..c603fc5 100644
--- a/tests/test_selfhosting_new_from_example_operator.cc
+++ b/tests/test_selfhosting_new_from_example_operator.cc
@@ -38,6 +38,14 @@ bool contains(const T_Container& container, const T_Value& name)
static bool test(Glom::Document::HostingMode hosting_mode)
{
+ /* SQLite does not have user/group access levels,
+ * so the SQL queries woudl fail.
+ */
+ if(hosting_mode == Glom::Document::HOSTING_MODE_SQLITE)
+ {
+ return true;
+ }
+
Glib::ustring temp_file_uri;
const Glib::ustring operator_user = "someoperator";
const Glib::ustring operator_password = "somepassword";
@@ -151,25 +159,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- /* SQLite does not have user/group access levels,
- * so the SQL queries woudl fail.
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- */
+
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_from_example_strangepath.cc b/tests/test_selfhosting_new_from_example_strangepath.cc
index 9207e20..749e0bf 100644
--- a/tests/test_selfhosting_new_from_example_strangepath.cc
+++ b/tests/test_selfhosting_new_from_example_strangepath.cc
@@ -28,6 +28,13 @@
static bool test(Glom::Document::HostingMode hosting_mode)
{
+ //TODO: MySQL: See if we can get this to work.
+ if(hosting_mode == Glom::Document::HOSTING_MODE_MYSQL_SELF)
+ {
+ test_selfhosting_cleanup(false /* do not delete the file. */);
+ return true;
+ }
+
Glom::Document document;
const bool recreated =
test_create_and_selfhost_from_example("example_music_collection.glom", document,
@@ -62,22 +69,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_then_alter_table.cc b/tests/test_selfhosting_new_then_alter_table.cc
index 2551eab..aff7446 100644
--- a/tests/test_selfhosting_new_then_alter_table.cc
+++ b/tests/test_selfhosting_new_then_alter_table.cc
@@ -90,22 +90,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_then_change_columns.cc b/tests/test_selfhosting_new_then_change_columns.cc
index c7dc336..dab0eaf 100644
--- a/tests/test_selfhosting_new_then_change_columns.cc
+++ b/tests/test_selfhosting_new_then_change_columns.cc
@@ -193,22 +193,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_then_choices.cc b/tests/test_selfhosting_new_then_choices.cc
index e953cb4..6d6c636 100644
--- a/tests/test_selfhosting_new_then_choices.cc
+++ b/tests/test_selfhosting_new_then_choices.cc
@@ -77,22 +77,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_then_image.cc b/tests/test_selfhosting_new_then_image.cc
index 3d8bcfd..59dfd6d 100644
--- a/tests/test_selfhosting_new_then_image.cc
+++ b/tests/test_selfhosting_new_then_image.cc
@@ -147,21 +147,9 @@ int main()
{
Glom::libglom_init();
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_then_lookup.cc b/tests/test_selfhosting_new_then_lookup.cc
index 4ca1f44..97f468d 100644
--- a/tests/test_selfhosting_new_then_lookup.cc
+++ b/tests/test_selfhosting_new_then_lookup.cc
@@ -205,22 +205,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_new_then_report.cc b/tests/test_selfhosting_new_then_report.cc
index 1f52732..9b676d4 100644
--- a/tests/test_selfhosting_new_then_report.cc
+++ b/tests/test_selfhosting_new_then_report.cc
@@ -69,22 +69,10 @@ static bool test(Glom::Document::HostingMode hosting_mode)
int main()
{
Glom::libglom_init();
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_non_numeric_primary_keys.cc b/tests/test_selfhosting_non_numeric_primary_keys.cc
index 051f3ff..c1f2dff 100644
--- a/tests/test_selfhosting_non_numeric_primary_keys.cc
+++ b/tests/test_selfhosting_non_numeric_primary_keys.cc
@@ -82,22 +82,10 @@ int main()
//test_selfhosting_new_from_example_in_locales.sh,
//so we do this so the locale will really be used:
setlocale(LC_ALL, "");
-
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_sqlinjection.cc b/tests/test_selfhosting_sqlinjection.cc
index 8bca01a..32ff5f9 100644
--- a/tests/test_selfhosting_sqlinjection.cc
+++ b/tests/test_selfhosting_sqlinjection.cc
@@ -256,21 +256,9 @@ int main()
{
Glom::libglom_init();
- if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
- {
- std::cerr << "Failed with PostgreSQL" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
-
- if(!test(Glom::Document::HOSTING_MODE_SQLITE))
- {
- std::cerr << "Failed with SQLite" << std::endl;
- test_selfhosting_cleanup();
- return EXIT_FAILURE;
- }
+ const int result = test_all_hosting_modes(sigc::ptr_fun(&test));
Glom::libglom_deinit();
- return EXIT_SUCCESS;
+ return result;
}
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index 3670541..62f8998 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -525,3 +525,30 @@ bool test_example_musiccollection_data(const Glom::Document* document)
const Gnome::Gda::Value album_id = data_model->get_value_at(0, 0);
return test_example_musiccollection_data_related(document, album_id);
}
+
+int test_all_hosting_modes(const SlotTest& slot)
+{
+ if(!slot(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
+ {
+ std::cerr << "Failed with PostgreSQL" << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ if(!slot(Glom::Document::HOSTING_MODE_SQLITE))
+ {
+ std::cerr << "Failed with SQLite" << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ if(!slot(Glom::Document::HOSTING_MODE_MYSQL_SELF))
+ {
+ std::cerr << "Failed with MySQL" << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/tests/test_selfhosting_utils.h b/tests/test_selfhosting_utils.h
index a11b76a..ab60f61 100644
--- a/tests/test_selfhosting_utils.h
+++ b/tests/test_selfhosting_utils.h
@@ -87,5 +87,12 @@ void test_selfhosting_cleanup(bool delete_file = true);
bool test_example_musiccollection_data(const Glom::Document* document);
+typedef sigc::slot<bool, Glom::Document::HostingMode> SlotTest;
+
+/** Call the test @a slot with various hosting modes.
+ * @result A result code for main().
+ */
+int test_all_hosting_modes(const SlotTest& slot);
+
#endif //GLOM_TEST_SELFHOSTING_UTILS_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]