mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
C++ Api to run a functor from a thread
This commit is contained in:
parent
7293129fe1
commit
aabd320e83
5 changed files with 111 additions and 14 deletions
|
@ -72,11 +72,3 @@ TEST_CASE("Property Tracker")
|
|||
REQUIRE(!tracker1.is_dirty());
|
||||
}
|
||||
|
||||
TEST_CASE("C++ Timers")
|
||||
{
|
||||
using namespace sixtyfps;
|
||||
|
||||
Timer testTimer(std::chrono::milliseconds(16), []() { sixtyfps::quit_event_loop(); });
|
||||
|
||||
sixtyfps::run_event_loop();
|
||||
}
|
||||
|
|
58
api/sixtyfps-cpp/tests/eventloop.cpp
Normal file
58
api/sixtyfps-cpp/tests/eventloop.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <sixtyfps.h>
|
||||
#include <thread>
|
||||
|
||||
TEST_CASE("C++ Timers")
|
||||
{
|
||||
using namespace sixtyfps;
|
||||
int called = 0;
|
||||
Timer testTimer(std::chrono::milliseconds(16), [&]() {
|
||||
sixtyfps::quit_event_loop();
|
||||
called += 10;
|
||||
});
|
||||
REQUIRE(called == 0);
|
||||
sixtyfps::run_event_loop();
|
||||
REQUIRE(called == 10);
|
||||
}
|
||||
|
||||
|
||||
SCENARIO("Quit from event")
|
||||
{
|
||||
int called = 0;
|
||||
sixtyfps::invoke_from_event_loop([&] {
|
||||
sixtyfps::quit_event_loop();
|
||||
called += 10;
|
||||
});
|
||||
REQUIRE(called == 0);
|
||||
sixtyfps::run_event_loop();
|
||||
REQUIRE(called == 10);
|
||||
}
|
||||
|
||||
|
||||
SCENARIO("Event from thread")
|
||||
{
|
||||
std::atomic<int> called = 0;
|
||||
auto t = std::thread([&] {
|
||||
called += 10;
|
||||
sixtyfps::invoke_from_event_loop([&] {
|
||||
called += 100;
|
||||
sixtyfps::quit_event_loop();
|
||||
});
|
||||
});
|
||||
|
||||
sixtyfps::run_event_loop();
|
||||
REQUIRE(called == 110);
|
||||
t.join();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue