|
7 | 7 | #include "tests\RA_UnitTestHelpers.h" |
8 | 8 | #include "tests\mocks\MockEmulatorContext.hh" |
9 | 9 | #include "tests\mocks\MockGameContext.hh" |
| 10 | +#include "tests\mocks\MockConsoleContext.hh" |
10 | 11 | #include "tests\mocks\MockWindowManager.hh" |
11 | 12 |
|
12 | 13 | #undef GetMessage |
@@ -71,6 +72,9 @@ TEST_CLASS(MemoryViewerViewModel_Tests) |
71 | 72 | bool IsReadOnly() const noexcept { return m_bReadOnly; } |
72 | 73 | void SetReadOnly(bool value) noexcept { m_bReadOnly = value; } |
73 | 74 |
|
| 75 | + bool IsAddressFixed() const noexcept { return m_bAddressFixed; } |
| 76 | + void SetAddressFixed(bool value) noexcept { m_bAddressFixed = value; } |
| 77 | + |
74 | 78 | void InitializeMemory(size_t nSize) |
75 | 79 | { |
76 | 80 | unsigned char* pBytes = new unsigned char[nSize]; |
@@ -1918,8 +1922,78 @@ TEST_CLASS(MemoryViewerViewModel_Tests) |
1918 | 1922 | Assert::IsTrue(viewer.NeedsRedraw()); |
1919 | 1923 | viewer.MockRender(); |
1920 | 1924 | } |
| 1925 | + |
| 1926 | + TEST_METHOD(TestOnShiftClickEightBit) |
| 1927 | + { |
| 1928 | + ra::data::context::mocks::MockConsoleContext mockConsole(PlayStation, L"Playstation"); |
| 1929 | + |
| 1930 | + MemoryViewerViewModelHarness viewer; |
| 1931 | + viewer.InitializeMemory(128); // 8 rows of 16 bytes |
| 1932 | + viewer.mockEmulatorContext.WriteMemoryByte(0U, 0x20); |
| 1933 | + viewer.mockEmulatorContext.WriteMemoryByte(1U, 0xff); |
| 1934 | + viewer.mockEmulatorContext.WriteMemoryByte(2U, 0x0); |
| 1935 | + |
| 1936 | + Assert::AreEqual(MemSize::EightBit, viewer.GetSize()); |
| 1937 | + Assert::AreEqual({ 0U }, viewer.GetAddress()); |
| 1938 | + Assert::AreEqual({ 0U }, viewer.GetSelectedNibble()); |
| 1939 | + |
| 1940 | + // If fixed address, ignore |
| 1941 | + viewer.SetAddressFixed(true); |
| 1942 | + viewer.OnShiftClick(10 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1943 | + Assert::AreEqual({0x0U}, viewer.GetAddress()); |
| 1944 | + |
| 1945 | + // If not fixed address and Shift click on the first byte containing 0x20 should lead to address 0x20 |
| 1946 | + viewer.SetAddressFixed(false); |
| 1947 | + viewer.OnShiftClick(10 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1948 | + Assert::AreEqual({ 0x20U }, viewer.GetAddress()); |
| 1949 | + |
| 1950 | + // Shift click on the second byte containing 0xFF should lead to address 0x7F as 0xFF is bigger than the last |
| 1951 | + // address in memory |
| 1952 | + viewer.OnShiftClick(13 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1953 | + Assert::AreEqual({0x7FU}, viewer.GetAddress()); |
| 1954 | + |
| 1955 | + // Shift click on the third byte containing 0x0 should lead back to address 0x0 |
| 1956 | + viewer.OnShiftClick(16 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1957 | + Assert::AreEqual({0x0U}, viewer.GetAddress()); |
| 1958 | + } |
| 1959 | + |
| 1960 | + TEST_METHOD(TestOnShiftClickSixTeenBit) |
| 1961 | + { |
| 1962 | + ra::data::context::mocks::MockConsoleContext mockConsole(PlayStation, L"Playstation"); |
| 1963 | + |
| 1964 | + MemoryViewerViewModelHarness viewer; |
| 1965 | + viewer.InitializeMemory(512); // 32 rows of 16 bytes |
| 1966 | + viewer.SetSize(MemSize::SixteenBit); |
| 1967 | + viewer.mockEmulatorContext.WriteMemory(0U, MemSize::SixteenBit, 0x20); |
| 1968 | + viewer.mockEmulatorContext.WriteMemory(2U, MemSize::SixteenBit, 0xff); |
| 1969 | + viewer.mockEmulatorContext.WriteMemory(4U, MemSize::SixteenBit, 0xffff); |
| 1970 | + |
| 1971 | + Assert::AreEqual(MemSize::SixteenBit, viewer.GetSize()); |
| 1972 | + Assert::AreEqual({0U}, viewer.GetAddress()); |
| 1973 | + Assert::AreEqual({0U}, viewer.GetSelectedNibble()); |
| 1974 | + |
| 1975 | + // If fixed address, ignore |
| 1976 | + viewer.SetAddressFixed(true); |
| 1977 | + viewer.OnShiftClick(10 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1978 | + Assert::AreEqual({0x0U}, viewer.GetAddress()); |
| 1979 | + |
| 1980 | + // If not fixed address and Shift click on the first word containing 0x20 should lead to address 0x20 |
| 1981 | + viewer.SetAddressFixed(false); |
| 1982 | + viewer.OnShiftClick(10 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1983 | + Assert::AreEqual({0x20U}, viewer.GetAddress()); |
| 1984 | + |
| 1985 | + // Shift click on the second word containing 0x40 should lead to address 0xFF |
| 1986 | + viewer.OnShiftClick(15 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1987 | + Assert::AreEqual({0xFFU}, viewer.GetAddress()); |
| 1988 | + |
| 1989 | + // Shift click on the third word containing 0xFFFF should lead to address 0x1FF as 0xFFFF is bigger than the |
| 1990 | + // last address in memory |
| 1991 | + viewer.OnShiftClick(19 * CHAR_WIDTH, CHAR_HEIGHT + 4); |
| 1992 | + Assert::AreEqual({0x1FFU}, viewer.GetAddress()); |
| 1993 | + } |
1921 | 1994 | }; |
1922 | 1995 |
|
| 1996 | + |
1923 | 1997 | } // namespace tests |
1924 | 1998 | } // namespace viewmodels |
1925 | 1999 | } // namespace ui |
|
0 commit comments