wide_stream_test.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2004-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #include <boost/iostreams/detail/config/wide_streams.hpp>
  7. #ifdef BOOST_IOSTREAMS_NO_WIDE_STREAMS
  8. # error wide streams not supported on this platform
  9. #endif
  10. #include <sstream>
  11. #include <vector>
  12. #include <boost/iostreams/device/back_inserter.hpp>
  13. #include <boost/iostreams/filtering_stream.hpp>
  14. #include <boost/test/test_tools.hpp>
  15. #include <boost/test/unit_test.hpp>
  16. #include "../example/container_device.hpp" // We use container_device instead
  17. #include "detail/filters.hpp" // of make_iterator_range to
  18. #include "detail/sequence.hpp" // reduce dependence on Boost.Range
  19. #include "detail/temp_file.hpp"
  20. #include "detail/verification.hpp"
  21. using boost::unit_test::test_suite;
  22. void read_wide_input_test()
  23. {
  24. using namespace std;
  25. using namespace boost;
  26. using namespace boost::iostreams;
  27. using namespace boost::iostreams::example;
  28. using namespace boost::iostreams::test;
  29. test_sequence<wchar_t> seq;
  30. container_device< test_sequence<wchar_t> > source(seq);
  31. {
  32. filtering_wistream first(source, 0);
  33. basic_istringstream<wchar_t> second(
  34. basic_string<wchar_t>(seq.begin(), seq.end())
  35. );
  36. BOOST_CHECK_MESSAGE(
  37. compare_streams_in_chars(first, second),
  38. "failed reading from a filter_wistream in chars with no buffer"
  39. );
  40. }
  41. {
  42. filtering_wistream first(source, 0);
  43. basic_istringstream<wchar_t> second(
  44. basic_string<wchar_t>(seq.begin(), seq.end())
  45. );
  46. BOOST_CHECK_MESSAGE(
  47. compare_streams_in_chunks(first, second),
  48. "failed reading from a filter_wistream in chunks with no buffer"
  49. );
  50. }
  51. {
  52. filtering_wistream first(source);
  53. basic_istringstream<wchar_t> second(
  54. basic_string<wchar_t>(seq.begin(), seq.end())
  55. );
  56. BOOST_CHECK_MESSAGE(
  57. compare_streams_in_chars(first, second),
  58. "failed reading from a filter_wistream in chars with large buffer"
  59. );
  60. }
  61. {
  62. filtering_wistream first(source);
  63. basic_istringstream<wchar_t> second(
  64. basic_string<wchar_t>(seq.begin(), seq.end())
  65. );
  66. BOOST_CHECK_MESSAGE(
  67. compare_streams_in_chunks(first, second),
  68. "failed reading from a filter_wistream in chunks with large buffer"
  69. );
  70. }
  71. }
  72. void write_wide_output_test()
  73. {
  74. using namespace std;
  75. using namespace boost;
  76. using namespace boost::iostreams;
  77. using namespace boost::iostreams::test;
  78. {
  79. vector<wchar_t> first;
  80. test_sequence<wchar_t> second;
  81. filtering_wostream out(iostreams::back_inserter(first), 0);
  82. write_data_in_chars(out);
  83. BOOST_CHECK_MESSAGE(
  84. first.size() == second.size() &&
  85. std::equal(first.begin(), first.end(), second.begin()),
  86. "failed writing to filtering_wostream in chars with no buffer"
  87. );
  88. }
  89. {
  90. vector<wchar_t> first;
  91. test_sequence<wchar_t> second;
  92. filtering_wostream out(iostreams::back_inserter(first), 0);
  93. write_data_in_chunks(out);
  94. BOOST_CHECK_MESSAGE(
  95. first.size() == second.size() &&
  96. std::equal(first.begin(), first.end(), second.begin()),
  97. "failed writing to filtering_wostream in chunks with no buffer"
  98. );
  99. }
  100. {
  101. vector<wchar_t> first;
  102. test_sequence<wchar_t> second;
  103. filtering_wostream out(iostreams::back_inserter(first), 0);
  104. write_data_in_chars(out);
  105. BOOST_CHECK_MESSAGE(
  106. first.size() == second.size() &&
  107. std::equal(first.begin(), first.end(), second.begin()),
  108. "failed writing to filtering_wostream in chars with large buffer"
  109. );
  110. }
  111. {
  112. vector<wchar_t> first;
  113. test_sequence<wchar_t> second;
  114. filtering_wostream out(iostreams::back_inserter(first));
  115. write_data_in_chunks(out);
  116. BOOST_CHECK_MESSAGE(
  117. first.size() == second.size() &&
  118. std::equal(first.begin(), first.end(), second.begin()),
  119. "failed writing to filtering_wostream in chunks with large buffer"
  120. );
  121. }
  122. }
  123. test_suite* init_unit_test_suite(int, char* [])
  124. {
  125. test_suite* test = BOOST_TEST_SUITE("wide stream test");
  126. test->add(BOOST_TEST_CASE(&read_wide_input_test));
  127. test->add(BOOST_TEST_CASE(&write_wide_output_test));
  128. return test;
  129. }