chiark / gitweb /
more testing
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 9 Dec 2007 18:55:04 +0000 (18:55 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 9 Dec 2007 18:55:04 +0000 (18:55 +0000)
lib/Makefile.am
lib/addr.c
lib/addr.h
lib/test.c
lib/utf8.c [deleted file]
lib/utf8.h [deleted file]

index 67416b2a0f57548603a9c4f389a1bce82883f554..ab856a797bc513635cb0a1213023101d4b4294ad 100644 (file)
@@ -65,7 +65,6 @@ libdisorder_a_SOURCES=charset.c charset.h             \
        user.h user.c                                   \
        unicode.h unicode.c                             \
        unidata.h unidata.c                             \
        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                                     \
        vacopy.h                                        \
        vector.c vector.h                               \
        wav.h wav.c                                     \
index 0b5b7837b9e9c3b4f13e9f375938281c0ef5c663..8288e4ec01ebf6f66254356075858c62fddc77df 100644 (file)
@@ -17,7 +17,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  */
  * 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 <config.h>
 #include "types.h"
 
 #include <config.h>
 #include "types.h"
index fb1dd7f53f63edd90360b8361e744ee220a20f18..8bd703f033b8f2135a2b409d0ed033cc432bc28b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
 /*
  * 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
  *
  * 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
  */
  * 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
 
 #ifndef ADDR_H
 #define ADDR_H
index e8e550fd44b06e1786c690da5efb7b50956f5fac..50280546fa9d306d5a91ea6afd7d496593c06bf2 100644 (file)
 #include <signal.h>
 #include <sys/wait.h>
 #include <stddef.h>
 #include <signal.h>
 #include <sys/wait.h>
 #include <stddef.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
 
 
-#include "utf8.h"
 #include "mem.h"
 #include "log.h"
 #include "vector.h"
 #include "mem.h"
 #include "log.h"
 #include "vector.h"
@@ -57,6 +59,8 @@
 #include "printf.h"
 #include "basen.h"
 #include "split.h"
 #include "printf.h"
 #include "basen.h"
 #include "split.h"
+#include "configuration.h"
+#include "addr.h"
 
 static int tests, errors;
 static int fail_first;
 
 static int tests, errors;
 static int fail_first;
@@ -1279,6 +1283,55 @@ static void test_hash(void) {
   check_integer(hash_count(h), 0);
 }
 
   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");
 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 */
   insist('a' == 0x61);
   insist('z' == 0x7A);
   /* addr.c */
+  test_addr();
   /* asprintf.c */
   /* authhash.c */
   /* basen.c */
   /* asprintf.c */
   /* authhash.c */
   /* basen.c */
diff --git a/lib/utf8.c b/lib/utf8.c
deleted file mode 100644 (file)
index 9ca228c..0000000
+++ /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 <config.h>
-#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 (file)
index 683a8a9..0000000
+++ /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:
-*/