#include #include #include using namespace XCEngine::Rendering; TEST(ObjectIdEncoding_Test, ConvertsValidRuntimeObjectIdLosslessly) { constexpr uint64_t objectId = 0x00ABCDEFu; RenderObjectId renderObjectId = kInvalidRenderObjectId; EXPECT_TRUE(CanConvertRuntimeObjectIdToRenderObjectId(objectId)); EXPECT_TRUE(TryConvertRuntimeObjectIdToRenderObjectId(objectId, renderObjectId)); EXPECT_EQ(renderObjectId, 0x00ABCDEFu); EXPECT_EQ(ConvertRenderObjectIdToRuntimeObjectId(renderObjectId), objectId); } TEST(ObjectIdEncoding_Test, RejectsInvalidAndOverflowRuntimeObjectIds) { RenderObjectId renderObjectId = 123u; EXPECT_FALSE(CanConvertRuntimeObjectIdToRenderObjectId(0u)); EXPECT_FALSE(TryConvertRuntimeObjectIdToRenderObjectId(0u, renderObjectId)); EXPECT_EQ(renderObjectId, kInvalidRenderObjectId); const uint64_t overflowObjectId = static_cast(std::numeric_limits::max()) + 1ull; renderObjectId = 456u; EXPECT_FALSE(CanConvertRuntimeObjectIdToRenderObjectId(overflowObjectId)); EXPECT_FALSE(TryConvertRuntimeObjectIdToRenderObjectId(overflowObjectId, renderObjectId)); EXPECT_EQ(renderObjectId, kInvalidRenderObjectId); } TEST(ObjectIdEncoding_Test, DecodesColorBackToRenderObjectId) { constexpr uint8_t r = 0x12u; constexpr uint8_t g = 0x34u; constexpr uint8_t b = 0x56u; constexpr uint8_t a = 0x78u; EXPECT_EQ(DecodeEncodedObjectIdFromColor(r, g, b, a), 0x78563412u); EXPECT_EQ(DecodeRenderObjectIdFromColor(r, g, b, a), 0x78563412u); EXPECT_EQ(ConvertRenderObjectIdToRuntimeObjectId(DecodeRenderObjectIdFromColor(r, g, b, a)), 0x78563412ull); } TEST(ObjectIdEncoding_Test, EncodesColorChannelsFromRenderObjectId) { const auto encodedColor = EncodeRenderObjectIdToColor(0x78563412u); constexpr float kInv255 = 1.0f / 255.0f; EXPECT_FLOAT_EQ(encodedColor.x, 0x12u * kInv255); EXPECT_FLOAT_EQ(encodedColor.y, 0x34u * kInv255); EXPECT_FLOAT_EQ(encodedColor.z, 0x56u * kInv255); EXPECT_FLOAT_EQ(encodedColor.w, 0x78u * kInv255); }