xref: /titanic_50/usr/src/cmd/sendmail/libsm/t-smstdio.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11 
12 #include <sm/gen.h>
13 SM_IDSTR(id, "@(#)$Id: t-smstdio.c,v 1.9 2001/03/21 18:30:41 ca Exp $")
14 
15 #include <sm/io.h>
16 #include <sm/string.h>
17 #include <sm/test.h>
18 
19 int
20 main(argc, argv)
21 	int argc;
22 	char **argv;
23 {
24 	FILE *stream;
25 	SM_FILE_T *fp;
26 	char buf[128];
27 	size_t n;
28 	static char testmsg[] = "hello, world\n";
29 
30 	sm_test_begin(argc, argv,
31 		"test sm_io_stdioopen, smiostdin, smiostdout");
32 
33 	stream = fopen("t-smstdio.1", "w");
34 	SM_TEST(stream != NULL);
35 
36 	fp = sm_io_stdioopen(stream, "w");
37 	SM_TEST(fp != NULL);
38 
39 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s", testmsg);
40 	sm_io_close(fp, SM_TIME_DEFAULT);
41 
42 #if 0
43 	/*
44 	**  stream should now be closed.  This is a tricky way to test
45 	**  if it is still open.  Alas, it core dumps on Linux.
46 	*/
47 
48 	fprintf(stream, "oops! stream is still open!\n");
49 	fclose(stream);
50 #endif
51 
52 	stream = fopen("t-smstdio.1", "r");
53 	SM_TEST(stream != NULL);
54 
55 	fp = sm_io_stdioopen(stream, "r");
56 	SM_TEST(fp != NULL);
57 
58 	n = sm_io_read(fp, SM_TIME_DEFAULT, buf, sizeof(buf));
59 	if (SM_TEST(n == strlen(testmsg)))
60 	{
61 		buf[n] = '\0';
62 		SM_TEST(strcmp(buf, testmsg) == 0);
63 	}
64 
65 #if 0
66 
67 	/*
68 	**  Copy smiostdin to smiostdout
69 	**  gotta think some more about how to test smiostdin and smiostdout
70 	*/
71 
72 	while ((c = sm_io_getc(smiostdin)) != SM_IO_EOF)
73 		sm_io_putc(smiostdout, c);
74 #endif
75 
76 	return sm_test_end();
77 }
78