xref: /illumos-gate/usr/src/cmd/sendmail/libsm/t-smstdio.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  */
9 
10 #include <sm/gen.h>
11 SM_IDSTR(id, "@(#)$Id: t-smstdio.c,v 1.9 2001/03/21 18:30:41 ca Exp $")
12 
13 #include <sm/io.h>
14 #include <sm/string.h>
15 #include <sm/test.h>
16 
17 int
18 main(argc, argv)
19 	int argc;
20 	char **argv;
21 {
22 	FILE *stream;
23 	SM_FILE_T *fp;
24 	char buf[128];
25 	size_t n;
26 	static char testmsg[] = "hello, world\n";
27 
28 	sm_test_begin(argc, argv,
29 		"test sm_io_stdioopen, smiostdin, smiostdout");
30 
31 	stream = fopen("t-smstdio.1", "w");
32 	SM_TEST(stream != NULL);
33 
34 	fp = sm_io_stdioopen(stream, "w");
35 	SM_TEST(fp != NULL);
36 
37 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s", testmsg);
38 	sm_io_close(fp, SM_TIME_DEFAULT);
39 
40 #if 0
41 	/*
42 	**  stream should now be closed.  This is a tricky way to test
43 	**  if it is still open.  Alas, it core dumps on Linux.
44 	*/
45 
46 	fprintf(stream, "oops! stream is still open!\n");
47 	fclose(stream);
48 #endif
49 
50 	stream = fopen("t-smstdio.1", "r");
51 	SM_TEST(stream != NULL);
52 
53 	fp = sm_io_stdioopen(stream, "r");
54 	SM_TEST(fp != NULL);
55 
56 	n = sm_io_read(fp, SM_TIME_DEFAULT, buf, sizeof(buf));
57 	if (SM_TEST(n == strlen(testmsg)))
58 	{
59 		buf[n] = '\0';
60 		SM_TEST(strcmp(buf, testmsg) == 0);
61 	}
62 
63 #if 0
64 
65 	/*
66 	**  Copy smiostdin to smiostdout
67 	**  gotta think some more about how to test smiostdin and smiostdout
68 	*/
69 
70 	while ((c = sm_io_getc(smiostdin)) != SM_IO_EOF)
71 		sm_io_putc(smiostdout, c);
72 #endif
73 
74 	return sm_test_end();
75 }
76