throwing_ptr
Smart pointers that throw on dereference if null
Functions
shared_ptr_comparison.cpp File Reference

Go to the source code of this file.

Functions

 TEST_CASE ("comparison operators between valid throwing::shared_ptr", "[shared_ptr][comparison]")
 
 TEST_CASE ("comparison operators between valid throwing::shared_ptr and " "std::shared_ptr", "[shared_ptr][comparison]")
 
 TEST_CASE ("comparison operators between valid throwing::shared_ptr and " "std::shared_ptr (other side)", "[shared_ptr][comparison]")
 
 TEST_CASE ("comparison operators with null throwing::shared_ptr", "[shared_ptr][comparison]")
 

Function Documentation

◆ TEST_CASE() [1/4]

TEST_CASE ( "comparison operators between valid throwing::shared_ptr ,
""  [shared_ptr][comparison] 
)

Definition at line 10 of file shared_ptr_comparison.cpp.

11  {
12  int *ptr1 = new int;
13  int *ptr2 = new int;
14  auto t_ptr1 = throwing::shared_ptr<int>(ptr1);
15  auto t_ptr1_1 = t_ptr1;
16  auto t_ptr2 = throwing::shared_ptr<int>(ptr2);
17 
18  REQUIRE_FALSE(t_ptr1 == t_ptr2);
19  REQUIRE_FALSE(t_ptr1_1 == t_ptr2);
20  REQUIRE(t_ptr1 == t_ptr1);
21  REQUIRE(t_ptr1 == t_ptr1_1);
22 
23  REQUIRE(t_ptr1 != t_ptr2);
24  REQUIRE(t_ptr1_1 != t_ptr2);
25  REQUIRE_FALSE(t_ptr1 != t_ptr1);
26  REQUIRE_FALSE(t_ptr1 != t_ptr1_1);
27 
28  REQUIRE((t_ptr1 < t_ptr2) == (ptr1 < ptr2));
29  REQUIRE((t_ptr1_1 < t_ptr2) == (ptr1 < ptr2));
30  REQUIRE_FALSE(t_ptr1 < t_ptr1);
31  REQUIRE_FALSE(t_ptr1 < t_ptr1_1);
32 
33  REQUIRE((t_ptr1 > t_ptr2) == (ptr1 > ptr2));
34  REQUIRE((t_ptr1_1 > t_ptr2) == (ptr1 > ptr2));
35  REQUIRE_FALSE(t_ptr1 > t_ptr1);
36  REQUIRE_FALSE(t_ptr1 > t_ptr1_1);
37 
38  REQUIRE((t_ptr1 <= t_ptr2) == (ptr1 <= ptr2));
39  REQUIRE((t_ptr1_1 <= t_ptr2) == (ptr1 <= ptr2));
40  REQUIRE((t_ptr1 <= t_ptr1) == (ptr1 <= ptr1));
41  REQUIRE((t_ptr1 <= t_ptr1_1) == (ptr1 <= ptr1));
42 
43  REQUIRE((t_ptr1 >= t_ptr2) == (ptr1 >= ptr2));
44  REQUIRE((t_ptr1_1 >= t_ptr2) == (ptr1 >= ptr2));
45  REQUIRE((t_ptr1 >= t_ptr1) == (ptr1 >= ptr1));
46  REQUIRE((t_ptr1 >= t_ptr1_1) == (ptr1 >= ptr1));
47 }
Wrapper aroung std::shared_ptr that throws when a wrapped null pointer is dereferenced.
Definition: shared_ptr.hpp:63

◆ TEST_CASE() [2/4]

TEST_CASE ( "comparison operators between valid throwing::shared_ptr and " "std::shared_ptr"  ,
""  [shared_ptr][comparison] 
)

Definition at line 49 of file shared_ptr_comparison.cpp.

51  {
52  int *ptr1 = new int;
53  int *ptr2 = new int;
54  auto t_ptr1 = throwing::shared_ptr<int>(ptr1);
55  auto t_ptr1_1 = t_ptr1;
56  auto t_ptr2 = std::shared_ptr<int>(ptr2);
57 
58  REQUIRE_FALSE(t_ptr1 == t_ptr2);
59  REQUIRE_FALSE(t_ptr1_1 == t_ptr2);
60  REQUIRE(t_ptr1 == t_ptr1);
61  REQUIRE(t_ptr1 == t_ptr1_1);
62 
63  REQUIRE(t_ptr1 != t_ptr2);
64  REQUIRE(t_ptr1_1 != t_ptr2);
65  REQUIRE_FALSE(t_ptr1 != t_ptr1);
66  REQUIRE_FALSE(t_ptr1 != t_ptr1_1);
67 
68  REQUIRE((t_ptr1 < t_ptr2) == (ptr1 < ptr2));
69  REQUIRE((t_ptr1_1 < t_ptr2) == (ptr1 < ptr2));
70  REQUIRE_FALSE(t_ptr1 < t_ptr1);
71  REQUIRE_FALSE(t_ptr1 < t_ptr1_1);
72 
73  REQUIRE((t_ptr1 > t_ptr2) == (ptr1 > ptr2));
74  REQUIRE((t_ptr1_1 > t_ptr2) == (ptr1 > ptr2));
75  REQUIRE_FALSE(t_ptr1 > t_ptr1);
76  REQUIRE_FALSE(t_ptr1 > t_ptr1_1);
77 
78  REQUIRE((t_ptr1 <= t_ptr2) == (ptr1 <= ptr2));
79  REQUIRE((t_ptr1_1 <= t_ptr2) == (ptr1 <= ptr2));
80  REQUIRE((t_ptr1 <= t_ptr1) == (ptr1 <= ptr1));
81  REQUIRE((t_ptr1 <= t_ptr1_1) == (ptr1 <= ptr1));
82 
83  REQUIRE((t_ptr1 >= t_ptr2) == (ptr1 >= ptr2));
84  REQUIRE((t_ptr1_1 >= t_ptr2) == (ptr1 >= ptr2));
85  REQUIRE((t_ptr1 >= t_ptr1) == (ptr1 >= ptr1));
86  REQUIRE((t_ptr1 >= t_ptr1_1) == (ptr1 >= ptr1));
87 }
Wrapper aroung std::shared_ptr that throws when a wrapped null pointer is dereferenced.
Definition: shared_ptr.hpp:63

◆ TEST_CASE() [3/4]

TEST_CASE ( "comparison operators between valid throwing::shared_ptr and " "std::shared_ptr (other side)"  ,
""  [shared_ptr][comparison] 
)

Definition at line 89 of file shared_ptr_comparison.cpp.

91  {
92  int *ptr1 = new int;
93  int *ptr2 = new int;
94  auto t_ptr1 = std::shared_ptr<int>(ptr1);
95  auto t_ptr1_1 = t_ptr1;
96  auto t_ptr2 = throwing::shared_ptr<int>(ptr2);
97 
98  REQUIRE_FALSE(t_ptr1 == t_ptr2);
99  REQUIRE_FALSE(t_ptr1_1 == t_ptr2);
100  REQUIRE(t_ptr1 == t_ptr1);
101  REQUIRE(t_ptr1 == t_ptr1_1);
102 
103  REQUIRE(t_ptr1 != t_ptr2);
104  REQUIRE(t_ptr1_1 != t_ptr2);
105  REQUIRE_FALSE(t_ptr1 != t_ptr1);
106  REQUIRE_FALSE(t_ptr1 != t_ptr1_1);
107 
108  REQUIRE((t_ptr1 < t_ptr2) == (ptr1 < ptr2));
109  REQUIRE((t_ptr1_1 < t_ptr2) == (ptr1 < ptr2));
110  REQUIRE_FALSE(t_ptr1 < t_ptr1);
111  REQUIRE_FALSE(t_ptr1 < t_ptr1_1);
112 
113  REQUIRE((t_ptr1 > t_ptr2) == (ptr1 > ptr2));
114  REQUIRE((t_ptr1_1 > t_ptr2) == (ptr1 > ptr2));
115  REQUIRE_FALSE(t_ptr1 > t_ptr1);
116  REQUIRE_FALSE(t_ptr1 > t_ptr1_1);
117 
118  REQUIRE((t_ptr1 <= t_ptr2) == (ptr1 <= ptr2));
119  REQUIRE((t_ptr1_1 <= t_ptr2) == (ptr1 <= ptr2));
120  REQUIRE((t_ptr1 <= t_ptr1) == (ptr1 <= ptr1));
121  REQUIRE((t_ptr1 <= t_ptr1_1) == (ptr1 <= ptr1));
122 
123  REQUIRE((t_ptr1 >= t_ptr2) == (ptr1 >= ptr2));
124  REQUIRE((t_ptr1_1 >= t_ptr2) == (ptr1 >= ptr2));
125  REQUIRE((t_ptr1 >= t_ptr1) == (ptr1 >= ptr1));
126  REQUIRE((t_ptr1 >= t_ptr1_1) == (ptr1 >= ptr1));
127 }
Wrapper aroung std::shared_ptr that throws when a wrapped null pointer is dereferenced.
Definition: shared_ptr.hpp:63

◆ TEST_CASE() [4/4]

TEST_CASE ( "comparison operators with null throwing::shared_ptr ,
""  [shared_ptr][comparison] 
)

Definition at line 129 of file shared_ptr_comparison.cpp.

130  {
131  int *ptr = new int;
132  auto t_ptr = throwing::shared_ptr<int>(ptr);
133  auto empty_t_ptr = throwing::shared_ptr<int>();
134 
135  REQUIRE(empty_t_ptr == nullptr);
136  REQUIRE_FALSE(t_ptr == nullptr);
137  REQUIRE(nullptr == empty_t_ptr);
138  REQUIRE_FALSE(nullptr == t_ptr);
139 
140  REQUIRE_FALSE(empty_t_ptr != nullptr);
141  REQUIRE(t_ptr != nullptr);
142  REQUIRE_FALSE(nullptr != empty_t_ptr);
143  REQUIRE(nullptr != t_ptr);
144 
145  REQUIRE((t_ptr < nullptr) == std::less<int *>()(ptr, nullptr));
146  REQUIRE((empty_t_ptr < nullptr) == std::less<int *>()(nullptr, nullptr));
147  REQUIRE((nullptr < t_ptr) == std::less<int *>()(nullptr, ptr));
148  REQUIRE((nullptr < empty_t_ptr) == std::less<int *>()(nullptr, nullptr));
149 
150  REQUIRE((t_ptr > nullptr) == std::less<int *>()(nullptr, ptr));
151  REQUIRE((empty_t_ptr > nullptr) == std::less<int *>()(nullptr, nullptr));
152  REQUIRE((nullptr > t_ptr) == std::less<int *>()(ptr, nullptr));
153  REQUIRE((nullptr > empty_t_ptr) == std::less<int *>()(nullptr, nullptr));
154 
155  REQUIRE((t_ptr <= nullptr) == !std::less<int *>()(nullptr, ptr));
156  REQUIRE((empty_t_ptr <= nullptr) == !std::less<int *>()(nullptr, nullptr));
157  REQUIRE((nullptr <= t_ptr) == !std::less<int *>()(ptr, nullptr));
158  REQUIRE((nullptr <= empty_t_ptr) == !std::less<int *>()(nullptr, nullptr));
159 
160  REQUIRE((t_ptr >= nullptr) == !std::less<int *>()(ptr, nullptr));
161  REQUIRE((empty_t_ptr >= nullptr) == !std::less<int *>()(nullptr, nullptr));
162  REQUIRE((nullptr >= t_ptr) == !std::less<int *>()(nullptr, ptr));
163  REQUIRE((nullptr >= empty_t_ptr) == !std::less<int *>()(nullptr, nullptr));
164 }
Wrapper aroung std::shared_ptr that throws when a wrapped null pointer is dereferenced.
Definition: shared_ptr.hpp:63