Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_ios/fill/char/1.cc

raw
1 // { dg-do run }
2
3 #include <ios>
4 #include <locale>
5 #include <streambuf>
6 #include <testsuite_hooks.h>
7
8 typedef char C;
9
10 struct tabby_mctype : std::ctype<C>
11 {
12 C do_widen(char c) const { return c == ' ' ? '\t' : c; }
13
14 const char*
15 do_widen(const char* lo, const char* hi, C* to) const
16 {
17 while (lo != hi)
18 *to++ = do_widen(*lo++);
19 return hi;
20 }
21 };
22
23 void
24 test01()
25 {
26 std::basic_ios<C> out(0);
27 std::locale loc(std::locale(), new tabby_mctype);
28 out.imbue(loc);
29 VERIFY( out.fill() == ' ' ); // Imbuing a new locale doesn't affect fill().
30 out.fill('*');
31 VERIFY( out.fill() == '*' ); // This will be cached now.
32 out.imbue(std::locale());
33 VERIFY( out.fill() == '*' ); // Imbuing a new locale doesn't affect fill().
34 }
35
36 void
37 test02()
38 {
39 std::locale loc(std::locale(), new tabby_mctype);
40 std::locale::global(loc);
41 std::basic_ios<C> out(0);
42 VERIFY( out.fill() == '\t' );
43 out.imbue(std::locale::classic());
44 VERIFY( out.fill() == '\t' ); // Imbuing a new locale doesn't affect fill().
45 out.fill('*');
46 VERIFY( out.fill() == '*' ); // This will be cached now.
47 out.imbue(std::locale());
48 VERIFY( out.fill() == '*' ); // Imbuing a new locale doesn't affect fill().
49 }
50
51 void
52 test03()
53 {
54 // This function tests a libstdc++ extension: if no ctype<char_type> facet
55 // is present when the stream is initialized, a fill character will not be
56 // cached. Calling fill() will obtain a fill character from the locale each
57 // time it's called.
58 typedef signed char C2;
59 std::basic_ios<C2> out(0);
60 #if __cpp_exceptions
61 try {
62 (void) out.fill(); // No ctype<signed char> in the locale.
63 VERIFY( false );
64 } catch (...) {
65 }
66 #endif
67 out.fill('*');
68 VERIFY( out.fill() == '*' ); // This will be cached now.
69 out.imbue(std::locale());
70 VERIFY( out.fill() == '*' ); // Imbuing a new locale doesn't affect fill().
71 }
72
73 int main()
74 {
75 test01();
76 test02();
77 test03();
78 }