ksgi

Форк
0
/
test-urlencode-deprecated.c 
77 строк · 2.1 Кб
1
/*	$Id$ */
2
/*
3
 * Copyright (c) 2018 Kristaps Dzonsons <kristaps@bsd.lv>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
#include "../config.h"
18

19
#if HAVE_ERR
20
# include <err.h>
21
#endif
22

23
#include <stdarg.h>
24
#include <stdint.h>
25
#include <stdlib.h>
26
#include <string.h>
27
#include <time.h>
28
#include <unistd.h>
29

30
#include "../kcgi.h"
31

32
struct	test {
33
	const char	*input;
34
	const char	*output;
35
};
36

37
static	const struct test tests[] = {
38
	{ "", "" },
39
	{ "foobar", "foobar" },
40
	{ "foo bar", "foo+bar" },
41
	{ "foo~bar", "foo~bar" },
42
	{ "foo-bar", "foo-bar" },
43
	{ "foo_bar", "foo_bar" },
44
	{ "foo.bar", "foo.bar" },
45
	{ "foo.bar.", "foo.bar." },
46
	{ "foo.bar.-", "foo.bar.-" },
47
	{ "-_foo.bar.-", "-_foo.bar.-" },
48
	{ "-_foo+bar.-", "-_foo%2Bbar.-" },
49
	{ "-_foo\tbar.-", "-_foo%09bar.-" },
50
	{ "\t-_foo\tbar.-", "%09-_foo%09bar.-" },
51
	{ "\t-_foo\tbar.-\t", "%09-_foo%09bar.-%09" },
52
	{ "\t-_foo%\tbar.-\t", "%09-_foo%25%09bar.-%09" },
53
	{ "-_foo%09}bar.-", "-_foo%2509%7Dbar.-" },
54
	{ "\t\t\t\t", "%09%09%09%09" },
55
	{ NULL, NULL }
56
};
57

58
int
59
main(int argc, char *argv[])
60
{
61
	const struct test 	*t;
62
	char			*url;
63

64
	if (kutil_urlencode(NULL) != NULL)
65
		errx(EXIT_FAILURE, "kutil_urlencode should fail");
66

67
	for (t = tests; t->input != NULL; t++) {
68
		if ((url = kutil_urlencode(t->input)) == NULL)
69
			err(EXIT_FAILURE, "kutil_urlencode");
70
		if (strcmp(url, t->output))
71
			errx(EXIT_FAILURE, "%s: fail (have %s, "
72
				"want %s)", t->input, url, t->output);
73
		free(url);
74
	}
75

76
	return EXIT_SUCCESS;
77
}
78

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.