Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/123100.cc

raw
1 // { dg-do run }
2
3 #include <sstream>
4 #include <testsuite_hooks.h>
5
6 void
7 test01()
8 {
9 const int n = 20;
10 const char data[n] = "abcde";
11 char buf[n] = "0123456789";
12 std::string expected("abcde56789\0\0\0\0\0\0\0\0\0\0", n);
13
14 std::ostringstream out;
15 out.rdbuf()->pubsetbuf(buf, n);
16 out << data;
17 VERIFY( out.str() == expected );
18 VERIFY( out.str() == expected );
19 #if __cplusplus >= 201103L
20 VERIFY( std::move(out).str() == expected );
21 #if __cplusplus >= 202002L && _GLIBCXX_USE_CXX11_ABI
22 expected.clear();
23 #endif
24 VERIFY( out.str() == expected );
25 VERIFY( std::move(out).str() == expected );
26 #endif
27 }
28
29 void
30 test02()
31 {
32 const int n = 20;
33 const char data[n] = "abcde";
34 char buf[n] = "0123456789";
35 std::string expected("abcde56789\0\0\0\0\0\0\0\0\0\0", n);
36
37 std::ostringstream out;
38 out << std::string(n * 2, 'a');
39 VERIFY( out.str() == std::string(n * 2, 'a') );
40 out.rdbuf()->pubsetbuf(buf, n);
41 out << data; // writes 6 chars
42 VERIFY( out.str() == expected );
43 VERIFY( out.str() == expected );
44 #if __cplusplus >= 201103L
45 VERIFY( std::move(out).str() == expected );
46 #if __cplusplus >= 202002L && _GLIBCXX_USE_CXX11_ABI
47 expected.clear();
48 #endif
49 VERIFY( out.str() == expected );
50 VERIFY( std::move(out).str() == expected );
51 #endif
52 }
53
54 int main()
55 {
56 test01();
57 test02();
58 }