From: Richard Kettlewell Date: Sun, 9 Dec 2007 18:55:04 +0000 (+0000) Subject: more testing X-Git-Tag: 1.5.99+dev10~7 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/d6ea854ab50aedf15bda9ad18f46ca80b50582a8 more testing --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 67416b2..ab856a7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -65,7 +65,6 @@ libdisorder_a_SOURCES=charset.c charset.h \ user.h user.c \ unicode.h unicode.c \ unidata.h unidata.c \ - utf8.h utf8.c \ vacopy.h \ vector.c vector.h \ wav.h wav.c \ diff --git a/lib/addr.c b/lib/addr.c index 0b5b783..8288e4e 100644 --- a/lib/addr.c +++ b/lib/addr.c @@ -17,7 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ -/** @file lib/addr.c Socket address support */ +/** @file lib/addr.c + * @brief Socket address support */ #include #include "types.h" diff --git a/lib/addr.h b/lib/addr.h index fb1dd7f..8bd703f 100644 --- a/lib/addr.h +++ b/lib/addr.h @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2004 Richard Kettlewell + * Copyright (C) 2004, 2007 Richard Kettlewell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ +/** @file lib/addr.h + * @brief Socket address support */ #ifndef ADDR_H #define ADDR_H diff --git a/lib/test.c b/lib/test.c index e8e550f..5028054 100644 --- a/lib/test.c +++ b/lib/test.c @@ -34,8 +34,10 @@ #include #include #include +#include +#include +#include -#include "utf8.h" #include "mem.h" #include "log.h" #include "vector.h" @@ -57,6 +59,8 @@ #include "printf.h" #include "basen.h" #include "split.h" +#include "configuration.h" +#include "addr.h" static int tests, errors; static int fail_first; @@ -1279,6 +1283,55 @@ static void test_hash(void) { check_integer(hash_count(h), 0); } +static void test_addr(void) { + struct stringlist a; + const char *s[2]; + struct addrinfo *ai; + char *name; + const struct sockaddr_in *sin; + + static const struct addrinfo pref = { + AI_PASSIVE, + PF_INET, + SOCK_STREAM, + 0, + 0, + 0, + 0, + 0 + }; + + a.n = 1; + a.s = (char **)s; + s[0] = "smtp"; + ai = get_address(&a, &pref, &name); + insist(ai != 0); + check_integer(ai->ai_family, PF_INET); + check_integer(ai->ai_socktype, SOCK_STREAM); + check_integer(ai->ai_protocol, IPPROTO_TCP); + check_integer(ai->ai_addrlen, sizeof(struct sockaddr_in)); + sin = (const struct sockaddr_in *)ai->ai_addr; + check_integer(sin->sin_family, AF_INET); + check_integer(sin->sin_addr.s_addr, 0); + check_integer(ntohs(sin->sin_port), 25); + check_string(name, "host * service smtp"); + + a.n = 2; + s[0] = "localhost"; + s[1] = "nntp"; + ai = get_address(&a, &pref, &name); + insist(ai != 0); + check_integer(ai->ai_family, PF_INET); + check_integer(ai->ai_socktype, SOCK_STREAM); + check_integer(ai->ai_protocol, IPPROTO_TCP); + check_integer(ai->ai_addrlen, sizeof(struct sockaddr_in)); + sin = (const struct sockaddr_in *)ai->ai_addr; + check_integer(sin->sin_family, AF_INET); + check_integer(ntohl(sin->sin_addr.s_addr), 0x7F000001); + check_integer(ntohs(sin->sin_port), 119); + check_string(name, "host localhost service nntp"); +} + int main(void) { mem_init(); fail_first = !!getenv("FAIL_FIRST"); @@ -1292,6 +1345,7 @@ int main(void) { insist('a' == 0x61); insist('z' == 0x7A); /* addr.c */ + test_addr(); /* asprintf.c */ /* authhash.c */ /* basen.c */ diff --git a/lib/utf8.c b/lib/utf8.c deleted file mode 100644 index 9ca228c..0000000 --- a/lib/utf8.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of DisOrder - * Copyright (C) 2005 Richard Kettlewell - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include -#include "types.h" - -#include "utf8.h" - -/* -Local Variables: -c-basic-offset:2 -comment-column:40 -fill-column:79 -End: -*/ diff --git a/lib/utf8.h b/lib/utf8.h deleted file mode 100644 index 683a8a9..0000000 --- a/lib/utf8.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of DisOrder - * Copyright (C) 2004, 2005 Richard Kettlewell - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef UTF8_H -#define UTF8_H - -#define PARSE_UTF8(S,C,E) do { \ - if((unsigned char)*S < 0x80) \ - C = *S++; \ - else if((unsigned char)*S <= 0xDF) { \ - C = (*S++ & 0x1F) << 6; \ - if((*S & 0xC0) != 0x80) { E; } \ - C |= (*S++ & 0x3F); \ - if(C < 0x80) { E; } \ - } else if((unsigned char)*S <= 0xEF) { \ - C = (*S++ & 0x0F) << 12; \ - if((*S & 0xC0) != 0x80) { E; } \ - C |= (*S++ & 0x3F) << 6; \ - if((*S & 0xC0) != 0x80) { E; } \ - C |= (*S++ & 0x3F); \ - if(C < 0x800 \ - || (C >= 0xD800 && C <= 0xDFFF)) { \ - E; \ - } \ - } else if((unsigned char)*S <= 0xF7) { \ - C = (*S++ & 0x07) << 18; \ - if((*S & 0xC0) != 0x80) { E; } \ - C |= (*S++ & 0x3F) << 12; \ - if((*S & 0xC0) != 0x80) { E; } \ - C |= (*S++ & 0x3F) << 6; \ - if((*S & 0xC0) != 0x80) { E; } \ - C |= (*S++ & 0x3F); \ - if(C < 0x10000 || C > 0x10FFFF) { E; } \ - } else { \ - E; \ - } \ -} while(0) - -#endif /* UTF8_h */ - -/* -Local Variables: -c-basic-offset:2 -comment-column:40 -End: -*/