From: Richard Kettlewell Date: Sun, 27 Apr 2008 10:22:03 +0000 (+0100) Subject: More testing. X-Git-Tag: 4.0~91 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/c3c40090c7a6d155d797e3bdddd2cac704de7a11 More testing. --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 085659a..000ec0b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 index 0000000..6fcf413 --- /dev/null +++ b/lib/t-syscalls.c @@ -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: +*/ diff --git a/lib/test.c b/lib/test.c index 407f77e..d18aa34 100644 --- a/lib/test.c +++ b/lib/test.c @@ -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; } diff --git a/lib/test.h b/lib/test.h index a32c8ab..dafdfb5 100644 --- a/lib/test.h +++ b/lib/test.h @@ -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 */