xref: /llvm-project/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.public/is_equal.pass.cpp (revision 2da049a1418f7a2f96e7cac4368cac3ce8667d2e)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed
11 // UNSUPPORTED: availability-pmr-missing
12 
13 // test_memory_resource requires RTTI for dynamic_cast
14 // UNSUPPORTED: no-rtti
15 
16 // <memory_resource>
17 
18 //------------------------------------------------------------------------------
19 // TESTING virtual bool is_equal(memory_resource const &) const noexcept
20 //
21 // Concerns:
22 //   A) 'memory_resource' provides a function 'is_equal' with the required
23 //      signature.
24 //   B) 'is_equal' is noexcept.
25 //   C) 'do_is_equal' is called using the same arguments passed to 'is_equal'
26 //      and the resulting value is returned.
27 //   D) 'do_is_equal' is called on the LHS object and not the RHS object.
28 
29 #include <memory_resource>
30 #include <cassert>
31 #include <type_traits>
32 
33 #include "test_macros.h"
34 #include "test_std_memory_resource.h"
35 
main(int,char **)36 int main(int, char**) {
37   {
38     const std::pmr::memory_resource* r1 = nullptr;
39     const std::pmr::memory_resource* r2 = nullptr;
40     ASSERT_NOEXCEPT(r1->is_equal(*r2));
41   }
42   {
43     TestResource1 R1(1);
44     auto& P1                            = R1.getController();
45     const std::pmr::memory_resource& M1 = R1;
46 
47     TestResource2 R2(1);
48     auto& P2                            = R2.getController();
49     const std::pmr::memory_resource& M2 = R2;
50 
51     assert(M1.is_equal(M2) == false);
52     assert(P1.checkIsEqualCalledEq(1));
53     assert(P2.checkIsEqualCalledEq(0));
54 
55     assert(M2.is_equal(M1) == false);
56     assert(P2.checkIsEqualCalledEq(1));
57     assert(P1.checkIsEqualCalledEq(1));
58   }
59   {
60     TestResource1 R1(1);
61     auto& P1                            = R1.getController();
62     const std::pmr::memory_resource& M1 = R1;
63 
64     TestResource1 R2(2);
65     auto& P2                            = R2.getController();
66     const std::pmr::memory_resource& M2 = R2;
67 
68     assert(M1.is_equal(M2) == false);
69     assert(P1.checkIsEqualCalledEq(1));
70     assert(P2.checkIsEqualCalledEq(0));
71 
72     assert(M2.is_equal(M1) == false);
73     assert(P2.checkIsEqualCalledEq(1));
74     assert(P1.checkIsEqualCalledEq(1));
75   }
76   {
77     TestResource1 R1(1);
78     auto& P1                            = R1.getController();
79     const std::pmr::memory_resource& M1 = R1;
80 
81     TestResource1 R2(1);
82     auto& P2                            = R2.getController();
83     const std::pmr::memory_resource& M2 = R2;
84 
85     assert(M1.is_equal(M2) == true);
86     assert(P1.checkIsEqualCalledEq(1));
87     assert(P2.checkIsEqualCalledEq(0));
88 
89     assert(M2.is_equal(M1) == true);
90     assert(P2.checkIsEqualCalledEq(1));
91     assert(P1.checkIsEqualCalledEq(1));
92   }
93 
94   return 0;
95 }
96