mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 21:03:00 +00:00
C++: Move the internal test helper in the private_api namespace
in a different file
This commit is contained in:
parent
7059d48f6f
commit
13fe59cc2e
3 changed files with 9 additions and 9 deletions
71
api/cpp/include/slint_tests_helpers.h
Normal file
71
api/cpp/include/slint_tests_helpers.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial
|
||||
|
||||
#pragma once
|
||||
#include "slint.h"
|
||||
#include <concepts>
|
||||
#include <iostream>
|
||||
|
||||
// this file contains function useful for internal testing
|
||||
|
||||
namespace slint::private_api::testing {
|
||||
|
||||
inline void init()
|
||||
{
|
||||
cbindgen_private::slint_testing_init_backend();
|
||||
}
|
||||
|
||||
inline void mock_elapsed_time(int64_t time_in_ms)
|
||||
{
|
||||
cbindgen_private::slint_mock_elapsed_time(time_in_ms);
|
||||
}
|
||||
|
||||
inline uint64_t get_mocked_time()
|
||||
{
|
||||
return cbindgen_private::slint_get_mocked_time();
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline void send_mouse_click(const Component *component, float x, float y)
|
||||
{
|
||||
cbindgen_private::slint_send_mouse_click(x, y, &component->window().window_handle());
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline void send_keyboard_char(const Component *component, const slint::SharedString &str,
|
||||
bool pressed)
|
||||
{
|
||||
cbindgen_private::slint_send_keyboard_char(&str, pressed, &component->window().window_handle());
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline void send_keyboard_string_sequence(const Component *component,
|
||||
const slint::SharedString &str)
|
||||
{
|
||||
cbindgen_private::send_keyboard_string_sequence(&str, &component->window().window_handle());
|
||||
}
|
||||
|
||||
#define assert_eq(A, B) \
|
||||
slint::private_api::testing::assert_eq_impl(A, B, #A, #B, __FILE__, __LINE__)
|
||||
|
||||
template<typename A, std::equality_comparable_with<A> B>
|
||||
void assert_eq_impl(const A &a, const B &b, const char *a_str, const char *b_str, const char *file,
|
||||
int line)
|
||||
{
|
||||
bool nok = true;
|
||||
if constexpr (std::is_integral_v<A> && std::is_integral_v<B>) {
|
||||
// Do a cast to the common type to avoid warning about signed vs. unsigned compare
|
||||
using T = std::common_type_t<A, B>;
|
||||
nok = T(a) != T(b);
|
||||
} else {
|
||||
nok = a != b;
|
||||
}
|
||||
if (nok) {
|
||||
std::cerr << file << ":" << line << ": assert_eq FAILED!\n"
|
||||
<< a_str << ": " << a << "\n"
|
||||
<< b_str << ": " << b << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace slint
|
||||
Loading…
Add table
Add a link
Reference in a new issue