PIThreadNotifier, rewrite PIObject::deleteLater()

tests for PIThreadNotifier and PIObject::deleteLater()
This commit is contained in:
Andrey
2021-10-29 18:20:48 +03:00
parent 6e5a5a6ade
commit 48c885e12a
9 changed files with 196 additions and 75 deletions

View File

@@ -0,0 +1,34 @@
#include "gtest/gtest.h"
#include "pithreadnotifier.h"
TEST(PIThreadNotifierTest, One) {
PIThreadNotifier n;
int cnt = 0;
PIThread t1([&n, &cnt](){n.wait(); cnt++;}, true);
piMSleep(10);
n.notifyOnce();
piMSleep(10);
ASSERT_EQ(cnt, 1);
n.notifyOnce();
piMSleep(10);
ASSERT_EQ(cnt, 2);
}
TEST(PIThreadNotifierTest, Two) {
PIThreadNotifier n;
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
PIThread t1([&n, &cnt1](){n.wait(); cnt1++; piMSleep(2);}, true);
PIThread t2([&n, &cnt2](){n.wait(); cnt2++; piMSleep(2);}, true);
PIThread t3([&n, &cnt3](){n.notifyOnce(); cnt3++; piMSleep(1);}, true);
piMSleep(20);
t3.stop(true);
piMSleep(100);
t1.stop();
t2.stop();
ASSERT_EQ(cnt1+cnt2, cnt3);
}