summaryrefslogtreecommitdiff
path: root/client/test-uri-utils.c
blob: 4f7e53d6c1b205f7144ad737ef3972391856acf7 (plain)
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

#include <string.h>

#include "gvfsuriutils.h"


typedef struct {
	const char *uri;
	const char *expected_host;
	guint expected_port;
} TestURIs;

static TestURIs uris[] = {
	{ "https://[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:443/", "[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]", 443 },
	{ "http://test:443/", "test", 443 },
	{ "http://test/", "test", -1 },
	{ "http://windows-host:8080/C:/", "windows-host", 8080 },
	{ "smb://user:password@192.192.192.192/foobar", "192.192.192.192", -1 },
	{ "https://d134w4tst3t.s3.amazonaws.com/a?Signature=6VJ9%2BAdPVZ4Z7NnPShRvtDsLofc%3D&Expires=1249330377&AWSAccessKeyId=0EYZF4DV8A7WM0H73602", "d134w4tst3t.s3.amazonaws.com", -1 },
	{ "dav+sd://foo%3Abar._webdav._tcp.local/", "foo:bar._webdav._tcp.local", -1 },
};

int main (int argc, char **argv)
{
	guint i;

	for (i = 0; i < G_N_ELEMENTS (uris); i++) {
		GDecodedUri *decoded;
		char *encoded;

		decoded = g_vfs_decode_uri (uris[i].uri);
		if (decoded == NULL) {
			g_warning ("Failed to parse \"%s\"", uris[i].uri);
			return 1;
		}
		if (decoded->host == NULL || strcmp (decoded->host, uris[i].expected_host) != 0) {
			g_warning ("Wrong host for \"%s\" (got '%s', expected '%s')", uris[i].uri, decoded->host, uris[i].expected_host);
			g_vfs_decoded_uri_free (decoded);
			return 1;
		}
		if (decoded->port != uris[i].expected_port) {
			g_warning ("Wrong port for \"%s\"", uris[i].uri);
			g_vfs_decoded_uri_free (decoded);
			return 1;
		}
		encoded = g_vfs_encode_uri (decoded, TRUE);
		if (encoded == NULL || strcmp (encoded, uris[i].uri) != 0) {
			g_warning ("Failed to re-encode \"%s\" from '%s'", uris[i].uri, encoded);
			g_vfs_decoded_uri_free (decoded);
			g_free (encoded);
			return 1;
		}
		g_free (encoded);
		g_vfs_decoded_uri_free (decoded);
	}

	return 0;
}