STYLE: Nightly Date Stamp
[cmake.git] / Source / kwsys / testIOS.cxx
blobe4e0a2d30903757e184578105f33145f7c4bbf16
1 #include "kwsysPrivate.h"
2 #include KWSYS_HEADER(stl/vector)
3 #include KWSYS_HEADER(ios/sstream)
4 #include KWSYS_HEADER(ios/iostream)
6 // Work-around CMake dependency scanning limitation. This must
7 // duplicate the above list of headers.
8 #if 0
9 # include "kwsys_stl_string.hxx.in"
10 # include "kwsys_stl_vector.h.in"
11 # include "kwsys_ios_sstream.h.in"
12 # include "kwsys_ios_iostream.h.in"
13 #endif
15 int testIOS(int, char*[])
17 kwsys_ios::ostringstream ostr;
18 ostr << "hello";
19 if(ostr.str() != "hello")
21 kwsys_ios::cerr << "failed to write hello to ostr" << kwsys_ios::endl;
22 return 1;
24 kwsys_ios::istringstream istr(" 10 20 str ");
25 kwsys_stl::string s;
26 int x;
27 if(istr >> x)
29 if(x != 10)
31 kwsys_ios::cerr << "x != 10" << kwsys_ios::endl;
32 return 1;
35 else
37 kwsys_ios::cerr << "Failed to read 10 from istr" << kwsys_ios::endl;
38 return 1;
40 if(istr >> x)
42 if(x != 20)
44 kwsys_ios::cerr << "x != 20" << kwsys_ios::endl;
45 return 1;
48 else
50 kwsys_ios::cerr << "Failed to read 20 from istr" << kwsys_ios::endl;
51 return 1;
53 if(istr >> s)
55 if(s != "str")
57 kwsys_ios::cerr << "s != \"str\"" << kwsys_ios::endl;
58 return 1;
61 else
63 kwsys_ios::cerr << "Failed to read str from istr" << kwsys_ios::endl;
64 return 1;
66 if(istr >> s)
68 kwsys_ios::cerr << "Able to read past end of stream" << kwsys_ios::endl;
69 return 1;
71 else
73 // Clear the failure.
74 istr.clear(istr.rdstate() & ~kwsys_ios::ios::eofbit);
75 istr.clear(istr.rdstate() & ~kwsys_ios::ios::failbit);
77 istr.str("30");
78 if(istr >> x)
80 if(x != 30)
82 kwsys_ios::cerr << "x != 30" << kwsys_ios::endl;
83 return 1;
86 else
88 kwsys_ios::cerr << "Failed to read 30 from istr" << kwsys_ios::endl;
89 return 1;
92 kwsys_ios::stringstream sstr;
93 sstr << "40 str2";
94 if(sstr >> x)
96 if(x != 40)
98 kwsys_ios::cerr << "x != 40" << kwsys_ios::endl;
99 return 1;
102 else
104 kwsys_ios::cerr << "Failed to read 40 from sstr" << kwsys_ios::endl;
105 return 1;
107 if(sstr >> s)
109 if(s != "str2")
111 kwsys_ios::cerr << "s != \"str2\"" << kwsys_ios::endl;
112 return 1;
115 else
117 kwsys_ios::cerr << "Failed to read str2 from sstr" << kwsys_ios::endl;
118 return 1;
121 kwsys_ios::cout << "IOS tests passed" << kwsys_ios::endl;
122 return 0;