Build XCUI splitter foundation and test harness
This commit is contained in:
90
tests/UI/Editor/unit/test_input_modifier_tracker.cpp
Normal file
90
tests/UI/Editor/unit/test_input_modifier_tracker.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <XCNewEditor/Host/InputModifierTracker.h>
|
||||
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::XCUI::Host::InputModifierTracker;
|
||||
using XCEngine::UI::UIInputEventType;
|
||||
|
||||
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);
|
||||
EXPECT_TRUE(modifiers.shift);
|
||||
EXPECT_TRUE(modifiers.alt);
|
||||
EXPECT_FALSE(modifiers.control);
|
||||
EXPECT_FALSE(modifiers.super);
|
||||
}
|
||||
|
||||
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