Update Uuid parameter name, and improve tests (#5943)
* Update Uuid parameter name, and improve tests * Update sdk/core/azure-core/inc/azure/core/uuid.hpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> --------- Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com> Co-authored-by: Rick Winter <rick.winter@microsoft.com>
This commit is contained in:
parent
c9d308d6d5
commit
6ae78faec8
@ -66,10 +66,10 @@ namespace Azure { namespace Core {
|
||||
|
||||
/**
|
||||
* @brief Construct a Uuid by parsing its representation.
|
||||
* @param s a string in `8-4-4-4-12` hex characters format.
|
||||
* @throw `std::invalid_argument` if \p s cannot be parsed.
|
||||
* @param uuidString a string in `8-4-4-4-12` hex characters format.
|
||||
* @throw `std::invalid_argument` if \p uuidString cannot be parsed.
|
||||
*/
|
||||
static Uuid Parse(std::string const& s);
|
||||
static Uuid Parse(std::string const& uuidString);
|
||||
|
||||
/**
|
||||
* @brief Compares with another instance of Uuid for equality.
|
||||
|
||||
@ -85,19 +85,20 @@ namespace Azure { namespace Core {
|
||||
return s;
|
||||
}
|
||||
|
||||
Uuid Uuid::Parse(std::string const& s)
|
||||
Uuid Uuid::Parse(std::string const& uuidString)
|
||||
{
|
||||
bool parseError = false;
|
||||
Uuid result;
|
||||
if (s.size() != UuidStringLength)
|
||||
if (uuidString.size() != UuidStringLength)
|
||||
{
|
||||
parseError = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// si = string index, bi = byte index
|
||||
for (size_t si = 0, bi = 0; si < UuidStringLength; ++si)
|
||||
{
|
||||
const auto c = s[si];
|
||||
const auto c = uuidString[si];
|
||||
if (IsDashIndex(si))
|
||||
{
|
||||
if (c != '-')
|
||||
@ -110,7 +111,7 @@ namespace Azure { namespace Core {
|
||||
{
|
||||
assert(si + 1 < UuidStringLength && bi < result.m_uuid.size());
|
||||
|
||||
const auto c2 = s[si + 1];
|
||||
const auto c2 = uuidString[si + 1];
|
||||
if (!StringExtensions::IsHexDigit(c) || !StringExtensions::IsHexDigit(c2))
|
||||
{
|
||||
parseError = true;
|
||||
@ -125,7 +126,7 @@ namespace Azure { namespace Core {
|
||||
}
|
||||
|
||||
return parseError ? throw std::invalid_argument(
|
||||
"Error parsing Uuid: '" + s
|
||||
"Error parsing Uuid: '" + uuidString
|
||||
+ "' is not in the '00112233-4455-6677-8899-aAbBcCdDeEfF' format.")
|
||||
: result;
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ TEST(Uuid, parse)
|
||||
// Spaces before, after, and both.
|
||||
ASSERT_THROW(Uuid::Parse("00000000-0000-0000-0000-000000000000 "), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse(" 00000000-0000-0000-0000-000000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse("00000000-0000-0000-0000-00000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse(" 00000000-0000-0000-0000-000000000000 "), std::invalid_argument);
|
||||
|
||||
// Valid characters, but in places where dashes should be
|
||||
ASSERT_THROW(Uuid::Parse("00000000a0000-0000-0000-000000000000"), std::invalid_argument);
|
||||
@ -190,11 +190,18 @@ TEST(Uuid, parse)
|
||||
Uuid::Parse("{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}"),
|
||||
std::invalid_argument);
|
||||
|
||||
// Correct characters, incorrect length.
|
||||
ASSERT_THROW(Uuid::Parse("0000000-0000-0000-0000-000000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse("00000000-000-0000-0000-000000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse("00000000-0000-000-0000-000000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse("00000000-0000-0000-000-000000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse("00000000-0000-0000-0000-00000000000"), std::invalid_argument);
|
||||
|
||||
// Correct length, invalid characters
|
||||
ASSERT_THROW(Uuid::Parse("o000000000-0000-0000-0000-000000000000"), std::invalid_argument);
|
||||
ASSERT_THROW(Uuid::Parse("0000000000-0000-0000-0000-00000000000o"), std::invalid_argument);
|
||||
|
||||
// Incorrect length, incorrect caracters
|
||||
// Incorrect length, incorrect characters
|
||||
ASSERT_THROW(Uuid::Parse("00000000-0000-0000-0000-0000000000G"), std::invalid_argument);
|
||||
|
||||
// Less dashes
|
||||
@ -244,6 +251,15 @@ TEST(Uuid, equality)
|
||||
EXPECT_FALSE(b != a);
|
||||
}
|
||||
|
||||
{
|
||||
Uuid const a = Uuid::Parse("00000000-0000-0000-0000-000000000000");
|
||||
Uuid const b = Uuid::Parse("00000000-0000-0000-0000-000000000000");
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_TRUE(b == a);
|
||||
EXPECT_FALSE(a != b);
|
||||
EXPECT_FALSE(b != a);
|
||||
}
|
||||
|
||||
{
|
||||
Uuid const a;
|
||||
Uuid const b = Uuid::Parse("00112233-4455-6677-8899-aabbccddeeff");
|
||||
@ -253,6 +269,15 @@ TEST(Uuid, equality)
|
||||
EXPECT_TRUE(b != a);
|
||||
}
|
||||
|
||||
{
|
||||
Uuid const a = Uuid::Parse("00112233-4455-6677-8899-aabbccddeeff");
|
||||
Uuid const b = Uuid::Parse("00112233-4455-6677-8899-aabbccddeeff");
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_TRUE(b == a);
|
||||
EXPECT_FALSE(a != b);
|
||||
EXPECT_FALSE(b != a);
|
||||
}
|
||||
|
||||
{
|
||||
Uuid const a = Uuid::Parse("ffeeddcc-bbaa-9988-7766-554433221100");
|
||||
Uuid const b = Uuid::Parse("00112233-4455-6677-8899-aabbccddeeff");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user