testIOS.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "kwsysPrivate.h"
  2. #include KWSYS_HEADER(stl/vector)
  3. #include KWSYS_HEADER(ios/sstream)
  4. #include KWSYS_HEADER(ios/fstream)
  5. #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_fstream.h.in"
  13. # include "kwsys_ios_iostream.h.in"
  14. #endif
  15. #include <string.h> /* strlen */
  16. int testIOS(int, char*[])
  17. {
  18. kwsys_ios::ostringstream ostr;
  19. const char hello[] = "hello";
  20. ostr << hello;
  21. if(ostr.str() != hello)
  22. {
  23. kwsys_ios::cerr << "failed to write hello to ostr" << kwsys_ios::endl;
  24. return 1;
  25. }
  26. const char world[] = "world";
  27. kwsys_ios::ostringstream ostr2;
  28. ostr2.write( hello, strlen(hello) ); /* I could do sizeof */
  29. ostr2.put( '\0' );
  30. ostr2.write( world, strlen(world) );
  31. if(ostr2.str().size() != strlen(hello) + 1 + strlen(world) )
  32. {
  33. kwsys_ios::cerr << "failed to write hello to ostr2" << kwsys_ios::endl;
  34. return 1;
  35. }
  36. 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 };
  37. const unsigned int narray = sizeof(array); // 180
  38. kwsys_ios::stringstream strstr;
  39. strstr.write( (char*)array, narray );
  40. //strstr.seekp( narray / 2 ); // set position of put pointer in mid string
  41. if(strstr.str().size() != narray )
  42. {
  43. kwsys_ios::cerr << "failed to write array to strstr" << kwsys_ios::endl;
  44. return 1;
  45. }
  46. kwsys_ios::istringstream istr(" 10 20 str ");
  47. kwsys_stl::string s;
  48. int x;
  49. if(istr >> x)
  50. {
  51. if(x != 10)
  52. {
  53. kwsys_ios::cerr << "x != 10" << kwsys_ios::endl;
  54. return 1;
  55. }
  56. }
  57. else
  58. {
  59. kwsys_ios::cerr << "Failed to read 10 from istr" << kwsys_ios::endl;
  60. return 1;
  61. }
  62. if(istr >> x)
  63. {
  64. if(x != 20)
  65. {
  66. kwsys_ios::cerr << "x != 20" << kwsys_ios::endl;
  67. return 1;
  68. }
  69. }
  70. else
  71. {
  72. kwsys_ios::cerr << "Failed to read 20 from istr" << kwsys_ios::endl;
  73. return 1;
  74. }
  75. if(istr >> s)
  76. {
  77. if(s != "str")
  78. {
  79. kwsys_ios::cerr << "s != \"str\"" << kwsys_ios::endl;
  80. return 1;
  81. }
  82. }
  83. else
  84. {
  85. kwsys_ios::cerr << "Failed to read str from istr" << kwsys_ios::endl;
  86. return 1;
  87. }
  88. if(istr >> s)
  89. {
  90. kwsys_ios::cerr << "Able to read past end of stream" << kwsys_ios::endl;
  91. return 1;
  92. }
  93. else
  94. {
  95. // Clear the failure.
  96. istr.clear(istr.rdstate() & ~kwsys_ios::ios::eofbit);
  97. istr.clear(istr.rdstate() & ~kwsys_ios::ios::failbit);
  98. }
  99. istr.str("30");
  100. if(istr >> x)
  101. {
  102. if(x != 30)
  103. {
  104. kwsys_ios::cerr << "x != 30" << kwsys_ios::endl;
  105. return 1;
  106. }
  107. }
  108. else
  109. {
  110. kwsys_ios::cerr << "Failed to read 30 from istr" << kwsys_ios::endl;
  111. return 1;
  112. }
  113. kwsys_ios::stringstream sstr;
  114. sstr << "40 str2";
  115. if(sstr >> x)
  116. {
  117. if(x != 40)
  118. {
  119. kwsys_ios::cerr << "x != 40" << kwsys_ios::endl;
  120. return 1;
  121. }
  122. }
  123. else
  124. {
  125. kwsys_ios::cerr << "Failed to read 40 from sstr" << kwsys_ios::endl;
  126. return 1;
  127. }
  128. if(sstr >> s)
  129. {
  130. if(s != "str2")
  131. {
  132. kwsys_ios::cerr << "s != \"str2\"" << kwsys_ios::endl;
  133. return 1;
  134. }
  135. }
  136. else
  137. {
  138. kwsys_ios::cerr << "Failed to read str2 from sstr" << kwsys_ios::endl;
  139. return 1;
  140. }
  141. // Just try to compile this.
  142. if(x == 12345)
  143. {
  144. kwsys_ios::ifstream fin("/does_not_exist",
  145. kwsys_ios::ios::in | kwsys_ios_binary);
  146. }
  147. kwsys_ios::cout << "IOS tests passed" << kwsys_ios::endl;
  148. return 0;
  149. }