1
0

Fix cUUID::Variant (#4213)

This commit is contained in:
peterbell10 2018-04-07 23:20:53 +01:00 committed by Mattes D
parent f4a1ebd880
commit 1e312296cc
2 changed files with 32 additions and 3 deletions

View File

@ -178,7 +178,7 @@ UInt8 cUUID::Version() const
UInt8 cUUID::Variant() const UInt8 cUUID::Variant() const
{ {
const Byte VariantBits = static_cast<Byte>((m_UUID[9] >> 5) & 0x07); const Byte VariantBits = static_cast<Byte>((m_UUID[8] >> 5) & 0x07);
/* Variant bits format: /* Variant bits format:
bits | variant | Description bits | variant | Description

View File

@ -10,7 +10,8 @@
/** Test that FromString -> ToShortString preserves the original value for short UUIDs. */ /** Test that FromString -> ToShortString preserves the original value for short UUIDs. */
static void UUIDFromStringToShortString() static void UUIDFromStringToShortString()
{ {
const char TestStrings[][33]{ const char TestStrings[][33]
{
"0123456789abcdef0123456789ABCDEF", "0123456789abcdef0123456789ABCDEF",
"d188b2648cc311e7bb31be2e44b06b34", "d188b2648cc311e7bb31be2e44b06b34",
"e760d270d8b34288b895d9f78a31e083", "e760d270d8b34288b895d9f78a31e083",
@ -38,7 +39,8 @@ static void UUIDFromStringToShortString()
/** Test that FromString -> ToLongString preserves the original value for long UUIDs. */ /** Test that FromString -> ToLongString preserves the original value for long UUIDs. */
static void UUIDFromStringToLongString() static void UUIDFromStringToLongString()
{ {
const char TestStrings[][37]{ const char TestStrings[][37]
{
"01234567-89ab-cdef-0123-456789ABCDEF", "01234567-89ab-cdef-0123-456789ABCDEF",
"d188b264-8cc3-11e7-bb31-be2e44b06b34", "d188b264-8cc3-11e7-bb31-be2e44b06b34",
"e760d270-d8b3-4288-b895-d9f78a31e083", "e760d270-d8b3-4288-b895-d9f78a31e083",
@ -108,6 +110,30 @@ static void UUIDNil()
/** Test that variant and version numbers are read correctly. */
static void UUIDType()
{
// From issue #4209
const char TestStrings[][33]
{
"31cfcbeea8f2324a86dbccb1d5aaa6f8",
"3f2e1dd234a03b6b824c5a0e74083b1e"
};
for (const auto & String : TestStrings)
{
cUUID UUID;
assert_test(UUID.FromString(String));
assert_test(UUID.Variant() == 1);
assert_test(UUID.Version() == 3);
}
}
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
LOG("UUID tests started"); LOG("UUID tests started");
@ -124,6 +150,9 @@ int main(int argc, char * argv[])
LOG("Testing nil UUIDs"); LOG("Testing nil UUIDs");
UUIDNil(); UUIDNil();
LOG("Testing UUID type information");
UUIDType();
LOG("UUID tests finished"); LOG("UUID tests finished");
} }