Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more profile GUID tests #17030

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions src/cascadia/UnitTests_SettingsModel/ProfileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ namespace SettingsModelUnitTests
// this test that includes synthesizing GUIDS for profiles without GUIDs
// set

const auto parseAndVerifyProfile = [](const std::string profile, const bool hasGuid) {
const auto profileAsJson = VerifyParseSucceeded(profile);
const auto profileParsed = implementation::Profile::FromJson(profileAsJson);

VERIFY_ARE_EQUAL(profileParsed->HasGuid(), hasGuid);
return profileParsed;
};

// Invalid GUID Values
const std::string profileWithoutGuid{ R"({
"name" : "profile0"
})" };
Expand All @@ -55,37 +64,50 @@ namespace SettingsModelUnitTests
"name" : "profile2",
"guid" : null
})" };
const std::string profileWithHyphenlessGuid{ R"({
"name" : "profile4",
"guid" : "{6239A42C1DE449A380BDE8FDD045185C}"
})" };
const std::string profileWithRawGuid{ R"({
"name" : "profile4",
"guid" : "6239a42c-1de4-49a3-80bd-e8fdd045185c"
})" };
const std::string profileWithGuidFormatP{ R"({
"name" : "profile4",
"guid" : "(6239a42c-1de4-49a3-80bd-e8fdd045185c)\\"
})" };
// Valid GUIDs
const std::string profileWithNullGuid{ R"({
"name" : "profile3",
"guid" : "{00000000-0000-0000-0000-000000000000}"
})" };
const std::string profileWithGuid{ R"({
const std::string profileWithGuidFormatB{ R"({
"name" : "profile4",
"guid" : "{6239a42c-1de4-49a3-80bd-e8fdd045185c}"
})" };
const std::string profileWithGuidUpperCaseFormatB{ R"({
"name" : "profile4",
"guid" : "{6239A42C-1DE4-49A3-80BD-E8FDD045185C}"
})" };

const auto profile0Json = VerifyParseSucceeded(profileWithoutGuid);
const auto profile1Json = VerifyParseSucceeded(secondProfileWithoutGuid);
const auto profile2Json = VerifyParseSucceeded(profileWithNullForGuid);
const auto profile3Json = VerifyParseSucceeded(profileWithNullGuid);
const auto profile4Json = VerifyParseSucceeded(profileWithGuid);

const auto profile0 = implementation::Profile::FromJson(profile0Json);
const auto profile1 = implementation::Profile::FromJson(profile1Json);
const auto profile2 = implementation::Profile::FromJson(profile2Json);
const auto profile3 = implementation::Profile::FromJson(profile3Json);
const auto profile4 = implementation::Profile::FromJson(profile4Json);
const winrt::guid cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}");
const winrt::guid nullGuid{};
parseAndVerifyProfile(profileWithoutGuid, false);
parseAndVerifyProfile(secondProfileWithoutGuid, false);

VERIFY_IS_FALSE(profile0->HasGuid());
VERIFY_IS_FALSE(profile1->HasGuid());
VERIFY_IS_FALSE(profile2->HasGuid());
VERIFY_IS_TRUE(profile3->HasGuid());
VERIFY_IS_TRUE(profile4->HasGuid());
// The following crash JSON parsing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this should throw an exception which you can verify you caught with VERIFY_THROWS!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if they should crash so I left them as comment, now they are using VERIFY_THROWS (thanks for mentioning that!)

VERIFY_THROWS(parseAndVerifyProfile(profileWithHyphenlessGuid, false), std::exception);
VERIFY_THROWS(parseAndVerifyProfile(profileWithRawGuid, false), std::exception);
VERIFY_THROWS(parseAndVerifyProfile(profileWithGuidFormatP, false), std::exception);

const auto parsedNullGuidProfile = parseAndVerifyProfile(profileWithNullGuid, true);
const auto parsedGuidProfileFormatB = parseAndVerifyProfile(profileWithGuidFormatB, true);
const auto parsedGuidProfileUpperCaseFormatB = parseAndVerifyProfile(profileWithGuidUpperCaseFormatB, true);

const winrt::guid nullGuid{};
const winrt::guid cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}");

VERIFY_ARE_EQUAL(profile3->Guid(), nullGuid);
VERIFY_ARE_EQUAL(profile4->Guid(), cmdGuid);
VERIFY_ARE_EQUAL(parsedNullGuidProfile->Guid(), nullGuid);
VERIFY_ARE_EQUAL(parsedGuidProfileFormatB->Guid(), cmdGuid);
VERIFY_ARE_EQUAL(parsedGuidProfileUpperCaseFormatB->Guid(), cmdGuid);
}

void ProfileTests::LayerProfileProperties()
Expand Down
Loading