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