Bound engineering UI state and session events for M9.8b
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "evo/client/ui_state.hpp"
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
using namespace evo::client;
|
||||
void check(bool ok) {
|
||||
if (!ok)
|
||||
throw std::runtime_error("UI state contract");
|
||||
}
|
||||
int main() try {
|
||||
UiState ui;
|
||||
check(ui.advance(100).has_value());
|
||||
auto first = ui.notify("Connected", NoticeLevel::info, 10);
|
||||
check(first.has_value());
|
||||
check(ui.advance(109).has_value() && ui.notices().size() == 1);
|
||||
check(ui.advance(110).has_value() && ui.notices().empty());
|
||||
check(!ui.dismiss(*first));
|
||||
check(!ui.advance(109));
|
||||
check(!ui.notify(std::string(241, 'x'), NoticeLevel::info));
|
||||
check(!ui.notify(std::string_view{"x\0y", 3}, NoticeLevel::info));
|
||||
check(!ui.notify("invalid", NoticeLevel::info, 0));
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
check(ui.notify("Burst", NoticeLevel::warning).has_value());
|
||||
check(ui.notices().size() == 8 && ui.evicted_notices() == 9992);
|
||||
auto dismissed = ui.notices().back().id;
|
||||
check(ui.dismiss(dismissed));
|
||||
check(ui.notices().size() == 7 && !ui.dismiss(dismissed));
|
||||
auto dialog = ui.open_dialog("Disconnect?", "Current intentions may remain unknown.");
|
||||
check(dialog.has_value());
|
||||
check(!ui.open_dialog("Other", "Blocked"));
|
||||
check(!ui.close_dialog(*dialog + 1));
|
||||
check(ui.close_dialog(*dialog));
|
||||
auto next = ui.open_dialog("New", "New modal");
|
||||
check(next.has_value());
|
||||
check(!ui.close_dialog(*dialog) && ui.dialog().has_value());
|
||||
check(ui.close_dialog(*next));
|
||||
check(ui.advance(std::numeric_limits<std::uint64_t>::max()).has_value());
|
||||
check(!ui.notify("Overflow", NoticeLevel::error, 1));
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user