Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 28s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m3s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 50s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m10s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 54s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 41s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 50s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 40s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 50s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 41s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 55s
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 39s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 26s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 43s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 28s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 46s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 32s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m6s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 53s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m13s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 58s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 32s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 25s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 44s
Bigfoot / Clang Format Checks (push) Successful in 11s
210 lines
5.7 KiB
C++
210 lines
5.7 KiB
C++
/*********************************************************************
|
|
* \file UUID.cpp
|
|
*
|
|
* \author Romain BOULLARD
|
|
* \date October 2025
|
|
*********************************************************************/
|
|
#include <System/UUID/UUID.hpp>
|
|
|
|
#include <System/UUID/UUID_generated.hpp>
|
|
|
|
#include <ankerl/unordered_dense.h>
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace Bigfoot
|
|
{
|
|
class UUIDFixture: public ::testing::Test
|
|
{
|
|
protected:
|
|
UUID m_a;
|
|
UUID m_b {"47183823-2574-4bfd-b411-99ed177d3e43"};
|
|
UUID m_c {"4bfd-b411-99ed177d3e43"};
|
|
|
|
std::array<std::byte, 16> m_raw {
|
|
std::byte {0},
|
|
std::byte {1},
|
|
std::byte {2},
|
|
std::byte {3},
|
|
std::byte {4},
|
|
std::byte {5},
|
|
std::byte {6},
|
|
std::byte {7},
|
|
std::byte {8},
|
|
std::byte {9},
|
|
std::byte {10},
|
|
std::byte {11},
|
|
std::byte {12},
|
|
std::byte {13},
|
|
std::byte {14},
|
|
std::byte {15},
|
|
};
|
|
UUID m_d {m_raw};
|
|
};
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, DumpingRawAndConstructAnUUIDWithItShouldGiveTheSameUUID)
|
|
{
|
|
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_a.ToBytes();
|
|
EXPECT_EQ(m_a, UUID {raw});
|
|
|
|
raw = m_b.ToBytes();
|
|
EXPECT_EQ(m_b, UUID {raw});
|
|
|
|
raw = m_d.ToBytes();
|
|
EXPECT_EQ(m_d, UUID {raw});
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, ValidIDFromStringShouldBeEqualToString)
|
|
{
|
|
EXPECT_EQ(m_b.ToString(), "47183823-2574-4bfd-b411-99ed177d3e43");
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, InvalidIDFromStringShouldNotBeEqualToString)
|
|
{
|
|
EXPECT_NE(m_c.ToString(), "4bfd-b411-99ed177d3e43");
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, NullIDStringShouldBeEqualToNullIDString)
|
|
{
|
|
EXPECT_EQ(UUID::NULL_UUID.ToString(), "00000000-0000-0000-0000-000000000000");
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, DefaultConstructedIDShouldBeValid)
|
|
{
|
|
EXPECT_TRUE(m_a);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, StringConstructedIDFromAValidStringShouldBeValid)
|
|
{
|
|
EXPECT_TRUE(m_b);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, StringConstructedIDFromAnInvalidStringShouldBeInvalid)
|
|
{
|
|
EXPECT_FALSE(m_c);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, RawConstructedIDShouldBeValid)
|
|
{
|
|
EXPECT_TRUE(m_d);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, ConstructingFromRawShouldAlwaysGiveTheSameUUID)
|
|
{
|
|
EXPECT_EQ(m_d, UUID {"00010203-0405-0607-0809-0a0b0c0d0e0f"});
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, NullIDShouldNotBeValid)
|
|
{
|
|
EXPECT_FALSE(UUID::NULL_UUID);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, IDShouldBeEqualToItself)
|
|
{
|
|
EXPECT_EQ(m_a, m_a);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, IDConstructedFromOtherIDShouldBeEqual)
|
|
{
|
|
EXPECT_EQ(m_a, UUID {m_a});
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, IDCopiedFromOtherIDShouldBeEqual)
|
|
{
|
|
const UUID m_aDuplicate = m_a;
|
|
EXPECT_EQ(m_a, m_aDuplicate);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, ValidIDsShouldNotBeEqualToNullID)
|
|
{
|
|
EXPECT_NE(m_a, UUID::NULL_UUID);
|
|
EXPECT_NE(m_b, UUID::NULL_UUID);
|
|
EXPECT_NE(m_d, UUID::NULL_UUID);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, InvalidIDsShouldBeEqualToNullID)
|
|
{
|
|
EXPECT_EQ(m_c, UUID::NULL_UUID);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, GeneratingFiveMillionUniqueID)
|
|
{
|
|
ankerl::unordered_dense::set<UUID> m_ids;
|
|
|
|
for (std::uint32_t index = 0; index < 5'000'000; ++index)
|
|
{
|
|
EXPECT_TRUE(m_ids.insert(UUID {}).second);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, ToBytes_ShouldGiveBackTheRawDataOfTheID)
|
|
{
|
|
std::span<const std::byte, UUID::UUID_BYTE_SIZE> d = m_d.ToBytes();
|
|
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_raw;
|
|
|
|
EXPECT_THAT(d, ::testing::ElementsAreArray(raw));
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, Pack_ShouldGiveAFlatUUIDWithTheSameRawBytes)
|
|
{
|
|
const ::Flat::Bigfoot::UUID flatUUID = flatbuffers::Pack(m_d);
|
|
|
|
for (std::uint32_t i = 0; i < UUID::UUID_BYTE_SIZE; ++i)
|
|
{
|
|
EXPECT_EQ(std::byte {(*flatUUID.bytes())[i]}, m_raw[i]);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, UnPack_ShouldGiveBackTheOriginalUUID)
|
|
{
|
|
const ::Flat::Bigfoot::UUID flatUUID = flatbuffers::Pack(m_d);
|
|
EXPECT_EQ(flatbuffers::UnPack(flatUUID), m_d);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
TEST_F(UUIDFixture, FormatsUUID)
|
|
{
|
|
EXPECT_EQ(fmt::format("{}", m_b), m_b.ToString());
|
|
EXPECT_EQ(fmt::format("{}", UUID::NULL_UUID), "00000000-0000-0000-0000-000000000000");
|
|
}
|
|
} // namespace Bigfoot
|