2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2014-08-08 17:05:49 -04:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Notifier.h" // NOLINT(build/include_order)
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
#include <fmt/core.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Timer.h"
|
2016-09-05 13:55:31 -07:00
|
|
|
#include "gtest/gtest.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2021-07-11 10:39:42 -04:00
|
|
|
TEST(NotifierTest, TestStartPeriodicAndStop) {
|
|
|
|
|
uint32_t counter = 0;
|
2014-08-08 17:05:49 -04:00
|
|
|
|
2021-07-11 10:39:42 -04:00
|
|
|
frc::Notifier notifier{[&] { ++counter; }};
|
2021-05-28 22:06:59 -07:00
|
|
|
notifier.StartPeriodic(1_s);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-05-31 10:21:34 -07:00
|
|
|
frc::Wait(10.5_s);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-07-11 10:39:42 -04:00
|
|
|
notifier.Stop();
|
|
|
|
|
EXPECT_EQ(10u, counter) << "Received " << counter
|
|
|
|
|
<< " notifications in 10.5 seconds\n";
|
|
|
|
|
fmt::print("Received {} notifications in 10.5 seconds\n", counter);
|
|
|
|
|
|
|
|
|
|
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);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-07-11 10:39:42 -04:00
|
|
|
EXPECT_EQ(1u, counter) << "Received " << counter
|
|
|
|
|
<< " notifications in 10.5 seconds\n";
|
|
|
|
|
fmt::print("Received {} notifications in 10.5 seconds\n", counter);
|
2014-08-08 17:05:49 -04:00
|
|
|
}
|