Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / testIOS.cxx
blob0ab5c0eb2e1ffd8274201c52b54ab42d9cb65190
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 #include <string.h> /* strlen */
17 int testIOS(int, char*[])
19 kwsys_ios::ostringstream ostr;
20 const char hello[] = "hello";
21 ostr << hello;
22 if(ostr.str() != hello)
24 kwsys_ios::cerr << "failed to write hello to ostr" << kwsys_ios::endl;
25 return 1;
27 const char world[] = "world";
28 kwsys_ios::ostringstream ostr2;
29 ostr2.write( hello, strlen(hello) ); /* I could do sizeof */
30 ostr2.put( '\0' );
31 ostr2.write( world, strlen(world) );
32 if(ostr2.str().size() != strlen(hello) + 1 + strlen(world) )
34 kwsys_ios::cerr << "failed to write hello to ostr2" << kwsys_ios::endl;
35 return 1;
37 static const unsigned char array[] = { 0xff,0x4f,0xff,0x51,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x01,0x01,0xff,0x52,0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x05,0x04,0x04,0x00,0x01,0xff,0x5c,0x00,0x13,0x40,0x40,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0xff,0x64,0x00,0x2c,0x00,0x00,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x62,0x79,0x20,0x49,0x54,0x4b,0x2f,0x47,0x44,0x43,0x4d,0x2f,0x4f,0x70,0x65,0x6e,0x4a,0x50,0x45,0x47,0x20,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x2e,0x30,0xff,0x90,0x00,0x0a,0x00,0x00,0x00,0x00,0x06,0x2c,0x00,0x01,0xff,0x93,0xcf,0xb0,0x18,0x08,0x7f,0xc6,0x99,0xbf,0xff,0xc0,0xf8,0xc1,0xc1,0xf3,0x05,0x81,0xf2,0x83,0x0a,0xa5,0xff,0x10,0x90,0xbf,0x2f,0xff,0x04,0xa8,0x7f,0xc0,0xf8,0xc4,0xc1,0xf3,0x09,0x81,0xf3,0x0c,0x19,0x34 };
38 const unsigned int narray = sizeof(array); // 180
39 kwsys_ios::stringstream strstr;
40 strstr.write( (char*)array, narray );
41 if(strstr.str().size() != narray )
43 kwsys_ios::cerr << "failed to write array to strstr" << kwsys_ios::endl;
44 return 1;
47 kwsys_ios::istringstream istr(" 10 20 str ");
48 kwsys_stl::string s;
49 int x;
50 if(istr >> x)
52 if(x != 10)
54 kwsys_ios::cerr << "x != 10" << kwsys_ios::endl;
55 return 1;
58 else
60 kwsys_ios::cerr << "Failed to read 10 from istr" << kwsys_ios::endl;
61 return 1;
63 if(istr >> x)
65 if(x != 20)
67 kwsys_ios::cerr << "x != 20" << kwsys_ios::endl;
68 return 1;
71 else
73 kwsys_ios::cerr << "Failed to read 20 from istr" << kwsys_ios::endl;
74 return 1;
76 if(istr >> s)
78 if(s != "str")
80 kwsys_ios::cerr << "s != \"str\"" << kwsys_ios::endl;
81 return 1;
84 else
86 kwsys_ios::cerr << "Failed to read str from istr" << kwsys_ios::endl;
87 return 1;
89 if(istr >> s)
91 kwsys_ios::cerr << "Able to read past end of stream" << kwsys_ios::endl;
92 return 1;
94 else
96 // Clear the failure.
97 istr.clear(istr.rdstate() & ~kwsys_ios::ios::eofbit);
98 istr.clear(istr.rdstate() & ~kwsys_ios::ios::failbit);
100 istr.str("30");
101 if(istr >> x)
103 if(x != 30)
105 kwsys_ios::cerr << "x != 30" << kwsys_ios::endl;
106 return 1;
109 else
111 kwsys_ios::cerr << "Failed to read 30 from istr" << kwsys_ios::endl;
112 return 1;
115 kwsys_ios::stringstream sstr;
116 sstr << "40 str2";
117 if(sstr >> x)
119 if(x != 40)
121 kwsys_ios::cerr << "x != 40" << kwsys_ios::endl;
122 return 1;
125 else
127 kwsys_ios::cerr << "Failed to read 40 from sstr" << kwsys_ios::endl;
128 return 1;
130 if(sstr >> s)
132 if(s != "str2")
134 kwsys_ios::cerr << "s != \"str2\"" << kwsys_ios::endl;
135 return 1;
138 else
140 kwsys_ios::cerr << "Failed to read str2 from sstr" << kwsys_ios::endl;
141 return 1;
144 kwsys_ios::cout << "IOS tests passed" << kwsys_ios::endl;
145 return 0;