35 lines
711 B
C++
35 lines
711 B
C++
#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);
|
|
}
|
|
|