scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <assert.h>
 2#include <stdio.h>
 3#include <string.h>
 4
 5/*
 6output:
 7testing
 8test1
 9test2
10done
11end:
12*/
13
14static void
15test1(void)
16{
17	char buf[80];
18	FILE *fp1, *fp2;
19
20	puts("test1");
21	fp1 = tmpfile();
22	assert(fp1);
23	fp2 = tmpfile();
24	assert(fp2);
25
26	fputs("This is the first\n", fp1);
27	fputs("This is the second\n", fp2);
28	fflush(fp1);
29	fflush(fp2);
30
31	rewind(fp1);
32	rewind(fp2);
33
34	fgets(buf, sizeof(buf), fp1);
35	assert(strcmp(buf, "This is the first\n") == 0);
36
37	fgets(buf, sizeof(buf), fp2);
38	assert(strcmp(buf, "This is the second\n") == 0);
39
40	assert(fclose(fp1) == 0);
41	assert(fclose(fp2) == 0);
42}
43
44static void
45test2(void)
46{
47	int i, max;
48	FILE *fp;
49	static FILE *fps[FOPEN_MAX];
50
51	puts("test2");
52
53	max = TMP_MAX - 2;
54	if (max > FOPEN_MAX)
55		max = FOPEN_MAX - 3;
56	if (max > 32)
57		max = 32;
58
59	for (i = 0; i < max; i++)
60		assert(fps[i] = tmpfile());
61
62	for (i = 0; i < max; i++)
63		assert(fclose(fps[i]) == 0);
64}
65
66int
67main(void)
68{
69	puts("testing");
70	test1();
71	test2();
72	puts("done");
73
74	return 0;
75}