[ox/std] Add test for UUID::generate() and fix bug

This commit is contained in:
Gary Talent 2023-02-13 19:08:04 -06:00
parent 86a3bf1248
commit 777a6d54f0
3 changed files with 13 additions and 1 deletions

View File

@ -22,3 +22,4 @@ add_test("[ox/std] StringSplit" StdTest "StringSplit")
add_test("[ox/std] FromHex" StdTest "FromHex") add_test("[ox/std] FromHex" StdTest "FromHex")
add_test("[ox/std] ToHex" StdTest "ToHex") add_test("[ox/std] ToHex" StdTest "ToHex")
add_test("[ox/std] UUID" StdTest "UUID") add_test("[ox/std] UUID" StdTest "UUID")
add_test("[ox/std] UUID::generate" StdTest "UUID::generate")

View File

@ -210,6 +210,16 @@ static std::map<ox::String, ox::Error(*)()> tests = {
return OxError(0); return OxError(0);
} }
}, },
{
"UUID::generate",
[] {
ox::UUID::seedGenerator({1234, 4321});
oxExpect(ox::UUID::generate().unwrap().toString(), "c8f4bff1-d403-4576-fd3b-0c41f1cd8b7d");
oxExpect(ox::UUID::generate().unwrap().toString(), "0d1b7dad-7d50-49b6-916d-c3d811b5af0a");
oxExpect(ox::UUID::generate().unwrap().toString(), "e3889e0b-4dcd-47b2-b3eb-492ea958d3e4");
return OxError(0);
}
},
{ {
"StringSplit", "StringSplit",
[] { [] {

View File

@ -27,7 +27,8 @@ Result<UUID> UUID::generate() noexcept {
for (auto &v : out.m_value) { for (auto &v : out.m_value) {
v = static_cast<uint8_t>(s_rand.gen() % 255); v = static_cast<uint8_t>(s_rand.gen() % 255);
} }
out.m_value[6] = 4; out.m_value[6] &= 0x0f;
out.m_value[6] |= 4 << 4;
return out; return out;
} }