summaryrefslogtreecommitdiff
path: root/usertest.c
diff options
context:
space:
mode:
Diffstat (limited to 'usertest.c')
-rw-r--r--usertest.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/usertest.c b/usertest.c
index ef1eaf8..8bb6e5b 100644
--- a/usertest.c
+++ b/usertest.c
@@ -40,6 +40,61 @@ void semi_putc(void *p, char c)
#define TESTDATA_FILE "testdata.txt"
const char file[] = "Small file of text data for test.\n";
+static int test_istty(void)
+{
+ int fd;
+ int fail = 0;
+
+ fd = semi_open(TESTDATA_FILE, OPEN_RDONLY);
+ if (fd == -1) {
+ semi_write0("FAIL could not open test data file\n");
+ return 1;
+ }
+
+ switch (semi_istty(fd)) {
+ case 0:
+ semi_write0("PASS istty(file) returned 0\n");
+ break;
+ case 1:
+ semi_write0("FAIL istty(file) returned 1\n");
+ fail++;
+ break;
+ default:
+ semi_write0("FAIL istty(file) failed\n");
+ fail++;
+ break;
+ }
+ semi_close(fd);
+ if (fail) {
+ return 1;
+ }
+
+ fd = semi_open(":tt", OPEN_RDONLY);
+ if (fd == -1) {
+ semi_write0("FAIL could not open stdin\n");
+ return 1;
+ }
+
+ switch (semi_istty(fd)) {
+ case 0:
+ semi_write0("FAIL istty(stdin) returned 0\n");
+ fail++;
+ break;
+ case 1:
+ semi_write0("PASS istty(stdin) returned 1\n");
+ break;
+ default:
+ semi_write0("FAIL istty(stdin) failed\n");
+ fail++;
+ break;
+ }
+ semi_close(fd);
+ if (fail) {
+ return 1;
+ }
+ return 0;
+}
+
int main(void)
{
void *bufp;
@@ -75,6 +130,10 @@ int main(void)
}
semi_write0("PASS test file contents match\n");
+ if (test_istty()) {
+ return 1;
+ }
+
semi_write0("ALL TESTS PASSED\n");
semi_exit(0);
/* not reached */