|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +#include "pch.h" |
| 5 | + |
| 6 | +#include "../TerminalSettingsModel/ColorScheme.h" |
| 7 | +#include "../TerminalSettingsModel/CascadiaSettings.h" |
| 8 | +#include "JsonTestClass.h" |
| 9 | +#include "TestUtils.h" |
| 10 | +#include <defaults.h> |
| 11 | +#include "../ut_app/TestDynamicProfileGenerator.h" |
| 12 | + |
| 13 | +using namespace Microsoft::Console; |
| 14 | +using namespace WEX::Logging; |
| 15 | +using namespace WEX::TestExecution; |
| 16 | +using namespace WEX::Common; |
| 17 | +using namespace winrt::Microsoft::Terminal::Settings::Model; |
| 18 | +using namespace winrt::Microsoft::Terminal::TerminalControl; |
| 19 | + |
| 20 | +namespace SettingsModelLocalTests |
| 21 | +{ |
| 22 | + // TODO:microsoft/terminal#3838: |
| 23 | + // Unfortunately, these tests _WILL NOT_ work in our CI. We're waiting for |
| 24 | + // an updated TAEF that will let us install framework packages when the test |
| 25 | + // package is deployed. Until then, these tests won't deploy in CI. |
| 26 | + |
| 27 | + class SerializationTests : public JsonTestClass |
| 28 | + { |
| 29 | + // Use a custom AppxManifest to ensure that we can activate winrt types |
| 30 | + // from our test. This property will tell taef to manually use this as |
| 31 | + // the AppxManifest for this test class. |
| 32 | + // This does not yet work for anything XAML-y. See TabTests.cpp for more |
| 33 | + // details on that. |
| 34 | + BEGIN_TEST_CLASS(SerializationTests) |
| 35 | + TEST_CLASS_PROPERTY(L"RunAs", L"UAP") |
| 36 | + TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TestHostAppXManifest.xml") |
| 37 | + END_TEST_CLASS() |
| 38 | + |
| 39 | + TEST_METHOD(GlobalSettings); |
| 40 | + TEST_METHOD(Profile); |
| 41 | + TEST_METHOD(ColorScheme); |
| 42 | + TEST_METHOD(CascadiaSettings); |
| 43 | + |
| 44 | + TEST_CLASS_SETUP(ClassSetup) |
| 45 | + { |
| 46 | + InitializeJsonReader(); |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + private: |
| 51 | + std::string toString(const Json::Value& json) |
| 52 | + { |
| 53 | + // set indentation to empty string to remove newlines |
| 54 | + // enableYAMLCompatibility adds a space after ':' |
| 55 | + Json::StreamWriterBuilder builder; |
| 56 | + builder["indentation"] = ""; |
| 57 | + builder["enableYAMLCompatibility"] = true; |
| 58 | + return Json::writeString(builder, json); |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + void SerializationTests::GlobalSettings() |
| 63 | + { |
| 64 | + DebugBreak(); |
| 65 | + // This needs to be in alphabetical order. |
| 66 | + const std::string globalsString{ |
| 67 | + "{" |
| 68 | + "\"alwaysOnTop\": false," |
| 69 | + "\"alwaysShowTabs\": true," |
| 70 | + "\"confirmCloseAllTabs\": true," |
| 71 | + "\"copyFormatting\": \"all\"," |
| 72 | + "\"copyOnSelect\": false," |
| 73 | + "\"debugFeatures\": true," |
| 74 | + "\"defaultProfile\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\"," |
| 75 | + "\"experimental.input.forceVT\": false," |
| 76 | + "\"experimental.rendering.forceFullRepaint\": false," |
| 77 | + "\"experimental.rendering.software\": false," |
| 78 | + "\"initialCols\": 120," |
| 79 | + "\"initialPosition\": \",\"," |
| 80 | + "\"initialRows\": 30," |
| 81 | + "\"largePasteWarning\": true," |
| 82 | + "\"launchMode\": \"default\"," |
| 83 | + "\"multiLinePasteWarning\": true," |
| 84 | + "\"showTabsInTitlebar\": true," |
| 85 | + "\"showTerminalTitleInTitlebar\": true," |
| 86 | + "\"snapToGridOnResize\": true," |
| 87 | + "\"startOnUserLogin\": false," |
| 88 | + "\"tabWidthMode\": \"equal\"," |
| 89 | + "\"theme\": \"system\"," |
| 90 | + "\"useTabSwitcher\": true," |
| 91 | + "\"wordDelimiters\": \" /\\\\()\\\"'-.,:;<>~!@#$%^&*|+=[]{}~?\\u2502\"" |
| 92 | + "}" |
| 93 | + }; |
| 94 | + |
| 95 | + const std::string smallGlobalsString{ |
| 96 | + "{" |
| 97 | + "\"defaultProfile\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\"" |
| 98 | + "}" |
| 99 | + }; |
| 100 | + |
| 101 | + auto roundtripTest = [this](auto jsonString) { |
| 102 | + const auto json{ VerifyParseSucceeded(jsonString) }; |
| 103 | + const auto globals{ implementation::GlobalAppSettings::FromJson(json) }; |
| 104 | + |
| 105 | + const auto result{ globals->ToJson() }; |
| 106 | + |
| 107 | + VERIFY_ARE_EQUAL(jsonString, toString(result)); |
| 108 | + }; |
| 109 | + |
| 110 | + roundtripTest(globalsString); |
| 111 | + roundtripTest(smallGlobalsString); |
| 112 | + } |
| 113 | + |
| 114 | + void SerializationTests::Profile() |
| 115 | + { |
| 116 | + DebugBreak(); |
| 117 | + const std::string profileString{ |
| 118 | + "{" |
| 119 | + "\"name\": \"Windows PowerShell\"," |
| 120 | + "\"guid\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\"," |
| 121 | + "\"hidden\": false," |
| 122 | + "\"foreground\": \"#AABBCC\"," |
| 123 | + "\"background\": \"#BBCCAA\"," |
| 124 | + "\"selectionBackground\": \"#CCAABB\"," |
| 125 | + "\"cursorColor\": \"#CCBBAA\"," |
| 126 | + "\"colorScheme\": \"Campbell\"," |
| 127 | + "\"historySize\": 9001," |
| 128 | + "\"snapOnInput\": true," |
| 129 | + "\"altGrAliasing\": true," |
| 130 | + "\"cursorHeight\": null," |
| 131 | + "\"cursorShape\": \"bar\"," |
| 132 | + "\"tabTitle\": null," |
| 133 | + "\"fontWeight\": \"normal\"," |
| 134 | + //"\"connectionType\": null," |
| 135 | + "\"commandline\": \"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\"," |
| 136 | + "\"fontFace\": \"Cascadia Mono\"," |
| 137 | + "\"fontSize\": 12," |
| 138 | + "\"useAcrylic\": false," |
| 139 | + "\"suppressApplicationTitle\": false," |
| 140 | + "\"closeOnExit\": \"graceful\"," |
| 141 | + "\"padding\": \"8, 8, 8, 8\"," |
| 142 | + "\"scrollbarState\": \"visible\"," |
| 143 | + "\"startingDirectory\": \"%USERPROFILE%\"," |
| 144 | + "\"icon\": \"ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png\"," |
| 145 | + "\"backgroundImage\": null," |
| 146 | + "\"backgroundImageOpacity\": 1.0," |
| 147 | + "\"backgroundImageStretchMode\": \"uniformToFill\"," |
| 148 | + "\"backgroundImageAlignment\": \"center\"," |
| 149 | + "\"experimental.retroTerminalEffect\": false," |
| 150 | + "\"antialiasingMode\": \"grayscale\"" |
| 151 | + "\"tabColor\": \"#0C0C0C\"," |
| 152 | + "}" |
| 153 | + }; |
| 154 | + |
| 155 | + const std::string smallProfileString{ |
| 156 | + "{" |
| 157 | + "\"name\": \"Custom Profile\"" |
| 158 | + "}" |
| 159 | + }; |
| 160 | + |
| 161 | + auto roundtripTest = [this](auto jsonString) { |
| 162 | + const auto json{ VerifyParseSucceeded(jsonString) }; |
| 163 | + const auto globals{ implementation::Profile::FromJson(json) }; |
| 164 | + |
| 165 | + const auto result{ globals->ToJson() }; |
| 166 | + |
| 167 | + VERIFY_ARE_EQUAL(jsonString, toString(result)); |
| 168 | + }; |
| 169 | + |
| 170 | + roundtripTest(profileString); |
| 171 | + roundtripTest(smallProfileString); |
| 172 | + } |
| 173 | + |
| 174 | + void SerializationTests::ColorScheme() |
| 175 | + { |
| 176 | + DebugBreak(); |
| 177 | + const std::string schemeString{ "{" |
| 178 | + "\"name\" : \"Campbell\"," |
| 179 | + "\"foreground\" : \"#F2F2F2\"," |
| 180 | + "\"background\" : \"#0C0C0C\"," |
| 181 | + "\"selectionBackground\" : \"#131313\"," |
| 182 | + "\"cursorColor\" : \"#FFFFFF\"," |
| 183 | + "\"black\" : \"#0C0C0C\"," |
| 184 | + "\"red\" : \"#C50F1F\"," |
| 185 | + "\"green\" : \"#13A10E\"," |
| 186 | + "\"yellow\" : \"#C19C00\"" |
| 187 | + "\"blue\" : \"#0037DA\"," |
| 188 | + "\"purple\" : \"#881798\"," |
| 189 | + "\"cyan\" : \"#3A96DD\"," |
| 190 | + "\"white\" : \"#CCCCCC\"," |
| 191 | + "\"brightBlack\" : \"#767676\"," |
| 192 | + "\"brightRed\" : \"#E74856\"," |
| 193 | + "\"brightGreen\" : \"#16C60C\"," |
| 194 | + "\"brightYellow\" : \"#F9F1A5\"," |
| 195 | + "\"brightBlue\" : \"#3B78FF\"," |
| 196 | + "\"brightPurple\" : \"#B4009E\"," |
| 197 | + "\"brightCyan\" : \"#61D6D6\"," |
| 198 | + "\"brightWhite\" : \"#F2F2F2\"" |
| 199 | + "}" }; |
| 200 | + |
| 201 | + const auto json{ VerifyParseSucceeded(schemeString) }; |
| 202 | + const auto profile{ implementation::ColorScheme::FromJson(json) }; |
| 203 | + |
| 204 | + const auto result{ profile->ToJson() }; |
| 205 | + VERIFY_ARE_EQUAL(json, result); |
| 206 | + } |
| 207 | + |
| 208 | + void SerializationTests::CascadiaSettings() |
| 209 | + { |
| 210 | + DebugBreak(); |
| 211 | + const std::string settingsString{ "" }; |
| 212 | + |
| 213 | + const auto json{ VerifyParseSucceeded(settingsString) }; |
| 214 | + const auto settings{ implementation::CascadiaSettings::FromJson(json) }; |
| 215 | + |
| 216 | + const auto result{ settings->ToJson() }; |
| 217 | + VERIFY_ARE_EQUAL(json, result); |
| 218 | + } |
| 219 | +} |
0 commit comments