File: libproxy.c

package info (click to toggle)
glib-networking 2.50.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,132 kB
  • sloc: ansic: 12,323; sh: 5,186; makefile: 248; sed: 16
file content (94 lines) | stat: -rw-r--r-- 2,707 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* GLibProxyResolver tests
 *
 * Copyright 2011-2013 Red Hat, 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, see
 * <http://www.gnu.org/licenses/>.
 */

#include <gio/gio.h>

#include "common.c"

static void
reset_proxy_settings (gpointer      fixture,
		      gconstpointer user_data)
{
  g_unsetenv ("http_proxy");
  g_unsetenv ("HTTP_PROXY");
  g_unsetenv ("https_proxy");
  g_unsetenv ("HTTPS_PROXY");
  g_unsetenv ("ftp_proxy");
  g_unsetenv ("FTP_PROXY");
  g_unsetenv ("no_proxy");
  g_unsetenv ("NO_PROXY");
}

static void
test_proxy_uri (gpointer      fixture,
		gconstpointer user_data)
{
  g_setenv ("http_proxy", "http://proxy.example.com:8080", TRUE);
  g_setenv ("https_proxy", "http://proxy-s.example.com:7070", TRUE);
  g_setenv ("ftp_proxy", "ftp://proxy-f.example.com:6060", TRUE);

  test_proxy_uri_common ();
}

static void
test_proxy_socks (gpointer      fixture,
		  gconstpointer user_data)
{
  g_setenv ("http_proxy", "socks://proxy.example.com:1234", TRUE);
  g_setenv ("no_proxy", "127.0.0.1", TRUE);

  test_proxy_socks_common ();
}

static void
test_proxy_ignore (gpointer      fixture,
		   gconstpointer user_data)
{
  gchar *no_proxy = g_strjoinv (",", (gchar **) ignore_hosts);

  g_setenv ("http_proxy", "http://localhost:8080", TRUE);
  g_setenv ("no_proxy", no_proxy, TRUE);
  g_free (no_proxy);

  test_proxy_ignore_common (TRUE);
}

int
main (int   argc,
      char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  /* Unset variables that would make libproxy try to use gconf or ksettings */
  g_unsetenv ("GNOME_DESKTOP_SESSION_ID");
  g_unsetenv ("DESKTOP_SESSION");
  g_unsetenv ("KDE_FULL_SESSION");

  /* Use the just-built libproxy module */
  g_setenv ("GIO_EXTRA_MODULES", TOP_BUILDDIR "/proxy/libproxy/.libs", TRUE);

  g_test_add_vtable ("/proxy/libproxy/uri", 0, NULL,
		     reset_proxy_settings, test_proxy_uri, NULL);
  g_test_add_vtable ("/proxy/libproxy/socks", 0, NULL,
		     reset_proxy_settings, test_proxy_socks, NULL);
  g_test_add_vtable ("/proxy/libproxy/ignore", 0, NULL,
		     reset_proxy_settings, test_proxy_ignore, NULL);

  return g_test_run();
}