chore: snapshot editor work and restore tests
Key points:\n- restore the tests tree removed by bc47e6e\n- capture current editor workspace, scene, and docs reshuffle changes\n- keep local cloud.nvdb resources ignored from this commit
This commit is contained in:
111
tests/UI/Editor/unit/test_input_modifier_tracker.cpp
Normal file
111
tests/UI/Editor/unit/test_input_modifier_tracker.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "app/Platform/Win32/InputModifierTracker.h"
|
||||
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::Editor::Host::InputModifierTracker;
|
||||
using XCEngine::UI::UIInputEventType;
|
||||
using XCEngine::UI::UIPointerButton;
|
||||
|
||||
TEST(InputModifierTrackerTest, ControlStatePersistsAcrossChordKeyDownAndClearsOnKeyUp) {
|
||||
InputModifierTracker tracker = {};
|
||||
|
||||
const auto ctrlDown = tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyDown,
|
||||
VK_CONTROL,
|
||||
0x001D0001);
|
||||
EXPECT_TRUE(ctrlDown.control);
|
||||
EXPECT_FALSE(ctrlDown.shift);
|
||||
EXPECT_FALSE(ctrlDown.alt);
|
||||
|
||||
const auto chordKeyDown = tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyDown,
|
||||
'P',
|
||||
0x00190001);
|
||||
EXPECT_TRUE(chordKeyDown.control);
|
||||
|
||||
const auto ctrlUp = tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyUp,
|
||||
VK_CONTROL,
|
||||
static_cast<LPARAM>(0xC01D0001u));
|
||||
EXPECT_FALSE(ctrlUp.control);
|
||||
|
||||
const auto nextKeyDown = tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyDown,
|
||||
'P',
|
||||
0x00190001);
|
||||
EXPECT_FALSE(nextKeyDown.control);
|
||||
}
|
||||
|
||||
TEST(InputModifierTrackerTest, PointerModifiersMergeMouseFlagsWithTrackedKeyboardState) {
|
||||
InputModifierTracker tracker = {};
|
||||
tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyDown,
|
||||
VK_MENU,
|
||||
0x00380001);
|
||||
|
||||
const auto modifiers = tracker.BuildPointerModifiers(MK_SHIFT | MK_RBUTTON);
|
||||
EXPECT_TRUE(modifiers.shift);
|
||||
EXPECT_TRUE(modifiers.alt);
|
||||
EXPECT_FALSE(modifiers.control);
|
||||
EXPECT_FALSE(modifiers.super);
|
||||
EXPECT_FALSE(modifiers.leftMouse);
|
||||
EXPECT_TRUE(modifiers.rightMouse);
|
||||
}
|
||||
|
||||
TEST(InputModifierTrackerTest, PointerMessagesUpdateTrackedMouseButtonState) {
|
||||
InputModifierTracker tracker = {};
|
||||
|
||||
const auto leftDown = tracker.ApplyPointerMessage(
|
||||
UIInputEventType::PointerButtonDown,
|
||||
UIPointerButton::Left,
|
||||
0u);
|
||||
EXPECT_TRUE(leftDown.leftMouse);
|
||||
EXPECT_TRUE(tracker.GetCurrentModifiers().leftMouse);
|
||||
|
||||
const auto leftUp = tracker.ApplyPointerMessage(
|
||||
UIInputEventType::PointerButtonUp,
|
||||
UIPointerButton::Left,
|
||||
0u);
|
||||
EXPECT_FALSE(leftUp.leftMouse);
|
||||
EXPECT_FALSE(tracker.GetCurrentModifiers().leftMouse);
|
||||
}
|
||||
|
||||
TEST(InputModifierTrackerTest, RightControlIsTrackedIndependentlyFromLeftControl) {
|
||||
InputModifierTracker tracker = {};
|
||||
|
||||
tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyDown,
|
||||
VK_CONTROL,
|
||||
static_cast<LPARAM>(0x011D0001u));
|
||||
EXPECT_TRUE(tracker.GetCurrentModifiers().control);
|
||||
|
||||
tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyDown,
|
||||
VK_CONTROL,
|
||||
0x001D0001);
|
||||
EXPECT_TRUE(tracker.GetCurrentModifiers().control);
|
||||
|
||||
tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyUp,
|
||||
VK_CONTROL,
|
||||
static_cast<LPARAM>(0xC11D0001u));
|
||||
EXPECT_TRUE(tracker.GetCurrentModifiers().control);
|
||||
|
||||
tracker.ApplyKeyMessage(
|
||||
UIInputEventType::KeyUp,
|
||||
VK_CONTROL,
|
||||
static_cast<LPARAM>(0xC01D0001u));
|
||||
EXPECT_FALSE(tracker.GetCurrentModifiers().control);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user