mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-12-30 04:33:01 +00:00
added some tests
This commit is contained in:
parent
7fad7d2bd6
commit
b1b7a26b51
16
lib/libc/tests/gen/psignal.c
Normal file
16
lib/libc/tests/gen/psignal.c
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* $Id: psignal.c,v 1.1 1997/09/05 06:46:20 gdr Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/signal.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
|
||||
printf("starting psignal test:\n\n");
|
||||
for (i=0; i<NSIG + 1; i++) {
|
||||
psignal(i, "signal test");
|
||||
}
|
||||
return 0;
|
||||
}
|
20
lib/libc/tests/stdio/buffer.c
Normal file
20
lib/libc/tests/stdio/buffer.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if 0
|
||||
#define STREAM stdout
|
||||
#else
|
||||
#define STREAM stderr
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
|
||||
for (i=0; i<3; i++) {
|
||||
fputc('x', STREAM);
|
||||
sleep(1);
|
||||
}
|
||||
fputc('\n', STREAM);
|
||||
exit(0);
|
||||
}
|
31
lib/libc/tests/stdio/fdopen1.c
Normal file
31
lib/libc/tests/stdio/fdopen1.c
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* $Id: fdopen1.c,v 1.1 1997/09/05 06:46:30 gdr Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int fd, i;
|
||||
FILE *fp;
|
||||
|
||||
if ((fd = open(*argv, O_RDONLY)) == -1) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
printf("open succeeded\n");
|
||||
if ((fp = fdopen(fd, "r")) == NULL) {
|
||||
perror("fdopen");
|
||||
exit(1);
|
||||
}
|
||||
printf("fopen succeeded\n");
|
||||
#if 0
|
||||
i = fclose(fp);
|
||||
printf("fclose returned %d\n", i);
|
||||
i = close(fd);
|
||||
printf("close returned %d\n", i);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
58
lib/libc/tests/stdio/fdopen2.c
Normal file
58
lib/libc/tests/stdio/fdopen2.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* $Id: fdopen2.c,v 1.1 1997/09/05 06:46:30 gdr Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define BUFFERSIZE 1024
|
||||
|
||||
char buffer[BUFFERSIZE];
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
FILE *fp1, *fp2;
|
||||
int fd1 = STDIN_FILENO;
|
||||
int fd2 = STDOUT_FILENO;
|
||||
|
||||
fprintf(stderr,"starting\n");
|
||||
#ifdef FROM_FILE
|
||||
if ((fp1 = fopen("data1", "rb")) == NULL) {
|
||||
#else
|
||||
#if 0
|
||||
fd1 = dup(STDIN_FILENO);
|
||||
fd2 = dup(STDOUT_FILENO);
|
||||
#endif
|
||||
if ((fd1 < 0) || (fd2 < 0)) {
|
||||
perror("dup failed");
|
||||
exit(1);
|
||||
}
|
||||
if ((fp1 = fdopen(fd1, "rb")) == NULL) {
|
||||
#endif
|
||||
perror("failed to do fdopen on stdin");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef FROM_FILE
|
||||
if ((fp2 = fopen("data5", "wb")) == NULL) {
|
||||
#else
|
||||
if ((fp2 = fdopen(fd2, "wb")) == NULL) {
|
||||
#endif
|
||||
perror("failed to do fdopen on stdout");
|
||||
exit(1);
|
||||
}
|
||||
while (fgets(buffer, BUFFERSIZE, fp1) != NULL) {
|
||||
if (fputs(buffer, fp2) == EOF) {
|
||||
perror("fputs failed for stdout");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (ferror(fp1)) {
|
||||
perror("error while reading from stdin");
|
||||
exit(1);
|
||||
}
|
||||
fclose(fp1);
|
||||
fclose(fp2);
|
||||
fprintf(stderr,"done\n");
|
||||
return 0;
|
||||
}
|
18
lib/libc/tests/stdio/fgets1.c
Normal file
18
lib/libc/tests/stdio/fgets1.c
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma lint -1
|
||||
#pragma debug 25
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFFERSIZE 1024
|
||||
|
||||
char buffer[BUFFERSIZE];
|
||||
int main(int argc, char **argv) {
|
||||
printf("hello, world\n");
|
||||
fprintf(stderr, "please enter a string: ");
|
||||
if (fgets(buffer, BUFFERSIZE, stdin) == NULL) {
|
||||
printf("fgets failed\n");
|
||||
} else {
|
||||
printf("input string was \"%s\"\n", buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
10
lib/libc/tests/stdio/filenos.c
Normal file
10
lib/libc/tests/stdio/filenos.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
printf("stdin fileno expected %d got %d\n", STDIN_FILENO, fileno(stdin));
|
||||
printf("stdout fileno expected %d got %d\n", STDOUT_FILENO, fileno(stdout));
|
||||
printf("stderr fileno expected %d got %d\n", STDERR_FILENO, fileno(stderr));
|
||||
return 0;
|
||||
}
|
8
lib/libc/tests/stdio/float1.c
Normal file
8
lib/libc/tests/stdio/float1.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
double pi = 3.141596;
|
||||
|
||||
printf("pi is %f\n", pi);
|
||||
return 0;
|
||||
}
|
20
lib/libc/tests/stdio/fopen.c
Normal file
20
lib/libc/tests/stdio/fopen.c
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* $Id: fopen.c,v 1.1 1997/09/05 06:46:31 gdr Exp $
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
FILE *fp;
|
||||
int i, j;
|
||||
|
||||
fp = fopen("/tmp/testfile", "w+");
|
||||
if (fp == NULL) {
|
||||
perror("open of /tmp/testfile failed");
|
||||
exit(1);
|
||||
}
|
||||
i = fprintf(fp, "now is the time\n");
|
||||
j = fclose(fp);
|
||||
printf("fprintf returned %d\nfclose returned %d\n", i, j);
|
||||
exit(0);
|
||||
}
|
41
lib/libc/tests/stdio/fopen2.c
Normal file
41
lib/libc/tests/stdio/fopen2.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This program exhibits a problem when opening a file for reading in
|
||||
* binary mode.
|
||||
*
|
||||
* $Id: fopen2.c,v 1.1 1997/09/05 06:46:31 gdr Exp $
|
||||
*/
|
||||
|
||||
#pragma keep "fopen2"
|
||||
#pragma debug 25
|
||||
#pragma lint -1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFFERSIZE 256
|
||||
#undef DO_READ
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
FILE *fp;
|
||||
#ifdef DO_READ
|
||||
static char buffer[BUFFERSIZE];
|
||||
int i;
|
||||
#endif
|
||||
|
||||
fp = fopen(*argv, "rb");
|
||||
if (fp == NULL) {
|
||||
perror("open failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef DO_READ
|
||||
i = fread(buffer, 1, BUFFERSIZE, fp);
|
||||
printf("fread returned %d\n", i);
|
||||
#endif
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
perror("fclose failed");
|
||||
return 1;
|
||||
}
|
||||
printf("done\n");
|
||||
return 0;
|
||||
}
|
42
lib/libc/tests/stdio/getputch.c
Normal file
42
lib/libc/tests/stdio/getputch.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This test checks to see if fgetc(3) returns a non-zero high byte
|
||||
* for anything but EOF.
|
||||
*
|
||||
* Usage:
|
||||
* Try it first on a text file. It should behave like cat(1):
|
||||
* getputch < getputch.c > out
|
||||
* Next try it on a binary file:
|
||||
* getputch < getputch > out
|
||||
* If fputc has problems with binary files you should see diagnostic
|
||||
* output. Note that in the second case you cannot do a cmp(1) on
|
||||
* the files and expect it to succeed since both stdin and stdout are
|
||||
* in "newline translation mode".
|
||||
*
|
||||
* $Id: getputch.c,v 1.1 1997/09/05 06:46:31 gdr Exp $
|
||||
*
|
||||
* Dave Tribby, August 1997.
|
||||
*/
|
||||
|
||||
#pragma debug 25
|
||||
#pragma lint -1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
int ch, hibyte, oldhi = -1;
|
||||
int retcode = 0;
|
||||
|
||||
while ((ch = fgetc(stdin)) != EOF) {
|
||||
if (ch > 255) {
|
||||
hibyte = (ch >> 8) & 255;
|
||||
if (hibyte != oldhi) {
|
||||
fprintf(stderr," fgetc() high byte = 0x%02X\n", hibyte);
|
||||
oldhi = hibyte;
|
||||
retcode = -1;
|
||||
}
|
||||
ch &= 0xFF;
|
||||
}
|
||||
(void) fputc(ch, stdout);
|
||||
}
|
||||
return retcode;
|
||||
}
|
40
lib/libc/tests/stdlib/cvt.c
Normal file
40
lib/libc/tests/stdlib/cvt.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sane.h>
|
||||
|
||||
char *ecvt (double, size_t, int *, int *);
|
||||
char *fcvt (double, size_t, int *, int *);
|
||||
|
||||
#define PI 3.141592653589793238512808959
|
||||
#define BUFFERSIZE 20
|
||||
|
||||
char buffer[BUFFERSIZE];
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
double d;
|
||||
int ndigits, decpt, sign, buflen, i;
|
||||
|
||||
buflen = BUFFERSIZE - 10;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
switch(i) {
|
||||
case 0: d = PI; break;
|
||||
case 1: d = 0.0123; break;
|
||||
case 2: d = 166.75; break;
|
||||
case 3: d = 0.9876; break;
|
||||
}
|
||||
ndigits = 6 /*buflen*/;
|
||||
|
||||
strcpy(buffer, ecvt(-d, ndigits, &decpt, &sign));
|
||||
printf("ecvt: decpt=%d\tsign=%d\tbuffer=%s\n",
|
||||
decpt, sign, buffer);
|
||||
|
||||
strcpy(buffer, fcvt(-d, ndigits, &decpt, &sign));
|
||||
printf("fcvt: decpt=%d\tsign=%d\tbuffer=%s\n",
|
||||
decpt, sign, buffer);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
25
lib/libc/tests/sys/rename.c
Normal file
25
lib/libc/tests/sys/rename.c
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is formatted with tab stops every 8 columns.
|
||||
*
|
||||
* $Id: rename.c,v 1.1 1997/09/05 06:46:33 gdr Exp $
|
||||
*
|
||||
* Devin Reade, 1997
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 3) {
|
||||
printf("usage: %s <oldfile> <newfile>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rename(argv[1], argv[2]) != 0) {
|
||||
perror("rename failed");
|
||||
return -1;
|
||||
}
|
||||
printf("passed\n");
|
||||
return 0;
|
||||
}
|
24
lib/libc/tests/sys/unlink.c
Normal file
24
lib/libc/tests/sys/unlink.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file is formatted with tab stops every 8 columns.
|
||||
*
|
||||
* $Id: unlink.c,v 1.1 1997/09/05 06:46:33 gdr Exp $
|
||||
*
|
||||
* Devin Reade, 1997
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("usage: %s filename\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
printf("trying to unlink %s\n", argv[1]);
|
||||
if (unlink(argv[1]) == -1) {
|
||||
perror("unlink failed");
|
||||
}
|
||||
printf("done\n");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user