xref: /freebsd/contrib/sendmail/libsm/t-smstdio.c (revision ee7b0571c2c18bdec848ed2044223cc88db29bd8)
140266059SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro  * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
340266059SGregory Neil Shapiro  *	All rights reserved.
440266059SGregory Neil Shapiro  *
540266059SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
640266059SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
740266059SGregory Neil Shapiro  * the sendmail distribution.
840266059SGregory Neil Shapiro  */
940266059SGregory Neil Shapiro 
1040266059SGregory Neil Shapiro #include <sm/gen.h>
11*4313cc83SGregory Neil Shapiro SM_IDSTR(id, "@(#)$Id: t-smstdio.c,v 1.12 2013-11-22 20:51:43 ca Exp $")
1240266059SGregory Neil Shapiro 
1340266059SGregory Neil Shapiro #include <sm/io.h>
1440266059SGregory Neil Shapiro #include <sm/string.h>
1540266059SGregory Neil Shapiro #include <sm/test.h>
1640266059SGregory Neil Shapiro 
1740266059SGregory Neil Shapiro int
1840266059SGregory Neil Shapiro main(argc, argv)
1940266059SGregory Neil Shapiro 	int argc;
2040266059SGregory Neil Shapiro 	char **argv;
2140266059SGregory Neil Shapiro {
2240266059SGregory Neil Shapiro 	FILE *stream;
2340266059SGregory Neil Shapiro 	SM_FILE_T *fp;
2440266059SGregory Neil Shapiro 	char buf[128];
2540266059SGregory Neil Shapiro 	size_t n;
2640266059SGregory Neil Shapiro 	static char testmsg[] = "hello, world\n";
2740266059SGregory Neil Shapiro 
2840266059SGregory Neil Shapiro 	sm_test_begin(argc, argv,
2940266059SGregory Neil Shapiro 		"test sm_io_stdioopen, smiostdin, smiostdout");
3040266059SGregory Neil Shapiro 
3140266059SGregory Neil Shapiro 	stream = fopen("t-smstdio.1", "w");
3240266059SGregory Neil Shapiro 	SM_TEST(stream != NULL);
3340266059SGregory Neil Shapiro 
3440266059SGregory Neil Shapiro 	fp = sm_io_stdioopen(stream, "w");
3540266059SGregory Neil Shapiro 	SM_TEST(fp != NULL);
3640266059SGregory Neil Shapiro 
3740266059SGregory Neil Shapiro 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s", testmsg);
3840266059SGregory Neil Shapiro 	sm_io_close(fp, SM_TIME_DEFAULT);
3940266059SGregory Neil Shapiro 
4040266059SGregory Neil Shapiro #if 0
4140266059SGregory Neil Shapiro 	/*
4240266059SGregory Neil Shapiro 	**  stream should now be closed.  This is a tricky way to test
4340266059SGregory Neil Shapiro 	**  if it is still open.  Alas, it core dumps on Linux.
4440266059SGregory Neil Shapiro 	*/
4540266059SGregory Neil Shapiro 
4640266059SGregory Neil Shapiro 	fprintf(stream, "oops! stream is still open!\n");
4740266059SGregory Neil Shapiro 	fclose(stream);
4840266059SGregory Neil Shapiro #endif
4940266059SGregory Neil Shapiro 
5040266059SGregory Neil Shapiro 	stream = fopen("t-smstdio.1", "r");
5140266059SGregory Neil Shapiro 	SM_TEST(stream != NULL);
5240266059SGregory Neil Shapiro 
5340266059SGregory Neil Shapiro 	fp = sm_io_stdioopen(stream, "r");
5440266059SGregory Neil Shapiro 	SM_TEST(fp != NULL);
5540266059SGregory Neil Shapiro 
5640266059SGregory Neil Shapiro 	n = sm_io_read(fp, SM_TIME_DEFAULT, buf, sizeof(buf));
5740266059SGregory Neil Shapiro 	if (SM_TEST(n == strlen(testmsg)))
5840266059SGregory Neil Shapiro 	{
5940266059SGregory Neil Shapiro 		buf[n] = '\0';
6040266059SGregory Neil Shapiro 		SM_TEST(strcmp(buf, testmsg) == 0);
6140266059SGregory Neil Shapiro 	}
6240266059SGregory Neil Shapiro 
6340266059SGregory Neil Shapiro #if 0
6440266059SGregory Neil Shapiro 
6540266059SGregory Neil Shapiro 	/*
6640266059SGregory Neil Shapiro 	**  Copy smiostdin to smiostdout
6740266059SGregory Neil Shapiro 	**  gotta think some more about how to test smiostdin and smiostdout
6840266059SGregory Neil Shapiro 	*/
6940266059SGregory Neil Shapiro 
7040266059SGregory Neil Shapiro 	while ((c = sm_io_getc(smiostdin)) != SM_IO_EOF)
7140266059SGregory Neil Shapiro 		sm_io_putc(smiostdout, c);
7240266059SGregory Neil Shapiro #endif
7340266059SGregory Neil Shapiro 
7440266059SGregory Neil Shapiro 	return sm_test_end();
7540266059SGregory Neil Shapiro }
76