Eric Fiselier | 257fd69 | 2016-05-07 01:04:55 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // UNSUPPORTED: c++98, c++03 |
| 11 | |
| 12 | // <experimental/memory_resource> |
| 13 | |
| 14 | //------------------------------------------------------------------------------ |
| 15 | // TESTING virtual bool is_equal(memory_resource const &) const noexcept |
| 16 | // |
| 17 | // Concerns: |
| 18 | // A) 'memory_resource' provides a function 'is_equal' with the required |
| 19 | // signature. |
| 20 | // B) 'is_equal' is noexcept. |
| 21 | // C) 'do_is_equal' is called using the same arguments passed to 'is_equal' |
| 22 | // and the resulting value is returned. |
| 23 | // D) 'do_is_equal' is called on the LHS object and not the RHS object. |
| 24 | |
| 25 | #include <experimental/memory_resource> |
| 26 | #include <type_traits> |
| 27 | #include <cassert> |
| 28 | #include "test_memory_resource.hpp" |
| 29 | |
| 30 | using std::experimental::pmr::memory_resource; |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | { |
| 35 | memory_resource const* r1 = nullptr; |
| 36 | memory_resource const* r2 = nullptr; |
| 37 | static_assert( |
| 38 | noexcept(r1->is_equal(*r2)) |
| 39 | , "is_equal must be noexcept" |
| 40 | ); |
| 41 | } |
| 42 | { |
| 43 | TestResource1 R1(1); |
| 44 | auto& P1 = R1.getController(); |
| 45 | memory_resource const& M1 = R1; |
| 46 | |
| 47 | TestResource2 R2(1); |
| 48 | auto& P2 = R2.getController(); |
| 49 | memory_resource const& 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 | memory_resource const& M1 = R1; |
| 63 | |
| 64 | TestResource1 R2(2); |
| 65 | auto& P2 = R2.getController(); |
| 66 | memory_resource const& 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 | memory_resource const& M1 = R1; |
| 80 | |
| 81 | TestResource1 R2(1); |
| 82 | auto& P2 = R2.getController(); |
| 83 | memory_resource const& 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 | } |