]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/move_assign.cc
testsuite_hooks.h: Rewrite VERIFY in terms of __builtin_printf and __builtin_abort.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / allocator / wchar_t / move_assign.cc
1 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++11 } }
19
20 #include <string>
21 #include <testsuite_hooks.h>
22 #include <testsuite_allocator.h>
23
24 #if _GLIBCXX_USE_CXX11_ABI
25 using C = wchar_t;
26 const C c = L'a';
27 using traits = std::char_traits<C>;
28
29 using __gnu_test::propagating_allocator;
30
31 void test01()
32 {
33 typedef propagating_allocator<C, false> alloc_type;
34 typedef std::basic_string<C, traits, alloc_type> test_type;
35
36 test_type v1(alloc_type(1));
37 v1.assign(1, c);
38 test_type v2(alloc_type(2));
39 v2.assign(1, c);
40 v2 = std::move(v1);
41 VERIFY(1 == v1.get_allocator().get_personality());
42 VERIFY(2 == v2.get_allocator().get_personality());
43
44 test_type v3(alloc_type(3));
45 v3.assign(1, c);
46 test_type v4(alloc_type(4));
47 v4.assign(100, c);
48 v4 = std::move(v3);
49 VERIFY(3 == v3.get_allocator().get_personality());
50 VERIFY(4 == v4.get_allocator().get_personality());
51
52 test_type v5(alloc_type(5));
53 v5.assign(100, c);
54 test_type v6(alloc_type(6));
55 v6.assign(1, c);
56 v6 = std::move(v5);
57 VERIFY(5 == v5.get_allocator().get_personality());
58 VERIFY(6 == v6.get_allocator().get_personality());
59
60 test_type v7(alloc_type(7));
61 v7.assign(100, c);
62 test_type v8(alloc_type(8));
63 v8.assign(100, c);
64 v8 = std::move(v7);
65 VERIFY(7 == v7.get_allocator().get_personality());
66 VERIFY(8 == v8.get_allocator().get_personality());
67 }
68
69 void test02()
70 {
71 typedef propagating_allocator<C, true> alloc_type;
72 typedef std::basic_string<C, traits, alloc_type> test_type;
73
74 test_type v1(alloc_type(1));
75 v1.assign(1, c);
76 test_type v2(alloc_type(2));
77 v2.assign(1, c);
78 v2 = std::move(v1);
79 VERIFY(0 == v1.get_allocator().get_personality());
80 VERIFY(1 == v2.get_allocator().get_personality());
81
82 test_type v3(alloc_type(3));
83 v3.assign(1, c);
84 test_type v4(alloc_type(4));
85 v4.assign(100, c);
86 v4 = std::move(v3);
87 VERIFY(0 == v3.get_allocator().get_personality());
88 VERIFY(3 == v4.get_allocator().get_personality());
89
90 test_type v5(alloc_type(5));
91 v5.assign(100, c);
92 test_type v6(alloc_type(6));
93 v6.assign(1, c);
94 v6 = std::move(v5);
95 VERIFY(0 == v5.get_allocator().get_personality());
96 VERIFY(5 == v6.get_allocator().get_personality());
97
98 test_type v7(alloc_type(7));
99 v7.assign(100, c);
100 test_type v8(alloc_type(8));
101 v8.assign(100, c);
102 v8 = std::move(v7);
103 VERIFY(0 == v7.get_allocator().get_personality());
104 VERIFY(7 == v8.get_allocator().get_personality());
105 }
106
107 void test03()
108 {
109 typedef propagating_allocator<C, false> alloc_type;
110 typedef std::basic_string<C, traits, alloc_type> test_type;
111
112 test_type v1(alloc_type(1));
113 v1.assign(1, c);
114 test_type v2(alloc_type(1));
115 v2.assign(1, c);
116 v2 = std::move(v1);
117 VERIFY(1 == v1.get_allocator().get_personality());
118 VERIFY(1 == v2.get_allocator().get_personality());
119
120 test_type v3(alloc_type(3));
121 v3.assign(1, c);
122 test_type v4(alloc_type(3));
123 v4.assign(100, c);
124 v4 = std::move(v3);
125 VERIFY(3 == v3.get_allocator().get_personality());
126 VERIFY(3 == v4.get_allocator().get_personality());
127
128 test_type v5(alloc_type(5));
129 v5.assign(100, c);
130 test_type v6(alloc_type(5));
131 v6.assign(1, c);
132 v6 = std::move(v5);
133 VERIFY(5 == v5.get_allocator().get_personality());
134 VERIFY(5 == v6.get_allocator().get_personality());
135
136 test_type v7(alloc_type(7));
137 v7.assign(100, c);
138 test_type v8(alloc_type(7));
139 v8.assign(100, c);
140 v8 = std::move(v7);
141 VERIFY(7 == v7.get_allocator().get_personality());
142 VERIFY(7 == v8.get_allocator().get_personality());
143 }
144
145 int main()
146 {
147 test01();
148 test02();
149 test03();
150 return 0;
151 }
152 #else
153 int main()
154 {
155 // COW strings don't support C++11 allocators
156 }
157 #endif