Commit | Line | Data |
---|---|---|
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 | ||
c68d8eba | 22 | static void test_syscalls(void) { |
c3c40090 RK |
23 | int p[2]; |
24 | char buf[128], *e; | |
25 | long n; | |
26 | long long nn; | |
c3c40090 RK |
27 | |
28 | xpipe(p); | |
29 | nonblock(p[1]); | |
30 | memset(buf, 99, sizeof buf); | |
31 | errno = 0; | |
32 | while(write(p[1], buf, sizeof buf) > 0) | |
33 | errno = 0; | |
34 | insist(errno == EAGAIN); | |
35 | memset(buf, 0, sizeof buf); | |
36 | insist(read(p[0], buf, sizeof buf) == sizeof buf); | |
37 | insist(buf[0] == 99); | |
38 | insist(buf[(sizeof buf) - 1] == 99); | |
39 | ||
40 | xclose(p[0]); | |
41 | xclose(p[1]); | |
42 | errno = 0; | |
43 | insist(read(p[0], buf, sizeof buf) < 0); | |
44 | insist(errno == EBADF); | |
45 | errno = 0; | |
46 | insist(write(p[1], buf, sizeof buf) < 0); | |
47 | insist(errno == EBADF); | |
48 | ||
49 | n = 0; | |
50 | e = 0; | |
51 | sprintf(buf, "%ld", LONG_MAX); | |
52 | insist(xstrtol(&n, buf, &e, 0) == 0); | |
53 | insist(n == LONG_MAX); | |
54 | insist(e == buf + strlen(buf)); | |
55 | ||
56 | n = 0; | |
57 | e = 0; | |
58 | sprintf(buf, "%ld0", LONG_MAX); | |
59 | insist(xstrtol(&n, buf, &e, 0) == ERANGE); | |
60 | insist(n == LONG_MAX); | |
61 | insist(e == buf + strlen(buf)); | |
62 | ||
63 | n = 0; | |
64 | e = 0; | |
65 | sprintf(buf, "%ldxyzzy", LONG_MAX); | |
66 | insist(xstrtol(&n, buf, &e, 0) == 0); | |
67 | insist(n == LONG_MAX); | |
68 | insist(e != 0); | |
69 | check_string(e, "xyzzy"); | |
70 | ||
98b46a80 RK |
71 | #ifdef LLONG_MAX |
72 | /* Debian's gcc 2.95 cannot easily be persuaded to define LLONG_MAX even in | |
73 | * extensions modes. If your compiler is this broken you just don't get the | |
74 | * full set of tests. Deal. */ | |
c3c40090 RK |
75 | nn = 0; |
76 | e = 0; | |
77 | sprintf(buf, "%lld", LLONG_MAX); | |
78 | insist(xstrtoll(&nn, buf, &e, 0) == 0); | |
79 | insist(nn == LLONG_MAX); | |
80 | insist(e == buf + strlen(buf)); | |
81 | ||
82 | nn = 0; | |
83 | e = 0; | |
84 | sprintf(buf, "%lld0", LLONG_MAX); | |
85 | insist(xstrtoll(&nn, buf, &e, 0) == ERANGE); | |
86 | insist(nn == LLONG_MAX); | |
87 | insist(e == buf + strlen(buf)); | |
88 | ||
89 | nn = 0; | |
90 | e = 0; | |
91 | sprintf(buf, "%lldxyzzy", LLONG_MAX); | |
92 | insist(xstrtoll(&nn, buf, &e, 0) == 0); | |
93 | insist(nn == LLONG_MAX); | |
94 | insist(e != 0); | |
98b46a80 RK |
95 | check_string(e, "xyzzy"); |
96 | #endif | |
c3c40090 RK |
97 | } |
98 | ||
c68d8eba RK |
99 | TEST(syscalls); |
100 | ||
c3c40090 RK |
101 | /* |
102 | Local Variables: | |
103 | c-basic-offset:2 | |
104 | comment-column:40 | |
105 | fill-column:79 | |
106 | indent-tabs-mode:nil | |
107 | End: | |
108 | */ |