1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

Bug 744: Add tests. There are four failures.

This commit is contained in:
Kalle Olavi Niemitalo 2007-07-19 13:46:47 +03:00 committed by Kalle Olavi Niemitalo
parent 4f0aaa166e
commit 273ae1ff6d
6 changed files with 243 additions and 1 deletions

View File

@ -10,7 +10,7 @@ SUBDIRS-$(CONFIG_NNTP) += nntp
SUBDIRS-$(CONFIG_SMB) += smb
SUBDIRS-$(CONFIG_URI_REWRITE) += rewrite
SUBDIRS = auth file http
SUBDIRS = auth file http test
OBJS-$(CONFIG_DATA) += data.o

View File

@ -0,0 +1,14 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
TEST_PROGS = \
test_uri
TESTDEPS = \
$(top_builddir)/src/protocol/protocol.o \
$(top_builddir)/src/protocol/uri.o \
stub.o
test_uri:: stub.o
include $(top_srcdir)/Makefile.lib

View File

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

88
src/protocol/test/stub.c Normal file
View File

@ -0,0 +1,88 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "elinks.h"
#include "bfu/msgbox.h" /* msg_text, msg_box */
#include "main/module.h"
#include "protocol/test/harness.h"
#include "protocol/user.h" /* get_user_program */
#include "session/session.h" /* print_error_dialog */
#define STUB_MODULE(name) \
struct module name = struct_module( \
/* name: */ "Stub " #name, \
/* options: */ NULL, \
/* hooks: */ NULL, \
/* submodules: */ NULL, \
/* data: */ NULL, \
/* init: */ NULL, \
/* done: */ NULL \
)
STUB_MODULE(auth_module);
STUB_MODULE(cgi_protocol_module);
STUB_MODULE(file_protocol_module);
STUB_MODULE(fsp_protocol_module);
STUB_MODULE(ftp_protocol_module);
STUB_MODULE(http_protocol_module);
STUB_MODULE(smb_protocol_module);
STUB_MODULE(uri_rewrite_module);
STUB_MODULE(user_protocol_module);
static void
stub_called(const unsigned char *fun)
{
fprintf(stderr, "FAIL: stub %s\n", fun);
test_failed();
}
#define STUB_PROTOCOL_HANDLER(name) \
void \
name(struct session *ses, struct uri *uri) \
{ \
stub_called(#name); \
}
STUB_PROTOCOL_HANDLER(about_protocol_handler)
STUB_PROTOCOL_HANDLER(data_protocol_handler)
STUB_PROTOCOL_HANDLER(ecmascript_protocol_handler)
STUB_PROTOCOL_HANDLER(file_protocol_handler)
STUB_PROTOCOL_HANDLER(fsp_protocol_handler)
STUB_PROTOCOL_HANDLER(ftp_protocol_handler)
STUB_PROTOCOL_HANDLER(http_protocol_handler)
STUB_PROTOCOL_HANDLER(proxy_protocol_handler)
STUB_PROTOCOL_HANDLER(smb_protocol_handler)
STUB_PROTOCOL_HANDLER(user_protocol_handler)
unsigned char *
get_user_program(struct terminal *term, unsigned char *progid, int progidlen)
{
stub_called("get_user_program");
return NULL;
}
void
print_error_dialog(struct session *ses, enum connection_state state,
struct uri *uri, enum connection_priority priority)
{
stub_called("print_error_dialog");
}
unsigned char *
msg_text(struct terminal *term, unsigned char *format, ...)
{
stub_called("msg_text");
return NULL;
}
struct dialog_data *
msg_box(struct terminal *term, struct memory_list *mem_list,
enum msgbox_flags flags, unsigned char *title, enum format_align align,
unsigned char *text, void *udata, int buttons, ...)
{
/* mem_list should be freed here but because this is just a
* test program it won't matter. */
stub_called("msg_box");
return NULL;
}

View File

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

View File

@ -0,0 +1,132 @@
#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/" },
/* 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" },
};
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;
}