]>
Commit | Line | Data |
---|---|---|
fbd26352 | 1 | // Copyright (C) 2018-2019 Free Software Foundation, Inc. |
51a5511d | 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-options "-std=gnu++17" } | |
19 | // { dg-do run { target c++17 } } | |
20 | // { dg-skip-if "" { *-*-* } { -fno-aligned-new } } | |
21 | ||
22 | #include <memory_resource> | |
23 | #include <testsuite_allocator.h> | |
24 | ||
25 | struct X { int i = 0; }; | |
26 | ||
27 | using test_type = std::pmr::polymorphic_allocator<X>; | |
28 | ||
29 | void | |
30 | test01() | |
31 | { | |
32 | __gnu_test::memory_resource r; | |
33 | test_type a(&r), b(&r); | |
34 | VERIFY( a == a ); | |
35 | VERIFY( ! (a != a) ); | |
36 | VERIFY( a == b ); | |
37 | VERIFY( ! (a != b) ); | |
38 | VERIFY( a.resource() == &r ); | |
39 | VERIFY( a.resource() == b.resource() ); | |
40 | ||
41 | __gnu_test::memory_resource r2(r); | |
42 | test_type c(&r2); | |
43 | VERIFY( c.resource() == &r2 ); | |
44 | VERIFY( c.resource() != a.resource() ); | |
45 | VERIFY( c == a ); | |
46 | } | |
47 | ||
48 | void | |
49 | test02() | |
50 | { | |
51 | __gnu_test::memory_resource r1, r2; | |
52 | test_type a(&r1), b(&r2); | |
53 | VERIFY( a == a ); | |
54 | VERIFY( b == b ); | |
55 | VERIFY( ! (a == b) ); | |
56 | VERIFY( ! (b == a) ); | |
57 | VERIFY( a != b ); | |
58 | VERIFY( b != a ); | |
59 | VERIFY( a.resource() == &r1 ); | |
60 | VERIFY( a.resource() != b.resource() ); | |
61 | ||
62 | test_type c; | |
63 | VERIFY( c == c ); | |
64 | VERIFY( ! (a == c) ); | |
65 | VERIFY( ! (c == a) ); | |
66 | VERIFY( ! (b == c) ); | |
67 | VERIFY( ! (c == b) ); | |
68 | VERIFY( a.resource() != c.resource() ); | |
69 | VERIFY( c.resource() == std::pmr::get_default_resource() ); | |
70 | ||
71 | std::pmr::set_default_resource(&r1); | |
72 | VERIFY( c.resource() != &r1 ); | |
73 | ||
74 | test_type d; | |
75 | VERIFY( d.resource() == &r1 ); | |
76 | VERIFY( d != c ); | |
77 | VERIFY( d == a ); | |
78 | ||
79 | std::pmr::set_default_resource(nullptr); | |
80 | } | |
81 | ||
82 | int | |
83 | main() | |
84 | { | |
85 | test01(); | |
86 | test02(); | |
87 | } |