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