2019-06-05 01:31:36 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
#include "WexTestClass.h"
|
|
|
|
#include "..\..\inc\consoletaeftemplates.hpp"
|
|
|
|
|
|
|
|
#include "..\inc\utils.hpp"
|
2019-07-26 00:03:00 +02:00
|
|
|
#include <conattrs.hpp>
|
2019-06-05 01:31:36 +02:00
|
|
|
|
|
|
|
using namespace WEX::Common;
|
|
|
|
using namespace WEX::Logging;
|
|
|
|
using namespace WEX::TestExecution;
|
|
|
|
|
|
|
|
using namespace Microsoft::Console::Utils;
|
|
|
|
|
|
|
|
class UtilsTests
|
|
|
|
{
|
|
|
|
TEST_CLASS(UtilsTests);
|
|
|
|
|
2019-07-26 00:03:00 +02:00
|
|
|
TEST_METHOD(TestClampToShortMax);
|
|
|
|
TEST_METHOD(TestSwapColorPalette);
|
2019-09-17 00:01:47 +02:00
|
|
|
TEST_METHOD(TestGuidToString);
|
2019-06-05 01:31:36 +02:00
|
|
|
};
|
2019-07-26 00:03:00 +02:00
|
|
|
|
|
|
|
void UtilsTests::TestClampToShortMax()
|
|
|
|
{
|
|
|
|
const short min = 1;
|
|
|
|
|
|
|
|
// Test outside the lower end of the range
|
|
|
|
const short minExpected = min;
|
|
|
|
auto minActual = ClampToShortMax(0, min);
|
|
|
|
VERIFY_ARE_EQUAL(minExpected, minActual);
|
|
|
|
|
|
|
|
// Test negative numbers
|
|
|
|
const short negativeExpected = min;
|
|
|
|
auto negativeActual = ClampToShortMax(-1, min);
|
|
|
|
VERIFY_ARE_EQUAL(negativeExpected, negativeActual);
|
|
|
|
|
|
|
|
// Test outside the upper end of the range
|
|
|
|
const short maxExpected = SHRT_MAX;
|
|
|
|
auto maxActual = ClampToShortMax(50000, min);
|
|
|
|
VERIFY_ARE_EQUAL(maxExpected, maxActual);
|
|
|
|
|
|
|
|
// Test within the range
|
|
|
|
const short withinRangeExpected = 100;
|
|
|
|
auto withinRangeActual = ClampToShortMax(withinRangeExpected, min);
|
|
|
|
VERIFY_ARE_EQUAL(withinRangeExpected, withinRangeActual);
|
|
|
|
}
|
|
|
|
void UtilsTests::TestSwapColorPalette()
|
|
|
|
{
|
|
|
|
std::array<COLORREF, COLOR_TABLE_SIZE> terminalTable;
|
|
|
|
std::array<COLORREF, COLOR_TABLE_SIZE> consoleTable;
|
|
|
|
|
2020-07-14 20:30:59 +02:00
|
|
|
gsl::span<COLORREF> terminalTableView = { &terminalTable[0], terminalTable.size() };
|
|
|
|
gsl::span<COLORREF> consoleTableView = { &consoleTable[0], consoleTable.size() };
|
2019-07-26 00:03:00 +02:00
|
|
|
|
|
|
|
// First set up the colors
|
|
|
|
InitializeCampbellColorTable(terminalTableView);
|
2019-09-03 22:02:09 +02:00
|
|
|
InitializeCampbellColorTableForConhost(consoleTableView);
|
2019-07-26 00:03:00 +02:00
|
|
|
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[0], consoleTable[0]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[1], consoleTable[4]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[2], consoleTable[2]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[3], consoleTable[6]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[4], consoleTable[1]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[5], consoleTable[5]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[6], consoleTable[3]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[7], consoleTable[7]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[8], consoleTable[8]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[9], consoleTable[12]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[10], consoleTable[10]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[11], consoleTable[14]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[12], consoleTable[9]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[13], consoleTable[13]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[14], consoleTable[11]);
|
|
|
|
VERIFY_ARE_EQUAL(terminalTable[15], consoleTable[15]);
|
|
|
|
}
|
2019-09-17 00:01:47 +02:00
|
|
|
|
|
|
|
void UtilsTests::TestGuidToString()
|
|
|
|
{
|
|
|
|
constexpr GUID constantGuid{
|
|
|
|
0x01020304, 0x0506, 0x0708, { 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 }
|
|
|
|
};
|
|
|
|
constexpr std::wstring_view constantGuidString{ L"{01020304-0506-0708-090a-0b0c0d0e0f10}" };
|
|
|
|
|
|
|
|
auto generatedGuid{ GuidToString(constantGuid) };
|
|
|
|
|
|
|
|
VERIFY_ARE_EQUAL(constantGuidString.size(), generatedGuid.size());
|
|
|
|
VERIFY_ARE_EQUAL(constantGuidString, generatedGuid);
|
|
|
|
}
|