Use Automake's simple test infrastructure for running Python-based
[disorder] / lib / t-syscalls.c
CommitLineData
c3c40090
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2008 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20#include "test.h"
21
22void test_syscalls(void) {
23 int p[2];
24 char buf[128], *e;
25 long n;
26 long long nn;
27
28 printf("test_syscalls\n");
29
30 xpipe(p);
31 nonblock(p[1]);
32 memset(buf, 99, sizeof buf);
33 errno = 0;
34 while(write(p[1], buf, sizeof buf) > 0)
35 errno = 0;
36 insist(errno == EAGAIN);
37 memset(buf, 0, sizeof buf);
38 insist(read(p[0], buf, sizeof buf) == sizeof buf);
39 insist(buf[0] == 99);
40 insist(buf[(sizeof buf) - 1] == 99);
41
42 xclose(p[0]);
43 xclose(p[1]);
44 errno = 0;
45 insist(read(p[0], buf, sizeof buf) < 0);
46 insist(errno == EBADF);
47 errno = 0;
48 insist(write(p[1], buf, sizeof buf) < 0);
49 insist(errno == EBADF);
50
51 n = 0;
52 e = 0;
53 sprintf(buf, "%ld", LONG_MAX);
54 insist(xstrtol(&n, buf, &e, 0) == 0);
55 insist(n == LONG_MAX);
56 insist(e == buf + strlen(buf));
57
58 n = 0;
59 e = 0;
60 sprintf(buf, "%ld0", LONG_MAX);
61 insist(xstrtol(&n, buf, &e, 0) == ERANGE);
62 insist(n == LONG_MAX);
63 insist(e == buf + strlen(buf));
64
65 n = 0;
66 e = 0;
67 sprintf(buf, "%ldxyzzy", LONG_MAX);
68 insist(xstrtol(&n, buf, &e, 0) == 0);
69 insist(n == LONG_MAX);
70 insist(e != 0);
71 check_string(e, "xyzzy");
72
98b46a80
RK
73#ifdef LLONG_MAX
74 /* Debian's gcc 2.95 cannot easily be persuaded to define LLONG_MAX even in
75 * extensions modes. If your compiler is this broken you just don't get the
76 * full set of tests. Deal. */
c3c40090
RK
77 nn = 0;
78 e = 0;
79 sprintf(buf, "%lld", LLONG_MAX);
80 insist(xstrtoll(&nn, buf, &e, 0) == 0);
81 insist(nn == LLONG_MAX);
82 insist(e == buf + strlen(buf));
83
84 nn = 0;
85 e = 0;
86 sprintf(buf, "%lld0", LLONG_MAX);
87 insist(xstrtoll(&nn, buf, &e, 0) == ERANGE);
88 insist(nn == LLONG_MAX);
89 insist(e == buf + strlen(buf));
90
91 nn = 0;
92 e = 0;
93 sprintf(buf, "%lldxyzzy", LLONG_MAX);
94 insist(xstrtoll(&nn, buf, &e, 0) == 0);
95 insist(nn == LLONG_MAX);
96 insist(e != 0);
98b46a80
RK
97 check_string(e, "xyzzy");
98#endif
c3c40090
RK
99}
100
101/*
102Local Variables:
103c-basic-offset:2
104comment-column:40
105fill-column:79
106indent-tabs-mode:nil
107End:
108*/