Skip to content

Commit

Permalink
Fix signal tests
Browse files Browse the repository at this point in the history
Tests worked only if ran separately because CoreApplication was new'd
for each test but never deleted. This fired an assert that assures that
there's only one CoreApplication existing at a time
  • Loading branch information
MiKom committed Jun 28, 2024
1 parent dc7faa5 commit eb61afe
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/auto/utils/signal/tst_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ TEST_SUITE("Signal")
{
int val = 4;

auto *appInstance = new KDFoundation::CoreApplication;
KDFoundation::CoreApplication app;
KDBindings::Signal<int> signal1;
KDBindings::Signal<int> signal2;

std::thread thread1([&] {
signal1.connectDeferred(appInstance->connectionEvaluator(), [&val](int value) {
signal1.connectDeferred(app.connectionEvaluator(), [&val](int value) {
val += value;
});
});

std::thread thread2([&] {
signal2.connectDeferred(appInstance->connectionEvaluator(), [&val](int value) {
signal2.connectDeferred(app.connectionEvaluator(), [&val](int value) {
val += value;
});
});
Expand All @@ -38,25 +38,25 @@ TEST_SUITE("Signal")
signal2.emit(3);
CHECK(val == 4); // val not changing immediately after emit

appInstance->connectionEvaluator()->evaluateDeferredConnections();
app.connectionEvaluator()->evaluateDeferredConnections();

CHECK(val == 9);
}

TEST_CASE("Emit Multiple Signals with Evaluator")
{
auto *appInstance = new KDFoundation::CoreApplication;
KDFoundation::CoreApplication app;
KDBindings::Signal<int> signal1;
KDBindings::Signal<int> signal2;

int val1 = 4;
int val2 = 4;

signal1.connectDeferred(appInstance->connectionEvaluator(), [&val1](int value) {
signal1.connectDeferred(app.connectionEvaluator(), [&val1](int value) {
val1 += value;
});

signal2.connectDeferred(appInstance->connectionEvaluator(), [&val2](int value) {
signal2.connectDeferred(app.connectionEvaluator(), [&val2](int value) {
val2 += value;
});

Expand All @@ -74,19 +74,19 @@ TEST_SUITE("Signal")
CHECK(val1 == 4);
CHECK(val2 == 4);

appInstance->connectionEvaluator()->evaluateDeferredConnections();
app.connectionEvaluator()->evaluateDeferredConnections();

CHECK(val1 == 6);
CHECK(val2 == 7);
}

TEST_CASE("Connect, Emit, Disconnect, and Evaluate")
{
auto *appInstance = new KDFoundation::CoreApplication;
KDFoundation::CoreApplication app;
KDBindings::Signal<int> signal;
int val = 4;

auto connection = signal.connectDeferred(appInstance->connectionEvaluator(), [&val](int value) {
auto connection = signal.connectDeferred(app.connectionEvaluator(), [&val](int value) {
val += value;
});

Expand All @@ -97,7 +97,7 @@ TEST_SUITE("Signal")

connection.disconnect();

appInstance->connectionEvaluator()->evaluateDeferredConnections();
app.connectionEvaluator()->evaluateDeferredConnections();

CHECK(val == 4);
}
Expand Down

0 comments on commit eb61afe

Please sign in to comment.