Testing: Add minimum/maximum support (#5192)

This commit is contained in:
Montel Laurent 2024-05-10 16:18:02 +02:00 committed by GitHub
parent 25ef8f8711
commit c37c9d4f26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 108 additions and 2 deletions

View file

@ -88,6 +88,57 @@ public:
return std::nullopt;
}
/// Returns the accessible-value-maximum of that element, if any.
std::optional<float> accessible_value_maximum() const
{
if (auto item = private_api::upgrade_item_weak(inner)) {
SharedString result;
if (item->item_tree.vtable()->accessible_string_property(
item->item_tree.borrow(), item->index,
cbindgen_private::AccessibleStringProperty::ValueMaximum, &result)) {
float value = 0.0;
if (cbindgen_private::slint_string_to_float(&result, &value)) {
return value;
}
}
}
return std::nullopt;
}
/// Returns the accessible-value-minimum of that element, if any.
std::optional<float> accessible_value_minimum() const
{
if (auto item = private_api::upgrade_item_weak(inner)) {
SharedString result;
if (item->item_tree.vtable()->accessible_string_property(
item->item_tree.borrow(), item->index,
cbindgen_private::AccessibleStringProperty::ValueMinimum, &result)) {
float value = 0.0;
if (cbindgen_private::slint_string_to_float(&result, &value)) {
return value;
}
}
}
return std::nullopt;
}
/// Returns the accessible-value-step of that element, if any.
std::optional<float> accessible_value_step() const
{
if (auto item = private_api::upgrade_item_weak(inner)) {
SharedString result;
if (item->item_tree.vtable()->accessible_string_property(
item->item_tree.borrow(), item->index,
cbindgen_private::AccessibleStringProperty::ValueStep, &result)) {
float value = 0.0;
if (cbindgen_private::slint_string_to_float(&result, &value)) {
return value;
}
}
}
return std::nullopt;
}
/// Returns the accessible-checked of that element, if any.
std::optional<bool> accessible_checked() const
{

View file

@ -51,6 +51,9 @@ void assert_eq_impl(const A &a, const B &b, const char *a_str, const char *b_str
// 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 if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) {
const double dEpsilon = 0.000001; // or some other small number
nok = fabs(a - b) > dEpsilon * fabs(a);
} else {
nok = a != b;
}