File: test-urlmatch-normalization.c

package info (click to toggle)
cgit 0.10.2.git2.0.1-3%2Bdeb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 26,640 kB
  • ctags: 19,675
  • sloc: ansic: 159,238; sh: 129,259; perl: 29,890; tcl: 21,214; python: 5,362; makefile: 3,295; lisp: 1,786; php: 120; asm: 98; csh: 45
file content (50 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (6)
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
#include "git-compat-util.h"
#include "urlmatch.h"

int main(int argc, char **argv)
{
	const char usage[] = "test-urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
	char *url1, *url2;
	int opt_p = 0, opt_l = 0;

	/*
	 * For one url, succeed if url_normalize succeeds on it, fail otherwise.
	 * For two urls, succeed only if url_normalize succeeds on both and
	 * the results compare equal with strcmp.  If -p is given (one url only)
	 * and url_normalize succeeds, print the result followed by "\n".  If
	 * -l is given (one url only) and url_normalize succeeds, print the
	 * returned length in decimal followed by "\n".
	 */

	if (argc > 1 && !strcmp(argv[1], "-p")) {
		opt_p = 1;
		argc--;
		argv++;
	} else if (argc > 1 && !strcmp(argv[1], "-l")) {
		opt_l = 1;
		argc--;
		argv++;
	}

	if (argc < 2 || argc > 3)
		die("%s", usage);

	if (argc == 2) {
		struct url_info info;
		url1 = url_normalize(argv[1], &info);
		if (!url1)
			return 1;
		if (opt_p)
			printf("%s\n", url1);
		if (opt_l)
			printf("%u\n", (unsigned)info.url_len);
		return 0;
	}

	if (opt_p || opt_l)
		die("%s", usage);

	url1 = url_normalize(argv[1], NULL);
	url2 = url_normalize(argv[2], NULL);
	return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
}