1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-25 01:05:37 +00:00

Change protocol/test to use the shell-based test infrastructure

This commit is contained in:
Jonas Fonseca 2007-08-10 13:30:28 +02:00
parent b3ca6a9e1f
commit 5f18156708
8 changed files with 143 additions and 156 deletions

View File

@ -1 +1 @@
test_uri
uri-parser

View File

@ -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

View File

@ -1,6 +0,0 @@
#ifndef EL__PROTOCOL_TEST_HARNESS_H
#define EL__PROTOCOL_TEST_HARNESS_H
void test_failed();
#endif

View File

@ -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) \

View 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

View File

@ -1,2 +0,0 @@
#! /bin/sh -e
./test_uri

View File

@ -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;
}

View 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;
}