Allow to simulate key event with the interpreter (C++)

This commit is contained in:
Olivier Goffart 2021-06-11 11:21:09 +02:00
parent 7f9bb18b9a
commit 7b63bb7d65
2 changed files with 41 additions and 1 deletions

View file

@ -417,4 +417,29 @@ SCENARIO("Component Definition Name")
ComponentCompiler compiler;
auto comp_def = *compiler.build_from_source("export IHaveAName := Rectangle { }", "");
REQUIRE(comp_def.name() == "IHaveAName");
}
}
SCENARIO("Send key events")
{
using namespace sixtyfps::interpreter;
using namespace sixtyfps;
ComponentCompiler compiler;
auto comp_def = compiler.build_from_source(R"(
export Dummy := Rectangle {
forward-focus: scope;
property <string> result;
scope := FocusScope {
key-pressed(event) => {
result += event.text;
return accept;
}
}
}
)",
"");
REQUIRE(comp_def.has_value());
auto instance = comp_def->create();
sixtyfps::testing::send_keyboard_string_sequence(&*instance, "Hello keys!", {});
REQUIRE(*instance->get_property("result")->to_string() == "Hello keys!");
}