chiark / gitweb /
More testing.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 27 Apr 2008 10:22:03 +0000 (11:22 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 27 Apr 2008 10:22:03 +0000 (11:22 +0100)
lib/Makefile.am
lib/t-syscalls.c [new file with mode: 0644]
lib/test.c
lib/test.h

index 085659a976dd88200771bf1562f754a2b49fccbe..000ec0baa3495359ba475281618504835ab23e78 100644 (file)
@@ -119,7 +119,7 @@ test_SOURCES=test.c memgc.c test.h t-addr.c t-basen.c t-cache.c             \
        t-casefold.c t-cookies.c t-filepart.c t-hash.c t-heap.c         \
        t-hex.c t-kvp.c t-mime.c t-printf.c t-regsub.c t-selection.c    \
        t-signame.c t-sink.c t-split.c t-unicode.c t-url.c t-utf8.c     \
-       t-words.c t-wstat.c t-bits.c t-vector.c
+       t-words.c t-wstat.c t-bits.c t-vector.c t-syscalls.c
 test_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC)
 test_DEPENDENCIES=libdisorder.a
 
diff --git a/lib/t-syscalls.c b/lib/t-syscalls.c
new file mode 100644 (file)
index 0000000..6fcf413
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * This file is part of DisOrder.
+ * Copyright (C) 2008 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 "test.h"
+
+void test_syscalls(void) {
+  int p[2];
+  char buf[128], *e;
+  long n;
+  long long nn;
+  
+  printf("test_syscalls\n");
+
+  xpipe(p);
+  nonblock(p[1]);
+  memset(buf, 99, sizeof buf);
+  errno = 0;
+  while(write(p[1], buf, sizeof buf) > 0)
+    errno = 0;
+  insist(errno == EAGAIN);
+  memset(buf, 0, sizeof buf);
+  insist(read(p[0], buf, sizeof buf) == sizeof buf);
+  insist(buf[0] == 99);
+  insist(buf[(sizeof buf) - 1] == 99);
+
+  xclose(p[0]);
+  xclose(p[1]);
+  errno = 0;
+  insist(read(p[0], buf, sizeof buf) < 0);
+  insist(errno == EBADF);
+  errno = 0;
+  insist(write(p[1], buf, sizeof buf) < 0);
+  insist(errno == EBADF);
+
+  n = 0;
+  e = 0;
+  sprintf(buf, "%ld", LONG_MAX);
+  insist(xstrtol(&n, buf, &e, 0) == 0);
+  insist(n == LONG_MAX);
+  insist(e == buf + strlen(buf));
+
+  n = 0;
+  e = 0;
+  sprintf(buf, "%ld0", LONG_MAX);
+  insist(xstrtol(&n, buf, &e, 0) == ERANGE);
+  insist(n == LONG_MAX);
+  insist(e == buf + strlen(buf));
+
+  n = 0;
+  e = 0;
+  sprintf(buf, "%ldxyzzy", LONG_MAX);
+  insist(xstrtol(&n, buf, &e, 0) == 0);
+  insist(n == LONG_MAX);
+  insist(e != 0);
+  check_string(e, "xyzzy");
+
+  nn = 0;
+  e = 0;
+  sprintf(buf, "%lld", LLONG_MAX);
+  insist(xstrtoll(&nn, buf, &e, 0) == 0);
+  insist(nn == LLONG_MAX);
+  insist(e == buf + strlen(buf));
+
+  nn = 0;
+  e = 0;
+  sprintf(buf, "%lld0", LLONG_MAX);
+  insist(xstrtoll(&nn, buf, &e, 0) == ERANGE);
+  insist(nn == LLONG_MAX);
+  insist(e == buf + strlen(buf));
+
+  nn = 0;
+  e = 0;
+  sprintf(buf, "%lldxyzzy", LLONG_MAX);
+  insist(xstrtoll(&nn, buf, &e, 0) == 0);
+  insist(nn == LLONG_MAX);
+  insist(e != 0);
+  check_string(e, "xyzzy");  
+}
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+indent-tabs-mode:nil
+End:
+*/
index 407f77ee66ac46323b7589193a870491108ce89c..d18aa347e1f3f3001384171f9b05777a54dd917f 100644 (file)
@@ -160,6 +160,7 @@ int main(void) {
   test_regsub();
   test_bits();
   test_vector();
+  test_syscalls();
   fprintf(stderr,  "%lld errors out of %lld tests\n", errors, tests);
   return !!errors;
 }
index a32c8abf1615c8f5f11c3f67f5bcdbc64858e1bc..dafdfb5203b1b3f7f8c8283bb8376c36f7803ec2 100644 (file)
@@ -155,6 +155,7 @@ void test_words(void);
 void test_wstat(void);
 void test_bits(void);
 void test_vector(void);
+void test_syscalls(void);
 
 #endif /* TEST_H */