slint/api/cpp/tests/testing.cpp
Montel Laurent 301892d008
Some checks failed
autofix.ci / format_fix (push) Has been cancelled
autofix.ci / lint_typecheck (push) Has been cancelled
CI / files-changed (push) Has been cancelled
CI / ffi_32bit_build (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, 1.85) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Has been cancelled
CI / build_and_test (ubuntu-22.04, 1.85) (push) Has been cancelled
CI / build_and_test (ubuntu-22.04, nightly) (push) Has been cancelled
CI / node_test (macos-14) (push) Has been cancelled
CI / node_test (ubuntu-22.04) (push) Has been cancelled
CI / node_test (windows-2022) (push) Has been cancelled
CI / python_test (macos-14) (push) Has been cancelled
CI / python_test (ubuntu-22.04) (push) Has been cancelled
CI / python_test (windows-2022) (push) Has been cancelled
CI / cpp_test_driver (macos-13) (push) Has been cancelled
CI / cpp_test_driver (ubuntu-22.04) (push) Has been cancelled
CI / cpp_test_driver (windows-2022) (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / cpp_cmake (macos-14, 1.85) (push) Has been cancelled
CI / cpp_cmake (ubuntu-22.04, stable) (push) Has been cancelled
CI / cpp_cmake (windows-2022, nightly) (push) Has been cancelled
CI / cpp_package_test (push) Has been cancelled
CI / wasm (push) Has been cancelled
CI / wasm_demo (push) Has been cancelled
CI / vsce_build_test (push) Has been cancelled
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Has been cancelled
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Has been cancelled
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Has been cancelled
CI / mcu-embassy (push) Has been cancelled
CI / tree-sitter (push) Has been cancelled
CI / updater_test (0.3.0) (push) Has been cancelled
CI / fmt_test (push) Has been cancelled
CI / esp-idf-quick (push) Has been cancelled
CI / android (push) Has been cancelled
CI / miri (push) Has been cancelled
CI / test-figma-inspector (push) Has been cancelled
Updgrade Catch2 dependency (#8846)
CMake 4.0 remove some deprecated code < 3.5 

Catch2 old version still depend against cmake 3.0 + deprecated method.
Necessary to increase version otherwise when we try to compile
example with cmake 4.0 it will failed to configure it
2025-07-05 08:54:24 +02:00

72 lines
2.3 KiB
C++

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
#define CATCH_CONFIG_MAIN
#include "catch2/catch_all.hpp"
#include <slint.h>
#include <slint-interpreter.h>
#include <slint-testing.h>
SCENARIO("ElementHandle")
{
using namespace slint::interpreter;
using namespace slint;
ComponentCompiler compiler;
auto result = compiler.build_from_source(
R"(
component ButtonBase {
@children
}
component PushButton inherits ButtonBase {
accessible-role: button;
in property <string> text <=> label.text;
label := Text {}
}
export component App {
VerticalLayout {
PushButton { text: "first"; }
second := PushButton { text: "second"; }
}
}
)",
"");
for (auto &&x : compiler.diagnostics())
std::cerr << x.message << std::endl;
REQUIRE(result.has_value());
auto component_definition = *result;
auto instance = component_definition.create();
SECTION("Find by accessible label")
{
auto elements = slint::testing::ElementHandle::find_by_accessible_label(instance, "first");
REQUIRE(elements.size() == 1);
REQUIRE(*elements[0].accessible_label() == "first");
REQUIRE(*elements[0].id() == "PushButton::label");
REQUIRE(*elements[0].type_name() == "Text");
REQUIRE((*elements[0].bases()).size() == 0);
}
SECTION("Find by id")
{
auto elements = slint::testing::ElementHandle::find_by_element_id(instance, "App::second");
REQUIRE(elements.size() == 1);
REQUIRE(*elements[0].id() == "App::second");
REQUIRE(*elements[0].type_name() == "PushButton");
REQUIRE((*elements[0].bases()).size() == 1);
REQUIRE((*elements[0].bases())[0] == "ButtonBase");
REQUIRE(*elements[0].accessible_role() == slint::testing::AccessibleRole::Button);
}
SECTION("Find by type name")
{
auto elements =
slint::testing::ElementHandle::find_by_element_type_name(instance, "PushButton");
REQUIRE(elements.size() == 2);
REQUIRE(*elements[0].id() == "");
REQUIRE(*elements[1].id() == "App::second");
}
}