[glom] Added test for Glom::Priv getting of group and user names.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Added test for Glom::Priv getting of group and user names.
- Date: Tue, 1 Nov 2011 20:47:59 +0000 (UTC)
commit 6c679e44d019b3089f2bae6f2dbff26ce70a94bb
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Nov 1 21:47:43 2011 +0100
Added test for Glom::Priv getting of group and user names.
* tests/test_selfhosting_new_then_get_privs.cc: Added a test of some
Glom::Privs functions.
* Makefile_tests.am: Mention the new test.
ChangeLog | 8 ++
Makefile_tests.am | 6 ++
glom/libglom/glom_postgres.h | 3 +-
tests/test_selfhosting_new_then_get_privs.cc | 96 ++++++++++++++++++++++++++
4 files changed, 112 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 57ace1a..7358be7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-11-01 Murray Cumming <murrayc murrayc com>
+
+ Added test for Glom::Priv getting of group and user names.
+
+ * tests/test_selfhosting_new_then_get_privs.cc: Added a test of some
+ Glom::Privs functions.
+ * Makefile_tests.am: Mention the new test.
+
2011-10-31 Murray Cumming <murrayc murrayc com>
libglom: Remove an unused Utils::sqlbuilder_get_full_query() overload.
diff --git a/Makefile_tests.am b/Makefile_tests.am
index e55794c..1943c72 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -29,6 +29,7 @@ check_PROGRAMS = \
tests/test_selfhosting_new_from_example \
tests/test_selfhosting_new_then_report \
tests/test_selfhosting_new_then_image \
+ tests/test_selfhosting_new_then_get_privs \
tests/test_selfhosting_sqlinjection \
tests/import/test_parsing \
tests/import/test_signals
@@ -46,6 +47,7 @@ TESTS = tests/test_document_load \
tests/test_selfhosting_new_from_example \
tests/test_selfhosting_new_then_report \
tests/test_selfhosting_new_then_image \
+ tests/test_selfhosting_new_then_get_privs \
tests/test_selfhosting_sqlinjection \
tests/import/test_parsing \
tests/import/test_signals
@@ -146,6 +148,10 @@ tests_test_selfhosting_new_then_image_SOURCES = tests/test_selfhosting_new_then_
tests_test_selfhosting_new_then_image_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_then_image_CPPFLAGS = $(tests_cppflags) $(glom_test_image_defines)
+tests_test_selfhosting_new_then_get_privs_SOURCES = tests/test_selfhosting_new_then_get_privs.cc $(sources_test_selfhosting_utils)
+tests_test_selfhosting_new_then_get_privs_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_then_get_privs_CPPFLAGS = $(tests_cppflags)
+
tests_test_selfhosting_sqlinjection_SOURCES = tests/test_selfhosting_sqlinjection.cc $(sources_test_selfhosting_utils)
tests_test_selfhosting_sqlinjection_LDADD = $(tests_ldadd)
tests_test_selfhosting_sqlinjection_CPPFLAGS = $(tests_cppflags)
diff --git a/glom/libglom/glom_postgres.h b/glom/libglom/glom_postgres.h
index 15b7ecd..97d04ed 100644
--- a/glom/libglom/glom_postgres.h
+++ b/glom/libglom/glom_postgres.h
@@ -32,9 +32,10 @@ class GlomPostgres
{
public:
+ typedef std::vector<Glib::ustring> type_vec_strings;
+
protected:
//Utility functions to help with the odd formats of postgres internal catalog fields:
- typedef std::vector<Glib::ustring> type_vec_strings;
static type_vec_strings pg_list_separate(const Glib::ustring& str);
};
diff --git a/tests/test_selfhosting_new_then_get_privs.cc b/tests/test_selfhosting_new_then_get_privs.cc
new file mode 100644
index 0000000..cedda77
--- /dev/null
+++ b/tests/test_selfhosting_new_then_get_privs.cc
@@ -0,0 +1,96 @@
+/* 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/privs.h>
+#include <iostream>
+#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
+
+static bool test(Glom::Document::HostingMode hosting_mode)
+{
+ Glom::Document document;
+ const bool recreated =
+ test_create_and_selfhost("example_smallbusiness.glom", document, hosting_mode);
+ if(!recreated)
+ {
+ std::cerr << "Recreation failed." << std::endl;
+ return false;
+ }
+
+ const Glom::Privs::type_vec_strings groups = Glom::Privs::get_database_groups();
+ if(groups.empty())
+ {
+ std::cerr << "Failure: groups was empty." << std::endl;
+ return false;
+ }
+
+ for(Glom::Privs::type_vec_strings::const_iterator iter = groups.begin(); iter != groups.end(); ++iter)
+ {
+ const Glib::ustring group_name = *iter;
+ if(group_name.empty())
+ {
+ std::cerr << "Failure: group_name was empty." << std::endl;
+ return false;
+ }
+
+ const Glom::Privs::type_vec_strings users = Glom::Privs::get_database_users(group_name);
+ for(Glom::Privs::type_vec_strings::const_iterator iter = users.begin(); iter != users.end(); ++iter)
+ {
+ const Glib::ustring user_name = *iter;
+ if(user_name.empty())
+ {
+ std::cerr << "Failure: user_name was empty." << std::endl;
+ return false;
+ }
+
+ std::cout << "group: " << group_name << ", has user: " << user_name << std::endl;
+ }
+ }
+
+ test_selfhosting_cleanup();
+
+ return true;
+}
+
+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 this feature:
+ if(!test(Glom::Document::HOSTING_MODE_SQLITE))
+ {
+ std::cerr << "Failed with SQLite" << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+ */
+
+ Glom::libglom_deinit();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]