mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Change protocol/test to use the shell-based test infrastructure
This commit is contained in:
parent
49c637661d
commit
ee83dca303
2
src/protocol/test/.gitignore
vendored
2
src/protocol/test/.gitignore
vendored
@ -1 +1 @@
|
||||
test_uri
|
||||
uri-parser
|
||||
|
@ -2,7 +2,7 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
TEST_PROGS = \
|
||||
test_uri
|
||||
uri-test
|
||||
|
||||
TESTDEPS = \
|
||||
$(top_builddir)/src/protocol/protocol.o \
|
||||
@ -11,6 +11,6 @@ TESTDEPS = \
|
||||
|
||||
CLEAN = stub.o
|
||||
|
||||
test_uri:: stub.o
|
||||
uri-test:: stub.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -1,6 +0,0 @@
|
||||
#ifndef EL__PROTOCOL_TEST_HARNESS_H
|
||||
#define EL__PROTOCOL_TEST_HARNESS_H
|
||||
|
||||
void test_failed();
|
||||
|
||||
#endif
|
@ -2,11 +2,15 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "bfu/msgbox.h"
|
||||
#include "main/module.h"
|
||||
#include "protocol/test/harness.h"
|
||||
#include "protocol/user.h"
|
||||
#include "session/session.h"
|
||||
|
||||
@ -34,11 +38,25 @@ STUB_MODULE(smb_protocol_module);
|
||||
STUB_MODULE(uri_rewrite_module);
|
||||
STUB_MODULE(user_protocol_module);
|
||||
|
||||
static void
|
||||
die(const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (msg) {
|
||||
va_start(args, msg);
|
||||
vfprintf(stderr, msg, args);
|
||||
fputs("\n", stderr);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
exit(!!NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
stub_called(const unsigned char *fun)
|
||||
{
|
||||
fprintf(stderr, "FAIL: stub %s\n", fun);
|
||||
test_failed();
|
||||
die("FAIL: stub %s\n", fun);
|
||||
}
|
||||
|
||||
#define STUB_PROTOCOL_HANDLER(name) \
|
||||
|
98
src/protocol/test/test-normalize-uri
Executable file
98
src/protocol/test/test-normalize-uri
Executable file
@ -0,0 +1,98 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
|
||||
test_description='Test URI normalizing'
|
||||
|
||||
. "$TEST_LIB"
|
||||
|
||||
test_uri_equals () {
|
||||
before="$1"; shift
|
||||
expected="$1"; shift
|
||||
normalized="$(uri-test "$before")"
|
||||
|
||||
test_expect_success "Normalize $before" "test \"$normalized\" = \"$expected\""
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar/baz?a=1&b=2#frag" \
|
||||
"http://example.org/foo/bar/baz?a=1&b=2#frag"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar/../?a=1&b=2#frag" \
|
||||
"http://example.org/foo/?a=1&b=2#frag"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar/../../baz?a=1&b=2#frag" \
|
||||
"http://example.org/baz?a=1&b=2#frag"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar/.." \
|
||||
"http://example.org/foo/"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar;a=1/.." \
|
||||
"http://example.org/foo/"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar.." \
|
||||
"http://example.org/foo/bar.."
|
||||
|
||||
# Bug 744 - ELinks changes "//" to "/" in path component of URI
|
||||
test_uri_equals "http://example.org/foo/bar/baz" \
|
||||
"http://example.org/foo/bar/baz"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar/" \
|
||||
"http://example.org/foo/bar/"
|
||||
|
||||
test_uri_equals "http://example.org/foo//baz" \
|
||||
"http://example.org/foo//baz"
|
||||
|
||||
test_uri_equals "http://example.org/foo//" \
|
||||
"http://example.org/foo//"
|
||||
|
||||
test_uri_equals "http://example.org//bar/baz" \
|
||||
"http://example.org//bar/baz"
|
||||
|
||||
test_uri_equals "http://example.org//bar/" \
|
||||
"http://example.org//bar/"
|
||||
|
||||
test_uri_equals "http://example.org///baz" \
|
||||
"http://example.org///baz"
|
||||
|
||||
test_uri_equals "http://example.org///" \
|
||||
"http://example.org///"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar/baz/.." \
|
||||
"http://example.org/foo/bar/"
|
||||
|
||||
test_uri_equals "http://example.org/foo/bar//.." \
|
||||
"http://example.org/foo/bar/"
|
||||
|
||||
test_uri_equals "http://example.org/foo//baz/.." \
|
||||
"http://example.org/foo//"
|
||||
|
||||
test_uri_equals "http://example.org/foo///.." \
|
||||
"http://example.org/foo//"
|
||||
|
||||
test_uri_equals "http://example.org//bar/baz/.." \
|
||||
"http://example.org//bar/"
|
||||
|
||||
test_uri_equals "http://example.org//bar//.." \
|
||||
"http://example.org//bar/"
|
||||
|
||||
test_uri_equals "http://example.org///baz/.." \
|
||||
"http://example.org///"
|
||||
|
||||
test_uri_equals "http://example.org////.." \
|
||||
"http://example.org///"
|
||||
|
||||
test_uri_equals "http://example.org/foo/..//bar/baz" \
|
||||
"http://example.org//bar/baz"
|
||||
|
||||
test_uri_equals "http://example.org//.//foo" \
|
||||
"http://example.org///foo"
|
||||
|
||||
test_uri_equals "http://example.org//./../foo" \
|
||||
"http://example.org/foo"
|
||||
|
||||
test_uri_equals "http://example.org/gag///./../.." \
|
||||
"http://example.org/gag/"
|
||||
|
||||
test_done
|
@ -1,2 +0,0 @@
|
||||
#! /bin/sh -e
|
||||
./test_uri
|
@ -1,142 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "protocol/test/harness.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "util/string.h"
|
||||
|
||||
static int failures = 0;
|
||||
static int successes = 0;
|
||||
|
||||
void
|
||||
test_failed(void)
|
||||
{
|
||||
++failures;
|
||||
}
|
||||
|
||||
void
|
||||
test_succeeded(void)
|
||||
{
|
||||
++successes;
|
||||
}
|
||||
|
||||
static void
|
||||
test_1_normalize_uri(const unsigned char *orig, const unsigned char *good)
|
||||
{
|
||||
struct string s;
|
||||
unsigned char *norm;
|
||||
|
||||
if (!init_string(&s)) {
|
||||
fputs("FAIL: init_string\n", stderr);
|
||||
test_failed();
|
||||
goto out;
|
||||
}
|
||||
if (!add_to_string(&s, orig)) {
|
||||
fputs("FAIL: add_to_string\n", stderr);
|
||||
test_failed();
|
||||
goto out;
|
||||
}
|
||||
|
||||
norm = normalize_uri(NULL, s.source);
|
||||
if (norm == NULL) {
|
||||
fprintf(stderr, "FAIL: normalize_uri NULL %s\n", orig);
|
||||
test_failed();
|
||||
goto out;
|
||||
}
|
||||
if (strcmp(norm, good) != 0) {
|
||||
fprintf(stderr, "FAIL: normalize_uri mismatch:\n"
|
||||
"\toriginal: %s\n"
|
||||
"\tresult: %s\n"
|
||||
"\texpected: %s\n",
|
||||
orig, norm, good);
|
||||
test_failed();
|
||||
goto out;
|
||||
}
|
||||
|
||||
test_succeeded();
|
||||
|
||||
out:
|
||||
done_string(&s);
|
||||
}
|
||||
|
||||
static void
|
||||
test_normalize_uri(void)
|
||||
{
|
||||
static const struct {
|
||||
unsigned char *orig;
|
||||
unsigned char *norm;
|
||||
} tests[] = {
|
||||
{ "http://example.org/foo/bar/baz?a=1&b=2#frag",
|
||||
"http://example.org/foo/bar/baz?a=1&b=2#frag" },
|
||||
{ "http://example.org/foo/bar/../?a=1&b=2#frag",
|
||||
"http://example.org/foo/?a=1&b=2#frag" },
|
||||
{ "http://example.org/foo/bar/../../baz?a=1&b=2#frag",
|
||||
"http://example.org/baz?a=1&b=2#frag" },
|
||||
{ "http://example.org/foo/bar/..",
|
||||
"http://example.org/foo/" },
|
||||
{ "http://example.org/foo/bar;a=1/..",
|
||||
"http://example.org/foo/" },
|
||||
{ "http://example.org/foo/bar..",
|
||||
"http://example.org/foo/bar.." },
|
||||
|
||||
/* Bug 744 - ELinks changes "//" to "/" in path
|
||||
* component of URI */
|
||||
{ "http://example.org/foo/bar/baz",
|
||||
"http://example.org/foo/bar/baz" },
|
||||
{ "http://example.org/foo/bar/",
|
||||
"http://example.org/foo/bar/" },
|
||||
{ "http://example.org/foo//baz",
|
||||
"http://example.org/foo//baz" },
|
||||
{ "http://example.org/foo//",
|
||||
"http://example.org/foo//" },
|
||||
{ "http://example.org//bar/baz",
|
||||
"http://example.org//bar/baz" },
|
||||
{ "http://example.org//bar/",
|
||||
"http://example.org//bar/" },
|
||||
{ "http://example.org///baz",
|
||||
"http://example.org///baz" },
|
||||
{ "http://example.org///",
|
||||
"http://example.org///" },
|
||||
{ "http://example.org/foo/bar/baz/..",
|
||||
"http://example.org/foo/bar/" },
|
||||
{ "http://example.org/foo/bar//..",
|
||||
"http://example.org/foo/bar/" },
|
||||
{ "http://example.org/foo//baz/..",
|
||||
"http://example.org/foo//" },
|
||||
{ "http://example.org/foo///..",
|
||||
"http://example.org/foo//" },
|
||||
{ "http://example.org//bar/baz/..",
|
||||
"http://example.org//bar/" },
|
||||
{ "http://example.org//bar//..",
|
||||
"http://example.org//bar/" },
|
||||
{ "http://example.org///baz/..",
|
||||
"http://example.org///" },
|
||||
{ "http://example.org////..",
|
||||
"http://example.org///" },
|
||||
{ "http://example.org/foo/..//bar/baz",
|
||||
"http://example.org//bar/baz" },
|
||||
{ "http://example.org//.//foo",
|
||||
"http://example.org///foo" },
|
||||
{ "http://example.org//./../foo",
|
||||
"http://example.org/foo" },
|
||||
{ "http://example.org/gag///./../..",
|
||||
"http://example.org/gag/" },
|
||||
};
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof_array(tests); ++i)
|
||||
test_1_normalize_uri(tests[i].orig, tests[i].norm);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
test_normalize_uri();
|
||||
printf("Total %d failures, %d successes.\n", failures, successes);
|
||||
return failures ? EXIT_FAILURE : 0;
|
||||
}
|
21
src/protocol/test/uri-test.c
Normal file
21
src/protocol/test/uri-test.c
Normal file
@ -0,0 +1,21 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "protocol/uri.h"
|
||||
#include "util/string.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
/* FIXME: As more protocol tests are added this could start
|
||||
* taking arguments like --normalize-uri=<arg> etc. */
|
||||
if (argc == 2) {
|
||||
fprintf(stdout, "%s\n", normalize_uri(NULL, argv[1]));
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user