[wpilib] Add Notifier integration tests (#3480)

Closes #2610.
This commit is contained in:
Tyler Veness
2021-07-11 10:39:42 -04:00
committed by GitHub
parent f8f13c536f
commit 7a8796414c
2 changed files with 81 additions and 21 deletions

View File

@@ -6,34 +6,38 @@
#include <fmt/core.h>
#include "TestBench.h"
#include "frc/Timer.h"
#include "gtest/gtest.h"
unsigned notifierCounter;
TEST(NotifierTest, TestStartPeriodicAndStop) {
uint32_t counter = 0;
void notifierHandler(void*) {
notifierCounter++;
}
/**
* Test if the Wait function works
*/
TEST(NotifierTest, DISABLED_TestTimerNotifications) {
fmt::print("NotifierTest...\n");
notifierCounter = 0;
fmt::print("notifier(notifierHandler, nullptr)...\n");
frc::Notifier notifier(notifierHandler, nullptr);
fmt::print("Start Periodic...\n");
frc::Notifier notifier{[&] { ++counter; }};
notifier.StartPeriodic(1_s);
fmt::print("Wait...\n");
frc::Wait(10.5_s);
fmt::print("...Wait\n");
EXPECT_EQ(10u, notifierCounter)
<< "Received " << notifierCounter << " notifications in 10.5 seconds";
fmt::print("Received {} notifications in 10.5 seconds", notifierCounter);
notifier.Stop();
EXPECT_EQ(10u, counter) << "Received " << counter
<< " notifications in 10.5 seconds\n";
fmt::print("Received {} notifications in 10.5 seconds\n", counter);
fmt::print("...NotifierTest\n");
frc::Wait(3_s);
EXPECT_EQ(10u, counter) << "Received " << counter - 10
<< " notifications in 3 seconds\n";
fmt::print("Received {} notifications in 3 seconds\n", counter - 10);
}
TEST(NotifierTest, TestStartSingle) {
uint32_t counter = 0;
frc::Notifier notifier{[&] { ++counter; }};
notifier.StartSingle(1_s);
frc::Wait(10.5_s);
EXPECT_EQ(1u, counter) << "Received " << counter
<< " notifications in 10.5 seconds\n";
fmt::print("Received {} notifications in 10.5 seconds\n", counter);
}