diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-09-23 18:22:17 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-09-23 18:58:20 +0300 |
commit | 105115da9f601c53d87cdc038f795f00f56a3495 (patch) | |
tree | c0b8c200f485ed604c58c88f21b4fdfb1d723482 | |
parent | bd63944a739b4dcd49e8a65294ffb1b8a0a7b20b (diff) |
UUID: add `!=` operator for comparing UUIDs
Make it possible to unit test with `EXPECT_NE(uuid1, uuid2)`.
-rw-r--r-- | source/blender/blenlib/BLI_uuid.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/uuid.cc | 5 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_uuid_test.cc | 8 |
3 files changed, 10 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_uuid.h b/source/blender/blenlib/BLI_uuid.h index d21ccd450cc..111a3d1eac3 100644 --- a/source/blender/blenlib/BLI_uuid.h +++ b/source/blender/blenlib/BLI_uuid.h @@ -93,6 +93,7 @@ class bUUID : public ::bUUID { }; bool operator==(bUUID uuid1, bUUID uuid2); +bool operator!=(bUUID uuid1, bUUID uuid2); } // namespace blender diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc index cdb430c046a..bc8f67f939c 100644 --- a/source/blender/blenlib/intern/uuid.cc +++ b/source/blender/blenlib/intern/uuid.cc @@ -184,4 +184,9 @@ bool operator==(const bUUID uuid1, const bUUID uuid2) return BLI_uuid_equal(uuid1, uuid2); } +bool operator!=(const bUUID uuid1, const bUUID uuid2) +{ + return !(uuid1 == uuid2); +} + } // namespace blender diff --git a/source/blender/blenlib/tests/BLI_uuid_test.cc b/source/blender/blenlib/tests/BLI_uuid_test.cc index 42aa618963f..b5d636ed1c3 100644 --- a/source/blender/blenlib/tests/BLI_uuid_test.cc +++ b/source/blender/blenlib/tests/BLI_uuid_test.cc @@ -40,7 +40,7 @@ TEST(BLI_uuid, generate_many_random) /* Generate lots of UUIDs to get some indication that the randomness is okay. */ for (int i = 0; i < 1000000; ++i) { const bUUID uuid = BLI_uuid_generate_random(); - EXPECT_FALSE(BLI_uuid_equal(first_uuid, uuid)); + EXPECT_NE(first_uuid, uuid); // Check that the non-random bits are set according to RFC4122. const uint16_t version = uuid.time_hi_and_version >> 12; @@ -55,7 +55,7 @@ TEST(BLI_uuid, nil_value) const bUUID nil_uuid = BLI_uuid_nil(); const bUUID zeroes_uuid{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - EXPECT_TRUE(BLI_uuid_equal(nil_uuid, zeroes_uuid)); + EXPECT_EQ(nil_uuid, zeroes_uuid); EXPECT_TRUE(BLI_uuid_is_nil(nil_uuid)); std::string buffer(36, '\0'); @@ -68,8 +68,8 @@ TEST(BLI_uuid, equality) const bUUID uuid1 = BLI_uuid_generate_random(); const bUUID uuid2 = BLI_uuid_generate_random(); - EXPECT_TRUE(BLI_uuid_equal(uuid1, uuid1)); - EXPECT_FALSE(BLI_uuid_equal(uuid1, uuid2)); + EXPECT_EQ(uuid1, uuid1); + EXPECT_NE(uuid1, uuid2); } TEST(BLI_uuid, string_formatting) |