ostream_string_test.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. Copyright 2019 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/core/lightweight_test.hpp>
  8. #include <boost/utility/ostream_string.hpp>
  9. #include <sstream>
  10. #include <string>
  11. int main()
  12. {
  13. {
  14. std::ostringstream os;
  15. os.width(1);
  16. os.fill('.');
  17. os.setf(std::ios_base::left, std::ios_base::adjustfield);
  18. boost::ostream_string(os, "xy", 2);
  19. BOOST_TEST(os.good());
  20. BOOST_TEST(os.width() == 0);
  21. BOOST_TEST(os.str() == "xy");
  22. }
  23. {
  24. std::wostringstream os;
  25. os.width(1);
  26. os.fill('.');
  27. os.setf(std::ios_base::left, std::ios_base::adjustfield);
  28. boost::ostream_string(os, L"xy", 2);
  29. BOOST_TEST(os.good());
  30. BOOST_TEST(os.width() == 0);
  31. BOOST_TEST(os.str() == L"xy");
  32. }
  33. {
  34. std::ostringstream os;
  35. os.width(1);
  36. os.fill('.');
  37. os.setf(std::ios_base::right, std::ios_base::adjustfield);
  38. boost::ostream_string(os, "xy", 2);
  39. BOOST_TEST(os.good());
  40. BOOST_TEST(os.width() == 0);
  41. BOOST_TEST(os.str() == "xy");
  42. }
  43. {
  44. std::wostringstream os;
  45. os.width(1);
  46. os.fill('.');
  47. os.setf(std::ios_base::right, std::ios_base::adjustfield);
  48. boost::ostream_string(os, L"xy", 2);
  49. BOOST_TEST(os.good());
  50. BOOST_TEST(os.width() == 0);
  51. BOOST_TEST(os.str() == L"xy");
  52. }
  53. {
  54. std::ostringstream os;
  55. os.width(4);
  56. os.fill('.');
  57. os.setf(std::ios_base::left, std::ios_base::adjustfield);
  58. boost::ostream_string(os, "xy", 2);
  59. BOOST_TEST(os.good());
  60. BOOST_TEST(os.width() == 0);
  61. BOOST_TEST(os.str() == "xy..");
  62. }
  63. {
  64. std::wostringstream os;
  65. os.width(4);
  66. os.fill(L'.');
  67. os.setf(std::ios_base::left, std::ios_base::adjustfield);
  68. boost::ostream_string(os, L"xy", 2);
  69. BOOST_TEST(os.good());
  70. BOOST_TEST(os.width() == 0);
  71. BOOST_TEST(os.str() == L"xy..");
  72. }
  73. {
  74. std::ostringstream os;
  75. os.width(4);
  76. os.fill('.');
  77. os.setf(std::ios_base::right, std::ios_base::adjustfield);
  78. boost::ostream_string(os, "xy", 2);
  79. BOOST_TEST(os.good());
  80. BOOST_TEST(os.width() == 0);
  81. BOOST_TEST(os.str() == "..xy");
  82. }
  83. {
  84. std::wostringstream os;
  85. os.width(4);
  86. os.fill(L'.');
  87. os.setf(std::ios_base::right, std::ios_base::adjustfield);
  88. boost::ostream_string(os, L"xy", 2);
  89. BOOST_TEST(os.good());
  90. BOOST_TEST(os.width() == 0);
  91. BOOST_TEST(os.str() == L"..xy");
  92. }
  93. {
  94. std::ostringstream os;
  95. os.width(12);
  96. os.fill('.');
  97. os.setf(std::ios_base::left, std::ios_base::adjustfield);
  98. boost::ostream_string(os, "xy", 2);
  99. BOOST_TEST(os.good());
  100. BOOST_TEST(os.width() == 0);
  101. BOOST_TEST(os.str() == "xy..........");
  102. }
  103. {
  104. std::wostringstream os;
  105. os.width(12);
  106. os.fill(L'.');
  107. os.setf(std::ios_base::left, std::ios_base::adjustfield);
  108. boost::ostream_string(os, L"xy", 2);
  109. BOOST_TEST(os.good());
  110. BOOST_TEST(os.width() == 0);
  111. BOOST_TEST(os.str() == L"xy..........");
  112. }
  113. {
  114. std::ostringstream os;
  115. os.width(12);
  116. os.fill('.');
  117. os.setf(std::ios_base::right, std::ios_base::adjustfield);
  118. boost::ostream_string(os, "xy", 2);
  119. BOOST_TEST(os.good());
  120. BOOST_TEST(os.width() == 0);
  121. BOOST_TEST(os.str() == "..........xy");
  122. }
  123. {
  124. std::wostringstream os;
  125. os.width(12);
  126. os.fill(L'.');
  127. os.setf(std::ios_base::right, std::ios_base::adjustfield);
  128. boost::ostream_string(os, L"xy", 2);
  129. BOOST_TEST(os.good());
  130. BOOST_TEST(os.width() == 0);
  131. BOOST_TEST(os.str() == L"..........xy");
  132. }
  133. return boost::report_errors();
  134. }