Commit e57bae59 authored by Niels Möller's avatar Niels Möller

* src/testsuite/utf8-test.c: New test program.

* src/testsuite/Makefile.am (TS_PROGS): Added utf8-test.
* src/testsuite/UTF-8-test.txt: Markus Kuhn's utf8 testfile.

Rev: src/testsuite/.cvsignore:1.21
Rev: src/testsuite/Makefile.am:1.72
Rev: src/testsuite/UTF-8-test.txt:1.1
Rev: src/testsuite/utf8-test.c:1.1
parent 7680f802
[attr]binary -text -crlf -diff -ident
* text ident
*.pdu binary
/src/testsuite/UTF-8-test.txt binary
LICENSE eol=crlf
/src/testsuite/rapid7-ssh-pdu/README eol=crlf
......@@ -28,4 +28,5 @@ temphome
test.out1
test.out2
twofish-test
utf8-test
yarrow-seed-file
......@@ -28,4 +28,5 @@
/test.out1
/test.out2
/twofish-test
/utf8-test
/yarrow-seed-file
......@@ -9,7 +9,8 @@ TS_PROGS = arcfour-test aes-test blowfish-test cast128-test \
des-test \
serpent-test twofish-test \
md5-test sha1-test rsa-test dsa-test spki-tag-test \
string-test parse-config-test sockaddr2info-test
string-test parse-config-test sockaddr2info-test \
utf8-test
TS_SH = conv-1-test conv-2-test conv-3-test \
export-1-test keygen-1-test keygen-2-test \
......
#include "testutils.h"
#include "charset.h"
/* Uses Markus Kuhn's test file as input. Originally at
http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt. */
#define VERBOSE 0
static FILE *
open_input(void)
{
FILE *f;
char *fname;
const char *srcdir = getenv("srcdir");
if (!srcdir)
{
fprintf(stderr, "$srcdir not set in the environment.\n");
FAIL();
}
fname = alloca(strlen(srcdir) + 25);
sprintf(fname, "%s/%s", srcdir, "UTF-8-test.txt");
f = fopen(fname, "rb");
if (!f)
{
fprintf(stderr, "Could not open %s.\n", fname);
FAIL();
}
return f;
}
static int
get_line(FILE *f, uint32_t size, char *buffer)
{
uint32_t length;
if (!fgets(buffer, size, f))
{
return -1;
}
length = strlen(buffer);
if (length > 0 && buffer[length - 1] == '\n')
buffer[--length] = 0;
return length;
}
#define LINE_LENGTH 79
int
test_main(void)
{
FILE *f = open_input();
char buffer[200];
struct lsh_string *s;
int length;
int lineno = 0;
/* This test doesn't really check that the decoder works right, it only
checks that it doesn't crash. */
while ( (length = get_line(f, sizeof(buffer), buffer)) >= 0)
{
static const int charsets[] =
{ CHARSET_UTF8, CHARSET_LATIN1, CHARSET_USASCII, -1 };
static const int flags[] =
{
0, utf8_tolerant | utf8_replace, utf8_replace, utf8_paranoid,
utf8_paranoid | utf8_replace, -1
};
int i, j;
/* Skip description lines */
if (length < LINE_LENGTH)
continue;
lineno++;
for (i = 0; charsets[i] >= 0; i++)
{
set_local_charset(charsets[i]);
for (j = 0; flags[j] >= 0; j++)
{
s = low_utf8_to_local(length, buffer, flags[j]);
#if VERBOSE
if (!s)
fprintf(stderr, "!%s\n", buffer);
else
fprintf(stderr, " %s\n", lsh_string_data(s));
#endif
if (flags[j] == (utf8_tolerant | utf8_replace) && !s)
{
fprintf(stderr, "utf8_to_local failed on line %d:\n"
"`%s'", lineno, buffer);
FAIL();
}
if (flags[j] == (utf8_replace | utf8_tolerant)
&& charsets[i] != CHARSET_UTF8
&& (!s || lsh_string_length(s) != LINE_LENGTH))
{
fprintf(stderr, "Bad chracter count from utf8_to_local, line %d:\n"
"in: %s\n"
"out: %s\n", lineno, buffer, lsh_string_data(s));
FAIL();
}
lsh_string_free(s);
}
}
}
if (ferror(f))
FAIL();
fclose(f);
SUCCESS();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment