54 lines
2.5 KiB
PHP
54 lines
2.5 KiB
PHP
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
// What the tests of Nostro.Ui and of the app build frames with, included after `import Nostro.Ui;` and Check.inc: a
|
||
|
|
// font of known sizes, so every position is exact, and the reading of a frame: what it says, and where.
|
||
|
|
|
||
|
|
namespace Test {
|
||
|
|
// Every code point half its size wide: at 16 pixels, eight a character. A line is 1.25 sizes tall, its baseline
|
||
|
|
// 0.8 of a size down.
|
||
|
|
inline Nostro::Ui::TextMeasure FixedMeasure() {
|
||
|
|
Nostro::Ui::TextMeasure measure;
|
||
|
|
measure.advance = [](Nostro::Ui::FontFace, std::uint32_t, float px) { return px * 0.5f; };
|
||
|
|
measure.ascent = [](Nostro::Ui::FontFace, float px) { return px * 0.8f; };
|
||
|
|
measure.lineHeight = [](Nostro::Ui::FontFace, float px) { return px * 1.25f; };
|
||
|
|
return measure;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Every line of text the frame shown draws, one to a line: what a failed check prints.
|
||
|
|
inline std::string Said(const Nostro::Ui::Context& ui) {
|
||
|
|
std::string said;
|
||
|
|
for(const std::string& text : ui.Shown().draw.Texts()) {
|
||
|
|
said += text;
|
||
|
|
said += '\n';
|
||
|
|
}
|
||
|
|
return said;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Whether a line the frame draws has `text` in it.
|
||
|
|
inline bool Says(const Nostro::Ui::Context& ui, std::string_view text) {
|
||
|
|
return std::ranges::any_of(ui.Shown().draw.Texts(), [text](const std::string& line) { return line.contains(text); });
|
||
|
|
}
|
||
|
|
|
||
|
|
// The frame says `text`.
|
||
|
|
inline void Shows(const Nostro::Ui::Context& ui, std::string_view text, std::string_view what, std::source_location where = std::source_location::current()) {
|
||
|
|
if(!Says(ui, text)) {
|
||
|
|
std::println("FAIL {}:{}: {}: the screen does not say '{}'. It says:\n{}", where.file_name(), where.line(), what, text, Said(ui));
|
||
|
|
failures++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// The frame does not say `text`.
|
||
|
|
inline void Hides(const Nostro::Ui::Context& ui, std::string_view text, std::string_view what, std::source_location where = std::source_location::current()) {
|
||
|
|
if(Says(ui, text)) {
|
||
|
|
std::println("FAIL {}:{}: {}: the screen says '{}'", where.file_name(), where.line(), what, text);
|
||
|
|
failures++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// A press and its release at one point, a tenth of a second apart: a tap as a finger makes it.
|
||
|
|
inline void TapAt(Nostro::Ui::Context& ui, Nostro::Ui::Point at, std::int64_t tMs = 0) {
|
||
|
|
ui.Pointer(Nostro::Ui::PointerPhase::Down, at, tMs);
|
||
|
|
ui.Pointer(Nostro::Ui::PointerPhase::Up, at, tMs + 100);
|
||
|
|
}
|
||
|
|
}
|