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