66#include " ..\..\inc\consoletaeftemplates.hpp"
77
88#include " ..\inc\utils.hpp"
9+ #include < conattrs.hpp>
910
1011using namespace WEX ::Common;
1112using namespace WEX ::Logging;
@@ -17,28 +18,60 @@ class UtilsTests
1718{
1819 TEST_CLASS (UtilsTests);
1920
20- TEST_METHOD (TestClampToShortMax)
21- {
22- const short min = 1 ;
23-
24- // Test outside the lower end of the range
25- const short minExpected = min;
26- auto minActual = ClampToShortMax (0 , min);
27- VERIFY_ARE_EQUAL (minExpected, minActual);
28-
29- // Test negative numbers
30- const short negativeExpected = min;
31- auto negativeActual = ClampToShortMax (-1 , min);
32- VERIFY_ARE_EQUAL (negativeExpected, negativeActual);
33-
34- // Test outside the upper end of the range
35- const short maxExpected = SHRT_MAX ;
36- auto maxActual = ClampToShortMax (50000 , min);
37- VERIFY_ARE_EQUAL (maxExpected, maxActual);
38-
39- // Test within the range
40- const short withinRangeExpected = 100 ;
41- auto withinRangeActual = ClampToShortMax (withinRangeExpected, min);
42- VERIFY_ARE_EQUAL (withinRangeExpected, withinRangeActual);
43- }
21+ TEST_METHOD (TestClampToShortMax);
22+ TEST_METHOD (TestSwapColorPalette);
4423};
24+
25+ void UtilsTests::TestClampToShortMax ()
26+ {
27+ const short min = 1 ;
28+
29+ // Test outside the lower end of the range
30+ const short minExpected = min;
31+ auto minActual = ClampToShortMax (0 , min);
32+ VERIFY_ARE_EQUAL (minExpected, minActual);
33+
34+ // Test negative numbers
35+ const short negativeExpected = min;
36+ auto negativeActual = ClampToShortMax (-1 , min);
37+ VERIFY_ARE_EQUAL (negativeExpected, negativeActual);
38+
39+ // Test outside the upper end of the range
40+ const short maxExpected = SHRT_MAX ;
41+ auto maxActual = ClampToShortMax (50000 , min);
42+ VERIFY_ARE_EQUAL (maxExpected, maxActual);
43+
44+ // Test within the range
45+ const short withinRangeExpected = 100 ;
46+ auto withinRangeActual = ClampToShortMax (withinRangeExpected, min);
47+ VERIFY_ARE_EQUAL (withinRangeExpected, withinRangeActual);
48+ }
49+ void UtilsTests::TestSwapColorPalette ()
50+ {
51+ std::array<COLORREF , COLOR_TABLE_SIZE > terminalTable;
52+ std::array<COLORREF , COLOR_TABLE_SIZE > consoleTable;
53+
54+ gsl::span<COLORREF > terminalTableView = { &terminalTable[0 ], gsl::narrow<ptrdiff_t >(terminalTable.size ()) };
55+ gsl::span<COLORREF > consoleTableleView = { &consoleTable[0 ], gsl::narrow<ptrdiff_t >(consoleTable.size ()) };
56+
57+ // First set up the colors
58+ InitializeCampbellColorTable (terminalTableView);
59+ InitializeCampbellColorTableForConhost (consoleTableleView);
60+
61+ VERIFY_ARE_EQUAL (terminalTable[0 ], consoleTable[0 ]);
62+ VERIFY_ARE_EQUAL (terminalTable[1 ], consoleTable[4 ]);
63+ VERIFY_ARE_EQUAL (terminalTable[2 ], consoleTable[2 ]);
64+ VERIFY_ARE_EQUAL (terminalTable[3 ], consoleTable[6 ]);
65+ VERIFY_ARE_EQUAL (terminalTable[4 ], consoleTable[1 ]);
66+ VERIFY_ARE_EQUAL (terminalTable[5 ], consoleTable[5 ]);
67+ VERIFY_ARE_EQUAL (terminalTable[6 ], consoleTable[3 ]);
68+ VERIFY_ARE_EQUAL (terminalTable[7 ], consoleTable[7 ]);
69+ VERIFY_ARE_EQUAL (terminalTable[8 ], consoleTable[8 ]);
70+ VERIFY_ARE_EQUAL (terminalTable[9 ], consoleTable[12 ]);
71+ VERIFY_ARE_EQUAL (terminalTable[10 ], consoleTable[10 ]);
72+ VERIFY_ARE_EQUAL (terminalTable[11 ], consoleTable[14 ]);
73+ VERIFY_ARE_EQUAL (terminalTable[12 ], consoleTable[9 ]);
74+ VERIFY_ARE_EQUAL (terminalTable[13 ], consoleTable[13 ]);
75+ VERIFY_ARE_EQUAL (terminalTable[14 ], consoleTable[11 ]);
76+ VERIFY_ARE_EQUAL (terminalTable[15 ], consoleTable[15 ]);
77+ }
0 commit comments