testIOS.cxx 4.1 KB

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