summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2023-03-12 10:28:45 +0100
committerJan-Michael Brummer <jan.brummer@tabos.org>2023-03-27 16:31:58 +0200
commit8aed359ca37c0fbdc020b144428222bffa7de4ac (patch)
tree1f83acec55ba4a4288d045b8ef57a0f050acaa3b
parent5de6dc8ff556e61ba23cfd21a6e5dca74a9fbaa1 (diff)
downloadlibproxy-git-8aed359ca37c0fbdc020b144428222bffa7de4ac.tar.gz
Add initial libproxy test (#75)
-rw-r--r--src/libproxy/meson.build28
-rw-r--r--src/libproxy/proxy.c8
-rw-r--r--tests/libproxy-test.c71
-rw-r--r--tests/meson.build10
4 files changed, 106 insertions, 11 deletions
diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build
index 873b184..ce50e85 100644
--- a/src/libproxy/meson.build
+++ b/src/libproxy/meson.build
@@ -2,15 +2,18 @@ libproxy_inc = include_directories('.')
libproxy_sources = []
-if build_dbus
-libproxy_sources += [
+libproxy_dbus_sources = [
'proxy-dbus.c',
]
-else
-libproxy_sources += [
+libproxy_non_dbus_sources = [
'proxy.c',
]
+
+if build_dbus
+ libproxy_sources += libproxy_dbus_sources
+else
+ libproxy_sources += libproxy_non_dbus_sources
endif
libproxy_headers = [
@@ -45,6 +48,23 @@ libproxy_dep = declare_dependency (
dependencies: libproxy_deps
)
+libproxy_test = shared_library(
+ 'proxy_test',
+ libproxy_non_dbus_sources,
+ include_directories: px_backend_inc,
+ dependencies: libproxy_deps,
+ link_args : vflag,
+ link_depends : mapfile,
+ soversion: '1',
+ install: false,
+)
+
+libproxy_test_dep = declare_dependency (
+ include_directories: libproxy_inc,
+ link_with: libproxy_test,
+ dependencies: libproxy_deps
+)
+
install_headers(libproxy_headers, subdir: 'libproxy')
pkg = import('pkgconfig')
diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c
index 5c910a1..6a60d6b 100644
--- a/src/libproxy/proxy.c
+++ b/src/libproxy/proxy.c
@@ -31,7 +31,6 @@
struct _pxProxyFactory {
PxManager *manager;
- GCancellable *cancellable;
};
pxProxyFactory *px_proxy_factory_copy (pxProxyFactory *self);
@@ -52,7 +51,6 @@ px_proxy_factory_new (void)
{
pxProxyFactory *self = g_new0 (pxProxyFactory, 1);
- self->cancellable = g_cancellable_new ();
self->manager = px_manager_new ();
return self;
@@ -72,10 +70,8 @@ px_proxy_factory_get_proxies (pxProxyFactory *self,
g_autoptr (GError) error = NULL;
result = px_manager_get_proxies_sync (self->manager, url, &error);
- if (!result) {
+ if (error)
g_warning ("Could not query proxy: %s", error ? error->message : "");
- return NULL;
- }
return g_steal_pointer (&result);
}
@@ -95,8 +91,6 @@ px_proxy_factory_free_proxies (char **proxies)
void
px_proxy_factory_free (pxProxyFactory *self)
{
- g_cancellable_cancel (self->cancellable);
- g_clear_object (&self->cancellable);
g_clear_object (&self->manager);
g_clear_pointer (&self, g_free);
}
diff --git a/tests/libproxy-test.c b/tests/libproxy-test.c
new file mode 100644
index 0000000..05e05b3
--- /dev/null
+++ b/tests/libproxy-test.c
@@ -0,0 +1,71 @@
+/* libproxy-test.c
+ *
+ * Copyright 2023 The Libproxy Team
+ *
+ * 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
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "proxy.h"
+
+#include <gio/gio.h>
+
+typedef struct {
+ pxProxyFactory *pf;
+} Fixture;
+
+static void
+fixture_setup (Fixture *self,
+ gconstpointer data)
+{
+ self->pf = px_proxy_factory_new ();
+}
+
+static void
+fixture_teardown (Fixture *fixture,
+ gconstpointer data)
+{
+ px_proxy_factory_free (fixture->pf);
+}
+
+static void
+test_libproxy_setup (Fixture *self,
+ const void *user_data)
+{
+ char **proxies = NULL;
+
+ proxies = px_proxy_factory_get_proxies (self->pf, "https://www.example.com");
+ g_assert_nonnull (proxies);
+ g_assert_nonnull (proxies[0]);
+ px_proxy_factory_free_proxies (proxies);
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Could not query proxy: URI is not absolute, and no base URI was provided");
+ proxies = px_proxy_factory_get_proxies (self->pf, "http_unknown://www.example.com");
+ g_assert_nonnull (proxies);
+ g_assert_nonnull (proxies[0]);
+ px_proxy_factory_free_proxies (proxies);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/libproxy/setup", Fixture, NULL, fixture_setup, test_libproxy_setup, fixture_teardown);
+
+ return g_test_run ();
+}
diff --git a/tests/meson.build b/tests/meson.build
index 23a7e91..3fa6e5a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -7,6 +7,16 @@ if get_option('tests')
test_cargs = ['-UG_DISABLE_ASSERT']
+ libproxy_test = executable('test-libproxy',
+ ['libproxy-test.c'],
+ include_directories: libproxy_inc,
+ dependencies: [libproxy_test_dep],
+ )
+ test('Libproxy test',
+ libproxy_test,
+ env: envs
+ )
+
if soup_dep.found()
px_manager_test = executable('test-px-manager',
['px-manager-test.c', 'px-manager-helper.c'],