Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-08-24 18:24:13 +0300
committerJacques Lucke <jacques@blender.org>2020-08-24 18:24:13 +0300
commit8e18a9984505514a229d66b38fff31d930367968 (patch)
tree97bb3e6f766e997df712bf081e05e027648e2c28 /source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh
parent530350935472970dccc211b0e728e2db4fd1d8ef (diff)
BLI: improve exception safety of Set and Map
For more information see rB2aff45146f1464ba8899368ad004522cb6a1a98c.
Diffstat (limited to 'source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh')
-rw-r--r--source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh44
1 files changed, 37 insertions, 7 deletions
diff --git a/source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh b/source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh
index 5ad7674396b..91270767a25 100644
--- a/source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh
+++ b/source/blender/blenlib/tests/BLI_exception_safety_test_utils.hh
@@ -1,3 +1,4 @@
+#include "BLI_hash.hh"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include "testing/testing.h"
@@ -16,18 +17,21 @@ class ExceptionThrower {
void *my_memory_;
public:
- bool throw_during_copy;
- bool throw_during_move;
+ mutable bool throw_during_copy;
+ mutable bool throw_during_move;
+ /* Used for hashing and comparing. */
+ int value;
- ExceptionThrower()
+ ExceptionThrower(int value = 0)
: state_(is_alive_state),
my_memory_(MEM_mallocN(1, AT)),
throw_during_copy(false),
- throw_during_move(false)
+ throw_during_move(false),
+ value(value)
{
}
- ExceptionThrower(const ExceptionThrower &other) : ExceptionThrower()
+ ExceptionThrower(const ExceptionThrower &other) : ExceptionThrower(other.value)
{
EXPECT_EQ(other.state_, is_alive_state);
if (other.throw_during_copy) {
@@ -35,7 +39,7 @@ class ExceptionThrower {
}
}
- ExceptionThrower(ExceptionThrower &&other) : ExceptionThrower()
+ ExceptionThrower(ExceptionThrower &&other) : ExceptionThrower(other.value)
{
EXPECT_EQ(other.state_, is_alive_state);
if (other.throw_during_move) {
@@ -49,6 +53,7 @@ class ExceptionThrower {
if (throw_during_copy || other.throw_during_copy) {
throw std::runtime_error("throwing during copy, as requested");
}
+ value = other.value;
return *this;
}
@@ -58,15 +63,40 @@ class ExceptionThrower {
if (throw_during_move || other.throw_during_move) {
throw std::runtime_error("throwing during move, as requested");
}
+ value = other.value;
return *this;
}
~ExceptionThrower()
{
- EXPECT_EQ(state_, is_alive_state);
+ const char *message = "";
+ if (state_ != is_alive_state) {
+ if (state_ == is_destructed_state) {
+ message = "Trying to destruct an already destructed instance.";
+ }
+ else {
+ message = "Trying to destruct an uninitialized instance.";
+ }
+ }
+ EXPECT_EQ(state_, is_alive_state) << message;
state_ = is_destructed_state;
MEM_freeN(my_memory_);
}
+
+ uint64_t hash() const
+ {
+ return static_cast<uint64_t>(value);
+ }
+
+ friend bool operator==(const ExceptionThrower &a, const ExceptionThrower &b)
+ {
+ return a.value == b.value;
+ }
+
+ friend bool operator!=(const ExceptionThrower &a, const ExceptionThrower &b)
+ {
+ return !(a == b);
+ }
};
} // namespace blender::tests