From 15d2e90a54009efb31300d8b59292d71ce98a5b2 Mon Sep 17 00:00:00 2001 From: Nikki VonHollen Date: Tue, 20 Dec 2011 11:10:17 -0500 Subject: =?UTF-8?q?Bug=2043608=20=E2=80=93=20Add=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://bugs.freedesktop.org/show_bug.cgi?id=43608 Basic unittest support and a few tests. Adds basic unit tests for: PolkitIdentity, PolkitUnixUser, PolkitUnixGroup, PolkitBackendLocalAuthorizationStore, and PolkitBackendLocalAuthority. Signed-off-by: David Zeuthen --- test/polkit/Makefile.am | 46 ++++++++++++ test/polkit/polkitidentitytest.c | 148 ++++++++++++++++++++++++++++++++++++++ test/polkit/polkitunixgrouptest.c | 82 +++++++++++++++++++++ test/polkit/polkitunixusertest.c | 82 +++++++++++++++++++++ 4 files changed, 358 insertions(+) create mode 100644 test/polkit/Makefile.am create mode 100644 test/polkit/polkitidentitytest.c create mode 100644 test/polkit/polkitunixgrouptest.c create mode 100644 test/polkit/polkitunixusertest.c (limited to 'test/polkit') diff --git a/test/polkit/Makefile.am b/test/polkit/Makefile.am new file mode 100644 index 0000000..70fbf67 --- /dev/null +++ b/test/polkit/Makefile.am @@ -0,0 +1,46 @@ + +NULL = + +INCLUDES = \ + -I$(top_builddir)/src \ + -I$(top_srcdir)/src \ + -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \ + -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_BIN_DIR=\""$(bindir)"\" \ + -DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \ + -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ + -D_POSIX_PTHREAD_SEMANTICS \ + -D_REENTRANT \ + $(NULL) + +AM_CFLAGS = \ + $(GLIB_CFLAGS) \ + $(NULL) + +LDADD = \ + $(GLIB_LIBS) \ + $(top_builddir)/src/polkit/libpolkit-gobject-1.la \ + $(NULL) + +TEST_PROGS = + +# ---------------------------------------------------------------------------------------------------- + +TEST_PROGS += polkitunixusertest +polkitunixusertest_SOURCES = polkitunixusertest.c + +TEST_PROGS += polkitunixgrouptest +polkitunixgrouptest_SOURCES = polkitunixgrouptest.c + +TEST_PROGS += polkitidentitytest +polkitidentitytest_SOURCES = polkitidentitytest.c + +# ---------------------------------------------------------------------------------------------------- + +check_PROGRAMS = $(TEST_PROGS) +TESTS = $(TEST_PROGS) + +clean-local : + rm -f *~ diff --git a/test/polkit/polkitidentitytest.c b/test/polkit/polkitidentitytest.c new file mode 100644 index 0000000..edbc765 --- /dev/null +++ b/test/polkit/polkitidentitytest.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2011 Google Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Nikki VonHollen + */ + +#include "glib.h" +#include + + +static void +test_user_from_string (void) +{ + PolkitIdentity *identity; + PolkitUnixUser *user; + GError *error = NULL; + + identity = polkit_identity_from_string ("unix-user:root", &error); + g_assert (identity); + g_assert_no_error (error); + g_assert (POLKIT_IS_UNIX_USER (identity)); + + user = POLKIT_UNIX_USER (identity); + g_assert (user); + + g_object_unref (user); +} + + +static void +test_group_from_string (void) +{ + PolkitIdentity *identity; + PolkitUnixGroup *group; + GError *error = NULL; + + identity = polkit_identity_from_string ("unix-group:root", &error); + g_assert (identity); + g_assert_no_error (error); + g_assert (POLKIT_IS_UNIX_GROUP (identity)); + + group = POLKIT_UNIX_GROUP (identity); + g_assert (group); + + g_object_unref (group); +} + + +static void +test_user_to_string (void) +{ + PolkitIdentity *identity; + GError *error = NULL; + gchar *value; + + identity = polkit_identity_from_string ("unix-user:root", &error); + g_assert (identity); + g_assert_no_error (error); + + value = polkit_identity_to_string (identity); + g_assert_cmpstr (value, ==, "unix-user:root"); + + g_free (value); + g_object_unref (identity); +} + + +static void +test_group_to_string (void) +{ + PolkitIdentity *identity; + GError *error = NULL; + gchar *value; + + identity = polkit_identity_from_string ("unix-group:root", &error); + g_assert (identity); + g_assert_no_error (error); + + value = polkit_identity_to_string (identity); + g_assert_cmpstr (value, ==, "unix-group:root"); + + g_free (value); + g_object_unref (identity); +} + + +static void +test_equal (void) +{ + PolkitIdentity *identity_a, *identity_b; + GError *error = NULL; + + identity_a = polkit_identity_from_string ("unix-group:root", &error); + identity_b = polkit_identity_from_string ("unix-group:root", &error); + g_assert (polkit_identity_equal (identity_a, identity_b)); + + g_object_unref (identity_a); + g_object_unref (identity_b); +} + + +static void +test_hash (void) +{ + PolkitIdentity *identity_a, *identity_b; + guint hash_a, hash_b; + GError *error = NULL; + + identity_a = polkit_identity_from_string ("unix-group:root", &error); + identity_b = polkit_identity_from_string ("unix-group:root", &error); + + hash_a = polkit_identity_hash (identity_a); + hash_b = polkit_identity_hash (identity_b); + g_assert_cmpint (hash_a, ==, hash_b); + + g_object_unref (identity_a); + g_object_unref (identity_b); +} + + +int +main (int argc, char *argv[]) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/PolkitIdentity/user_from_string", test_user_from_string); + g_test_add_func ("/PolkitIdentity/user_to_string", test_user_to_string); + g_test_add_func ("/PolkitIdentity/group_from_string", test_group_from_string); + g_test_add_func ("/PolkitIdentity/group_to_string", test_group_to_string); + g_test_add_func ("/PolkitIdentity/equal", test_equal); + g_test_add_func ("/PolkitIdentity/hash", test_hash); + return g_test_run (); +} diff --git a/test/polkit/polkitunixgrouptest.c b/test/polkit/polkitunixgrouptest.c new file mode 100644 index 0000000..f1417b3 --- /dev/null +++ b/test/polkit/polkitunixgrouptest.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011 Google Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Nikki VonHollen + */ + +#include "glib.h" +#include + + +static void +test_new (void) +{ + PolkitUnixGroup *group; + + group = POLKIT_UNIX_GROUP (polkit_unix_group_new (0)); + g_assert (group); + + gint group_gid = polkit_unix_group_get_gid (group); + g_assert_cmpint (group_gid, ==, 0); + + g_object_unref (group); +} + + +static void +test_new_for_name (void) +{ + GError *error = NULL; + PolkitUnixGroup *group; + + group = POLKIT_UNIX_GROUP (polkit_unix_group_new_for_name ("root", &error)); + g_assert (group); + g_assert_no_error (error); + + gint group_gid = polkit_unix_group_get_gid (group); + g_assert_cmpint (group_gid, ==, 0); + + g_object_unref (group); +} + + +static void +test_set_gid (void) +{ + PolkitUnixGroup *group; + group = POLKIT_UNIX_GROUP (polkit_unix_group_new (0)); + + polkit_unix_group_set_gid (group, 5); + + gint group_gid = polkit_unix_group_get_gid (group); + g_assert_cmpint (group_gid, ==, 5); + + g_object_unref (group); +} + + +int +main (int argc, char *argv[]) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/PolkitUnixGroup/new", test_new); + g_test_add_func ("/PolkitUnixGroup/new_for_name", test_new_for_name); + g_test_add_func ("/PolkitUnixGroup/set_gid", test_set_gid); + return g_test_run (); +} diff --git a/test/polkit/polkitunixusertest.c b/test/polkit/polkitunixusertest.c new file mode 100644 index 0000000..1ad0a65 --- /dev/null +++ b/test/polkit/polkitunixusertest.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011 Google Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Nikki VonHollen + */ + +#include "glib.h" +#include + + +static void +test_new (void) +{ + PolkitUnixUser *user; + + user = POLKIT_UNIX_USER (polkit_unix_user_new (0)); + g_assert (user); + + gint user_uid = polkit_unix_user_get_uid (user); + g_assert_cmpint (user_uid, ==, 0); + + g_object_unref (user); +} + + +static void +test_new_for_name (void) +{ + GError *error = NULL; + PolkitUnixUser *user; + + user = POLKIT_UNIX_USER (polkit_unix_user_new_for_name ("root", &error)); + g_assert (user); + g_assert_no_error (error); + + gint user_uid = polkit_unix_user_get_uid (user); + g_assert_cmpint (user_uid, ==, 0); + + g_object_unref (user); +} + + +static void +test_set_uid (void) +{ + PolkitUnixUser *user; + user = POLKIT_UNIX_USER (polkit_unix_user_new (0)); + + polkit_unix_user_set_uid (user, 5); + + gint user_uid = polkit_unix_user_get_uid (user); + g_assert_cmpint (user_uid, ==, 5); + + g_object_unref (user); +} + + +int +main (int argc, char *argv[]) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/PolkitUnixUser/new", test_new); + g_test_add_func ("/PolkitUnixUser/new_for_name", test_new_for_name); + g_test_add_func ("/PolkitUnixUser/set_uid", test_set_uid); + return g_test_run (); +} -- cgit v1.2.1