1N/A/*
1N/A * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_IDSTR(id, "@(#)$Id: t-smstdio.c,v 1.9 2001/03/21 18:30:41 ca Exp $")
1N/A
1N/A#include <sm/io.h>
1N/A#include <sm/string.h>
1N/A#include <sm/test.h>
1N/A
1N/Aint
1N/Amain(argc, argv)
1N/A int argc;
1N/A char **argv;
1N/A{
1N/A FILE *stream;
1N/A SM_FILE_T *fp;
1N/A char buf[128];
1N/A size_t n;
1N/A static char testmsg[] = "hello, world\n";
1N/A
1N/A sm_test_begin(argc, argv,
1N/A "test sm_io_stdioopen, smiostdin, smiostdout");
1N/A
1N/A stream = fopen("t-smstdio.1", "w");
1N/A SM_TEST(stream != NULL);
1N/A
1N/A fp = sm_io_stdioopen(stream, "w");
1N/A SM_TEST(fp != NULL);
1N/A
1N/A (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s", testmsg);
1N/A sm_io_close(fp, SM_TIME_DEFAULT);
1N/A
1N/A#if 0
1N/A /*
1N/A ** stream should now be closed. This is a tricky way to test
1N/A ** if it is still open. Alas, it core dumps on Linux.
1N/A */
1N/A
1N/A fprintf(stream, "oops! stream is still open!\n");
1N/A fclose(stream);
1N/A#endif
1N/A
1N/A stream = fopen("t-smstdio.1", "r");
1N/A SM_TEST(stream != NULL);
1N/A
1N/A fp = sm_io_stdioopen(stream, "r");
1N/A SM_TEST(fp != NULL);
1N/A
1N/A n = sm_io_read(fp, SM_TIME_DEFAULT, buf, sizeof(buf));
1N/A if (SM_TEST(n == strlen(testmsg)))
1N/A {
1N/A buf[n] = '\0';
1N/A SM_TEST(strcmp(buf, testmsg) == 0);
1N/A }
1N/A
1N/A#if 0
1N/A
1N/A /*
1N/A ** Copy smiostdin to smiostdout
1N/A ** gotta think some more about how to test smiostdin and smiostdout
1N/A */
1N/A
1N/A while ((c = sm_io_getc(smiostdin)) != SM_IO_EOF)
1N/A sm_io_putc(smiostdout, c);
1N/A#endif
1N/A
1N/A return sm_test_end();
1N/A}