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 Serializer to CascadiaSettings #8018

Merged
25 commits merged into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
48d8d06
Add Serializer to CascadiaSettings
carlos-zamora Oct 22, 2020
a3695fa
fix up new tests (mostly)
carlos-zamora Oct 23, 2020
5db3d03
only perform guid generation in getter
carlos-zamora Oct 27, 2020
8ba6394
serialize hidden shells
carlos-zamora Oct 27, 2020
e6b1bef
Revert "serialize hidden shells"
carlos-zamora Oct 28, 2020
fda5ddd
fix tests
carlos-zamora Oct 28, 2020
5833bb9
polish
carlos-zamora Oct 28, 2020
df10fc4
fix unit test
carlos-zamora Oct 28, 2020
6bb948f
add Export()
carlos-zamora Oct 28, 2020
4377296
address Mike's PR comments
carlos-zamora Oct 29, 2020
917679b
address Niksa + Griese PR comments
carlos-zamora Oct 30, 2020
f6ad218
only write backup if none exists
carlos-zamora Nov 4, 2020
31dd278
use CREATE_NEW to make this more right
carlos-zamora Nov 4, 2020
396c1a1
work with miniksa to make this look right
carlos-zamora Nov 4, 2020
c4f2733
timestamp the backup file
carlos-zamora Nov 6, 2020
dd04469
remove a semicolon
carlos-zamora Nov 6, 2020
c51f9b4
make timestamp look right
carlos-zamora Nov 6, 2020
92dc467
Merge branch 'dev/cazamor/tsm/serialization' of https://github.com/mi…
carlos-zamora Nov 6, 2020
29f7769
spellcheck
carlos-zamora Nov 6, 2020
8db53af
Merge branch 'main' into dev/cazamor/tsm/serialization
carlos-zamora Nov 6, 2020
125860e
propagate 'useTabSwitcher'-->'tabSwitcherMode' change
carlos-zamora Nov 6, 2020
ecf88ae
Merge remote-tracking branch 'origin/main' into dev/cazamor/tsm/seria…
DHowett Nov 9, 2020
4c058e2
remove unnecessary comment
carlos-zamora Nov 11, 2020
0c5aedb
polish writing settings to disk (verified)
carlos-zamora Nov 13, 2020
5d7fc4a
deserialize source
carlos-zamora Nov 13, 2020
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
1 change: 1 addition & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ IObject
IStorage
LCID
llabs
localtime
lround
LSHIFT
msappx
Expand Down
1 change: 1 addition & 0 deletions .github/actions/spell-check/dictionary/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418872,6 +418872,7 @@ time-shrouded
time-space
time-spirit
timestamp
timestamped
timestamps
timet
time-table
Expand Down
10 changes: 5 additions & 5 deletions src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ namespace SettingsModelLocalTests
VERIFY_ARE_EQUAL(0u, settings->_warnings.Size());
VERIFY_ARE_EQUAL(2u, settings->_allProfiles.Size());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(0).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_FALSE(settings->_allProfiles.GetAt(1).HasGuid());
}

void DeserializationTests::TestReorderWithNullGuids()
Expand Down Expand Up @@ -935,7 +935,7 @@ namespace SettingsModelLocalTests
VERIFY_ARE_EQUAL(0u, settings->_warnings.Size());
VERIFY_ARE_EQUAL(4u, settings->_allProfiles.Size());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(0).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_FALSE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(2).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(3).HasGuid());
VERIFY_ARE_EQUAL(L"profile0", settings->_allProfiles.GetAt(0).Name());
Expand Down Expand Up @@ -1036,7 +1036,7 @@ namespace SettingsModelLocalTests
VERIFY_ARE_EQUAL(0u, settings->_warnings.Size());
VERIFY_ARE_EQUAL(4u, settings->_allProfiles.Size());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(0).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_FALSE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(2).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(3).HasGuid());
VERIFY_ARE_EQUAL(L"Command Prompt", settings->_allProfiles.GetAt(0).Name());
Expand Down Expand Up @@ -1190,8 +1190,8 @@ namespace SettingsModelLocalTests

VERIFY_ARE_EQUAL(5u, settings->_allProfiles.Size());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(0).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(2).HasGuid());
VERIFY_IS_FALSE(settings->_allProfiles.GetAt(1).HasGuid());
VERIFY_IS_FALSE(settings->_allProfiles.GetAt(2).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(3).HasGuid());
VERIFY_IS_TRUE(settings->_allProfiles.GetAt(4).HasGuid());
VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings->_allProfiles.GetAt(0).Name());
Expand Down
14 changes: 14 additions & 0 deletions src/cascadia/LocalTests_SettingsModel/JsonTestClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class JsonTestClass
{
_reader = std::unique_ptr<Json::CharReader>(Json::CharReaderBuilder::CharReaderBuilder().newCharReader());
};

void InitializeJsonWriter()
{
_writer = std::unique_ptr<Json::StreamWriter>(Json::StreamWriterBuilder::StreamWriterBuilder().newStreamWriter());
}

Json::Value VerifyParseSucceeded(std::string content)
{
Json::Value root;
Expand All @@ -31,6 +37,14 @@ class JsonTestClass
return root;
};

std::string toString(const Json::Value& json)
{
std::stringstream s;
_writer->write(json, &s);
return s.str();
}

protected:
std::unique_ptr<Json::CharReader> _reader;
std::unique_ptr<Json::StreamWriter> _writer;
};
295 changes: 295 additions & 0 deletions src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"

#include "../TerminalSettingsModel/ColorScheme.h"
#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "JsonTestClass.h"
#include "TestUtils.h"
#include <defaults.h>
#include "../ut_app/TestDynamicProfileGenerator.h"

using namespace Microsoft::Console;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
using namespace WEX::Common;
using namespace winrt::Microsoft::Terminal::Settings::Model;
using namespace winrt::Microsoft::Terminal::TerminalControl;

namespace SettingsModelLocalTests
{
// TODO:microsoft/terminal#3838:
// Unfortunately, these tests _WILL NOT_ work in our CI. We're waiting for
// an updated TAEF that will let us install framework packages when the test
// package is deployed. Until then, these tests won't deploy in CI.
Comment on lines +22 to +25
Copy link
Member

Choose a reason for hiding this comment

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

FYI, we can do this now. Did you check whether these tests work in our CI or not? I swear I put this module on in CI.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like none of the helix tests are running.


class SerializationTests : public JsonTestClass
{
// Use a custom AppxManifest to ensure that we can activate winrt types
// from our test. This property will tell taef to manually use this as
// the AppxManifest for this test class.
// This does not yet work for anything XAML-y. See TabTests.cpp for more
// details on that.
BEGIN_TEST_CLASS(SerializationTests)
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TestHostAppXManifest.xml")
END_TEST_CLASS()

TEST_METHOD(GlobalSettings);
TEST_METHOD(Profile);
TEST_METHOD(ColorScheme);
TEST_METHOD(CascadiaSettings);

TEST_CLASS_SETUP(ClassSetup)
{
InitializeJsonReader();
InitializeJsonWriter();
return true;
}

private:
// Method Description:
// - deserializes and reserializes a json string representing a settings object model of type T
// - verifies that the generated json string matches the provided one
// Template Types:
// - <T>: The type of Settings Model object to generate (must be impl type)
// Arguments:
// - jsonString - JSON string we're performing the test on
// Return Value:
// - the JsonObject representing this instance
template<typename T>
void RoundtripTest(const std::string& jsonString)
{
const auto json{ VerifyParseSucceeded(jsonString) };
const auto settings{ T::FromJson(json) };
const auto result{ settings->ToJson() };

// Compare toString(json) instead of jsonString here.
// The toString writes the json out alphabetically.
// This trick allows jsonString to _not_ have to be
// written alphabetically.
VERIFY_ARE_EQUAL(toString(json), toString(result));
}
};

void SerializationTests::GlobalSettings()
{
const std::string globalsString{ R"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

"initialRows": 30,
"initialCols": 120,
"initialPosition": ",",
"launchMode": "default",
"alwaysOnTop": false,

"copyOnSelect": false,
"copyFormatting": "all",
"wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",

"alwaysShowTabs": true,
"showTabsInTitlebar": true,
"showTerminalTitleInTitlebar": true,
"tabWidthMode": "equal",
"tabSwitcherMode": "mru",

"startOnUserLogin": false,
"theme": "system",
"snapToGridOnResize": true,
"disableAnimations": false,

"confirmCloseAllTabs": true,
"largePasteWarning": true,
"multiLinePasteWarning": true,

"experimental.input.forceVT": false,
"experimental.rendering.forceFullRepaint": false,
"experimental.rendering.software": false
})" };

const std::string smallGlobalsString{ R"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"
})" };

RoundtripTest<implementation::GlobalAppSettings>(globalsString);
RoundtripTest<implementation::GlobalAppSettings>(smallGlobalsString);
}

void SerializationTests::Profile()
{
const std::string profileString{ R"(
{
"name": "Windows PowerShell",
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"startingDirectory": "%USERPROFILE%",

"icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"hidden": false,

"tabTitle": "Cool Tab",
"suppressApplicationTitle": false,

"fontFace": "Cascadia Mono",
"fontSize": 12,
"fontWeight": "normal",
"padding": "8, 8, 8, 8",
"antialiasingMode": "grayscale",

"cursorShape": "bar",
"cursorColor": "#CCBBAA",
"cursorHeight": 10,

"altGrAliasing": true,

"colorScheme": "Campbell",
"tabColor": "#0C0C0C",
"foreground": "#AABBCC",
"background": "#BBCCAA",
"selectionBackground": "#CCAABB",

"useAcrylic": false,
"acrylicOpacity": 0.5,

"backgroundImage": "made_you_look.jpeg",
"backgroundImageStretchMode": "uniformToFill",
"backgroundImageAlignment": "center",
"backgroundImageOpacity": 1.0,

"scrollbarState": "visible",
"snapOnInput": true,
"historySize": 9001,

"closeOnExit": "graceful",
"experimental.retroTerminalEffect": false
})" };

const std::string smallProfileString{ R"(
{
"name": "Custom Profile"
})" };

// Setting "tabColor" to null tests two things:
// - null should count as an explicit user-set value, not falling back to the parent's value
// - null should be acceptable even though we're working with colors
const std::string weirdProfileString{ R"(
{
"name": "Weird Profile",
"tabColor": null,
"foreground": null,
"source": "local"
})" };

RoundtripTest<implementation::Profile>(profileString);
RoundtripTest<implementation::Profile>(smallProfileString);
RoundtripTest<implementation::Profile>(weirdProfileString);
}

void SerializationTests::ColorScheme()
{
const std::string schemeString{ R"({
"name": "Campbell",

"cursorColor": "#FFFFFF",
"selectionBackground": "#131313",

"background": "#0C0C0C",
"foreground": "#F2F2F2",

"black": "#0C0C0C",
"blue": "#0037DA",
"cyan": "#3A96DD",
"green": "#13A10E",
"purple": "#881798",
"red": "#C50F1F",
"white": "#CCCCCC",
"yellow": "#C19C00",
"brightBlack": "#767676",
"brightBlue": "#3B78FF",
"brightCyan": "#61D6D6",
"brightGreen": "#16C60C",
"brightPurple": "#B4009E",
"brightRed": "#E74856",
"brightWhite": "#F2F2F2",
"brightYellow": "#F9F1A5"
})" };

RoundtripTest<implementation::ColorScheme>(schemeString);
}

void SerializationTests::CascadiaSettings()
{
const std::string settingsString{ R"({
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-1111-5271-96e7-009a87ff44bf}",

"profiles": {
"defaults": {
"fontFace": "Zamora Code"
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
},
"list": [
{
"fontFace": "Cascadia Code",
"guid": "{61c54bbd-1111-5271-96e7-009a87ff44bf}",
"name": "HowettShell"
},
{
"hidden": true,
"name": "BhojwaniShell"
},
{
"antialiasingMode": "aliased",
"name": "NiksaShell"
}
]
},
"schemes": [
{
"name": "Cinnamon Roll",

"cursorColor": "#FFFFFD",
"selectionBackground": "#FFFFFF",

"background": "#3C0315",
"foreground": "#FFFFFD",

"black": "#282A2E",
"blue": "#0170C5",
"cyan": "#3F8D83",
"green": "#76AB23",
"purple": "#7D498F",
"red": "#BD0940",
"white": "#FFFFFD",
"yellow": "#E0DE48",
"brightBlack": "#676E7A",
"brightBlue": "#5C98C5",
"brightCyan": "#8ABEB7",
"brightGreen": "#B5D680",
"brightPurple": "#AC79BB",
"brightRed": "#BD6D85",
"brightWhite": "#FFFFFD",
"brightYellow": "#FFFD76"
}
],
"actions": [
{"command": { "action": "renameTab","input": "Liang Tab" },"keys": "ctrl+t" }
],
"keybindings": [
{ "command": { "action": "sendInput","input": "VT Griese Mode" },"keys": "ctrl+k" }
]
Comment on lines +278 to +283
Copy link
Member

Choose a reason for hiding this comment

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

Wait how the heck does this pass if the keybindings aren't getting re-serialized?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. We actually copy the Json::Value for actions/keybindings. Then when we serialize our settings, we put them back in.

})" };

auto settings{ winrt::make_self<implementation::CascadiaSettings>(false) };
settings->_ParseJsonString(settingsString, false);
settings->_ApplyDefaultsFromUserSettings();
settings->LayerJson(settings->_userSettings);
settings->_ValidateSettings();

const auto result{ settings->ToJson() };
VERIFY_ARE_EQUAL(toString(settings->_userSettings), toString(result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ClCompile Include="KeyBindingsTests.cpp" />
<ClCompile Include="CommandTests.cpp" />
<ClCompile Include="DeserializationTests.cpp" />
<ClCompile Include="SerializationTests.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down
Loading