1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1999-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                                                                      *
19 ***********************************************************************/
20 #include	"sftest.h"
21 
tmain()22 tmain()
23 {
24 	Sfio_t*	f1;
25 	Sfio_t* f2;
26 	char*	s;
27 
28 	if(!(f1 = sfopen(NIL(Sfio_t*), tstfile("sf", 0),"w+")) )
29 		terror("Can't open file");
30 	if(sfwrite(f1,"0123456789\n",11) != 11)
31 		terror("Can't write to file");
32 
33 	sfclose(sfstdin);
34 	if(sfswap(f1,sfstdin) != sfstdin)
35 		terror("Can't swap with sfstdin");
36 	sfseek(sfstdin,(Sfoff_t)0,0);
37 	if(!(s = sfgetr(sfstdin,'\n',1)) )
38 		terror("sfgetr failed");
39 	if(strcmp(s,"0123456789") != 0)
40 		terror("Get wrong data");
41 
42 	if(!(f1 = sfswap(sfstdin,NIL(Sfio_t*))) )
43 		terror("Failed swapping to NULL");
44 	if(!sfstack(sfstdout,f1) )
45 		terror("Failed stacking f1");
46 
47 	if(!(f2 = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "r")) )
48 		terror("Can't open for read");
49 
50 	if(sfswap(f1,f2) != NIL(Sfio_t*) )
51 		terror("sfswap should have failed");
52 
53 	texit(0);
54 }
55