summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:30:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:30:14 +0000
commitf38bddc70a6ec7c1ab26d9a8b06eed25d618ae22 (patch)
tree6437d0de9ba7fb9b0933a7c0eaa610a404d79e4e /tests
parentInitial commit. (diff)
downloadgdm3-f38bddc70a6ec7c1ab26d9a8b06eed25d618ae22.tar.xz
gdm3-f38bddc70a6ec7c1ab26d9a8b06eed25d618ae22.zip
Adding upstream version 3.38.2.1.upstream/3.38.2.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/m-common.c81
-rw-r--r--tests/meson.build17
-rw-r--r--tests/s-common-address.c209
-rw-r--r--tests/s-common-address.h28
-rw-r--r--tests/s-common.c110
-rw-r--r--tests/s-common.h28
6 files changed, 473 insertions, 0 deletions
diff --git a/tests/m-common.c b/tests/m-common.c
new file mode 100644
index 0000000..0c533d0
--- /dev/null
+++ b/tests/m-common.c
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <stdlib.h>
+#include <glib/gi18n.h>
+#include <glib.h>
+#include <glib-object.h>
+
+#include "s-common-address.h"
+#include "s-common.h"
+
+static gboolean no_fork = FALSE;
+static gboolean verbose = FALSE;
+
+static GOptionEntry entries[] = {
+ {"no-fork", 0, 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork individual tests", NULL},
+ {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "Enable verbose output", NULL},
+ {NULL}
+};
+
+int
+main (int argc, char **argv)
+{
+ GOptionContext *context;
+ SRunner *r;
+ int failed;
+ GError *error;
+
+ failed = 0;
+
+ context = g_option_context_new ("");
+ g_option_context_add_main_entries (context, entries, NULL);
+ error = NULL;
+ g_option_context_parse (context, &argc, &argv, &error);
+ g_option_context_free (context);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ exit (EXIT_FAILURE);
+ }
+
+ r = srunner_create (suite_common_address ());
+
+ if (no_fork) {
+ srunner_set_fork_status (r, CK_NOFORK);
+ }
+
+ srunner_run_all (r, verbose ? CK_VERBOSE : CK_NORMAL);
+ failed = srunner_ntests_failed (r);
+ srunner_free (r);
+
+ r = srunner_create (suite_common ());
+
+ if (no_fork) {
+ srunner_set_fork_status (r, CK_NOFORK);
+ }
+
+ srunner_run_all (r, verbose ? CK_VERBOSE : CK_NORMAL);
+ failed |= srunner_ntests_failed (r);
+ srunner_free (r);
+
+ return failed != 0;
+}
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..128b5d2
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,17 @@
+m_common_test_src = [
+ 'm-common.c',
+ 's-common-address.c',
+ 's-common.c',
+]
+
+m_common_test_deps = [
+ libgdmcommon_dep,
+ libcheck_dep,
+]
+
+m_common_test = executable('m-common',
+ m_common_test_src,
+ dependencies: m_common_test_deps,
+)
+
+test('m-common', m_common_test)
diff --git a/tests/s-common-address.c b/tests/s-common-address.c
new file mode 100644
index 0000000..bd4e2ca
--- /dev/null
+++ b/tests/s-common-address.c
@@ -0,0 +1,209 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Andrew Ziem <ahz001@gmail.com>
+ * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <stdlib.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <stdio.h>
+#include <glib.h>
+#include <check.h>
+
+#include "gdm-address.h"
+#include "s-common-address.h"
+
+static GdmAddress *ga;
+static GdmAddress *ga192;
+static struct sockaddr sa;
+static struct sockaddr_in *s_in;
+
+#ifdef ENABLE_IPV6
+static GdmAddress *ga6;
+static struct sockaddr_storage sa6;
+static struct sockaddr_in6 *s_in6;
+#endif
+
+static void
+setup (void)
+{
+ s_in = (struct sockaddr_in *) &sa;
+ s_in->sin_family = AF_INET;
+ s_in->sin_port = htons (25);
+ s_in->sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+ ga = gdm_address_new_from_sockaddr (&sa, sizeof (sa));
+ ck_assert (NULL != ga);
+
+ s_in->sin_addr.s_addr = htonl (0xc0a80001); /* 192.168.0.1 */
+ ga192 = gdm_address_new_from_sockaddr (&sa, sizeof (sa));
+ ck_assert (NULL != (ga192));
+
+#ifdef ENABLE_IPV6
+ s_in6 = (struct sockaddr_in6 *) &sa6;
+ s_in6->sin6_family = AF_INET6;
+ s_in6->sin6_port = htons (25);
+ s_in6->sin6_addr = in6addr_loopback;
+ ga6 = gdm_address_new_from_sockaddr ((struct sockaddr*)&sa6, sizeof(sa6));
+ ck_assert (NULL != ga6);
+#endif
+}
+
+static void
+teardown (void)
+{
+ gdm_address_free (ga);
+ gdm_address_free (ga192);
+#ifdef ENABLE_IPV6
+ gdm_address_free (ga6);
+#endif
+}
+
+
+/*
+ * GType gdm_address_get_type (void);
+ */
+START_TEST (test_gdm_address_get_type)
+{
+ gdm_address_get_type ();
+ /* it did not crash! :) */
+
+}
+END_TEST
+
+
+START_TEST (test_gdm_address_new_from_sockaddr)
+{
+
+ GdmAddress *_ga;
+#ifdef ENABLE_IPV6
+ GdmAddress *_ga6;
+#endif
+
+ _ga = gdm_address_new_from_sockaddr ((struct sockaddr *) &sa, sizeof (sa));
+ ck_assert (NULL != _ga);
+ gdm_address_free (_ga);
+
+#ifdef ENABLE_IPV6
+ _ga6 = gdm_address_new_from_sockaddr((struct sockaddr *) &sa6, sizeof (sa6));
+ ck_assert (NULL != _ga6);
+ gdm_address_free (_ga6);
+#endif
+
+#ifndef NO_INVALID_INPUT
+ /* invalid input */
+ ck_assert_msg (NULL == gdm_address_new_from_sockaddr ((struct sockaddr *) &sa, 1), NULL );
+ ck_assert_msg (NULL == gdm_address_new_from_sockaddr (NULL, 0), NULL);
+#endif
+}
+END_TEST
+
+
+START_TEST (test_gdm_address_get_family_type)
+{
+ ck_assert_msg (AF_INET == gdm_address_get_family_type (ga), NULL);
+
+#ifdef ENABLE_IPV6
+ ck_assert_msg (AF_INET6 == gdm_address_get_family_type (ga6), NULL);
+#endif
+
+#ifndef NO_INVALID_INPUT
+ /* invalid input */
+ ck_assert_msg (-1 == gdm_address_get_family_type (NULL), NULL);
+#endif
+
+}
+END_TEST
+
+
+START_TEST (test_gdm_address_is_loopback)
+{
+ ck_assert (TRUE == gdm_address_is_loopback (ga));
+ ck_assert (FALSE == gdm_address_is_loopback (ga192));
+
+#ifdef ENABLE_IPV6
+ ck_assert (TRUE == gdm_address_is_loopback (ga6));
+ /* FIXME: add more addresses */
+#endif
+
+#ifndef NO_INVALID_INPUT
+ /* invalid input */
+ ck_assert (FALSE == gdm_address_is_loopback (NULL));
+#endif
+}
+END_TEST
+
+
+START_TEST (test_gdm_address_equal)
+{
+ GdmAddress *gdm1;
+ struct sockaddr sa1;
+ struct sockaddr_in *sin1;
+
+ /* should be inequal */
+ sin1 = (struct sockaddr_in *) &sa1;
+ sin1->sin_family = AF_INET;
+ sin1->sin_addr.s_addr = htonl (0xc0a80001); /* 192.168.0.1 */
+ gdm1 = gdm_address_new_from_sockaddr (&sa1, sizeof (sa1));
+ ck_assert_msg (gdm_address_equal (ga, ga192) == FALSE, NULL);
+
+ /* should be equal */
+ ck_assert_msg (TRUE == gdm_address_equal (ga192, gdm1), NULL);
+
+ gdm_address_free (gdm1);
+
+#ifdef ENABLE_IPV6
+ /* should be inequal */
+ ck_assert_msg (FALSE == gdm_address_equal (ga6, ga), NULL);
+ ck_assert_msg (FALSE == gdm_address_equal (ga6, ga192), NULL);
+ ck_assert_msg (FALSE == gdm_address_equal (ga6, gdm1), NULL);
+
+ /* should be equal */
+ /* FIXME: ipv6 version too */
+#endif
+
+#ifndef NO_INVALID_INPUT
+ /* invalid input */
+ ck_assert_msg (FALSE == gdm_address_equal (NULL, NULL), NULL);
+ ck_assert_msg (FALSE == gdm_address_equal (ga, NULL), NULL);
+ ck_assert_msg (FALSE == gdm_address_equal (NULL, ga), NULL);
+#endif
+}
+END_TEST
+
+
+Suite *
+suite_common_address (void)
+{
+ Suite *s;
+ TCase *tc_core;
+
+ s = suite_create ("gdm-address");
+ tc_core = tcase_create ("core");
+
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+ tcase_add_test (tc_core, test_gdm_address_get_type);
+ tcase_add_test (tc_core, test_gdm_address_new_from_sockaddr);
+ tcase_add_test (tc_core, test_gdm_address_get_family_type);
+ tcase_add_test (tc_core, test_gdm_address_is_loopback);
+ tcase_add_test (tc_core, test_gdm_address_equal);
+ suite_add_tcase (s, tc_core);
+
+ return s;
+}
diff --git a/tests/s-common-address.h b/tests/s-common-address.h
new file mode 100644
index 0000000..32f3744
--- /dev/null
+++ b/tests/s-common-address.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __S_COMMON_ADDRESS_H
+#define __S_COMMON_ADDRESS_H
+
+#include <check.h>
+
+Suite *suite_common_address (void);
+
+#endif /* __S_COMMON_ADDRESS_H */
diff --git a/tests/s-common.c b/tests/s-common.c
new file mode 100644
index 0000000..feff326
--- /dev/null
+++ b/tests/s-common.c
@@ -0,0 +1,110 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Andrew Ziem <ahz001@gmail.com>
+ * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2015 Alexander Larsson <alexl@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <glib.h>
+#include <check.h>
+
+#include "gdm-common.h"
+#include "s-common.h"
+
+static void
+setup (void)
+{
+}
+
+static void
+teardown (void)
+{
+}
+
+static char *
+expand_fn (const char *var, gpointer data)
+{
+ if (strcmp (var, "FOO") == 0)
+ return g_strdup ("BAR");
+ if (strcmp (var, "FOO9") == 0)
+ return g_strdup ("XXX");
+ if (strcmp (var, "_FOO") == 0)
+ return g_strdup ("YYY");
+ if (strcmp (var, "FOO_FOO") == 0)
+ return g_strdup ("ZZZ");
+ return NULL;
+}
+
+static gboolean expands_to (const char *to_expand, const char *expanded)
+{
+ return strcmp (gdm_shell_expand (to_expand, expand_fn, NULL), expanded) == 0;
+}
+
+START_TEST (test_gdm_shell_expand)
+{
+ ck_assert (expands_to ("foo", "foo"));
+ ck_assert (expands_to ("foo ", "foo "));
+ ck_assert (expands_to ("foo#bar", "foo#bar"));
+ ck_assert (expands_to ("foo #bar", "foo "));
+ ck_assert (expands_to ("#bar", ""));
+ ck_assert (expands_to ("foo #bar gazonk", "foo "));
+ ck_assert (expands_to ("foo #bar gazonk", "foo "));
+ ck_assert (expands_to ("foo #bar gazonk", "foo "));
+ ck_assert (expands_to ("$FOO", "BAR"));
+ ck_assert (expands_to ("$9FOO", "$9FOO"));
+ ck_assert (expands_to ("$FOO9", "XXX"));
+ ck_assert (expands_to ("${FOO}9", "BAR9"));
+ ck_assert (expands_to ("$_FOO", "YYY"));
+ ck_assert (expands_to ("$FOO_FOO", "ZZZ"));
+ ck_assert (expands_to ("${FOO}", "BAR"));
+ ck_assert (expands_to ("$FOO$FOO", "BARBAR"));
+ ck_assert (expands_to ("${FOO}${FOO}", "BARBAR"));
+ ck_assert (expands_to ("$FOO${FOO}", "BARBAR"));
+ ck_assert (expands_to ("$foo", ""));
+ ck_assert (expands_to ("$FOOBAR", ""));
+ ck_assert (expands_to ("$FOO/BAR", "BAR/BAR"));
+ ck_assert (expands_to ("${FOO}BAR", "BARBAR"));
+ ck_assert (expands_to ("$/BAR", "$/BAR"));
+ ck_assert (expands_to ("${FOO BAR}BAR", "${FOO BAR}BAR"));
+ ck_assert (expands_to ("${}BAR", "${}BAR"));
+ ck_assert (expands_to ("${$FOO}BAR", "${BAR}BAR"));
+ ck_assert (expands_to ("\\$foo", "$foo"));
+ ck_assert (expands_to ("a\\\\b", "a\\b"));
+ ck_assert (expands_to ("a\\b", "a\\b"));
+ ck_assert (expands_to ("a\\#b", "a#b"));
+}
+END_TEST
+
+Suite *
+suite_common (void)
+{
+ Suite *s;
+ TCase *tc_core;
+
+ s = suite_create ("gdm-common");
+ tc_core = tcase_create ("core");
+
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+ tcase_add_test (tc_core, test_gdm_shell_expand);
+ suite_add_tcase (s, tc_core);
+
+ return s;
+}
diff --git a/tests/s-common.h b/tests/s-common.h
new file mode 100644
index 0000000..561186f
--- /dev/null
+++ b/tests/s-common.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 Alexander Larsson <alexl@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __S_COMMON_H
+#define __S_COMMON_H
+
+#include <check.h>
+
+Suite *suite_common (void);
+
+#endif /* __S_COMMON_H */