diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-01-24 08:03:26 +0100 |
---|---|---|
committer | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-03-27 16:31:58 +0200 |
commit | 4cf5a0ce431a28732c453340ccf17e4f5dc46857 (patch) | |
tree | c730cc932461238fcfa52ebd297c92b4ce2500ec | |
parent | d875586bab506b7fdb4b2e0ce12c4c7f307cc6bd (diff) | |
download | libproxy-git-4cf5a0ce431a28732c453340ccf17e4f5dc46857.tar.gz |
Add initial config GNOME test (#12)
-rw-r--r-- | src/backend/plugins/config-gnome/config-gnome.c | 2 | ||||
-rw-r--r-- | src/tests/config-gnome-test.c | 121 | ||||
-rw-r--r-- | src/tests/meson.build | 13 |
3 files changed, 135 insertions, 1 deletions
diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index f894498..0416d2e 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -113,7 +113,7 @@ store_response (GStrvBuilder *builder, g_string_append_printf (tmp, "%s:%d", host, port); - g_strv_builder_add (builder, g_string_free (tmp, TRUE)); + g_strv_builder_add (builder, g_string_free (tmp, FALSE)); } } diff --git a/src/tests/config-gnome-test.c b/src/tests/config-gnome-test.c new file mode 100644 index 0000000..2f4bb8c --- /dev/null +++ b/src/tests/config-gnome-test.c @@ -0,0 +1,121 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2022-2023 Jan-Michael Brummer <jan.brummer@tabos.org> + * + * 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ******************************************************************************/ + +#include "px-manager.h" + +#include "px-manager-helper.h" + +#include <glib.h> +#include <gio/gio.h> + +typedef struct { + GSettings *proxy_settings; + GSettings *http_proxy_settings; + GSettings *https_proxy_settings; + GSettings *ftp_proxy_settings; +} Fixture; + +enum { + GNOME_PROXY_MODE_NONE = 0, + GNOME_PROXY_MODE_MANUAL, + GNOME_PROXY_MODE_AUTO +}; + +typedef struct { + int mode; + const char *proxy; + int proxy_port; + const char *url; + const char *expected_return; + gboolean success; +} ConfigGnomeTest; + +static const ConfigGnomeTest config_gnome_test_set[] = { + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "https://www.example.com", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://www.example.com", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "ftp://www.example.com", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://localhost:1234", "http://127.0.0.1:8080", TRUE}, +}; + +static void +fixture_setup (Fixture *self, + gconstpointer data) +{ + self->proxy_settings = g_settings_new ("org.gnome.system.proxy"); + self->http_proxy_settings = g_settings_new ("org.gnome.system.proxy.http"); + self->https_proxy_settings = g_settings_new ("org.gnome.system.proxy.https"); + self->ftp_proxy_settings = g_settings_new ("org.gnome.system.proxy.ftp"); +} + +static void +fixture_teardown (Fixture *fixture, + gconstpointer data) +{ +} + +static void +test_config_gnome (Fixture *self, + const void *user_data) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_gnome_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigGnomeTest test = config_gnome_test_set[idx]; + + g_settings_set_enum (self->proxy_settings, "mode", test.mode); + g_settings_set_string (self->http_proxy_settings, "host", test.proxy); + g_settings_set_int (self->http_proxy_settings, "port", test.proxy_port); + g_settings_set_string (self->https_proxy_settings, "host", test.proxy); + g_settings_set_int (self->https_proxy_settings, "port", test.proxy_port); + g_settings_set_string (self->ftp_proxy_settings, "host", test.proxy); + g_settings_set_int (self->ftp_proxy_settings, "port", test.proxy_port); + + manager = px_test_manager_new ("config-gnome"); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + if (test.success) + g_assert_cmpstr (config[0], ==, test.expected_return); + else + g_assert_cmpstr (config[0], !=, test.expected_return); + + g_clear_object (&manager); + } +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add ("/config/gnome", Fixture, NULL, fixture_setup, test_config_gnome, fixture_teardown); + + return g_test_run (); +} diff --git a/src/tests/meson.build b/src/tests/meson.build index c03e0e4..d745d7e 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -2,6 +2,7 @@ if get_option('tests') envs = [ 'G_TEST_SRCDIR=' + meson.current_source_dir(), 'G_TEST_BUILDDIR=' + meson.current_build_dir(), + 'GSETTINGS_BACKEND=memory', ] test_cargs = ['-UG_DISABLE_ASSERT'] @@ -39,4 +40,16 @@ if get_option('tests') env: envs ) endif + + if get_option('config-gnome') + config_gnome_test = executable('test-config-gnome', + ['config-gnome-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config GNOMEtest', + config_gnome_test, + env: [envs, 'XDG_CURRENT_DESKTOP=GNOME'], + ) + endif endif |