Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Asynchronous timers from Asio are relatively easy to use. However, there are no

The generated Doxygen documentation for `periodic_timer` is [here](https://connectivecpp.github.io/periodic-timer/).

## Dependencies
## Library Dependencies

The `periodic_timer` header file has the stand-alone Asio library for a dependency. Specific version (or branch) specs for the Asio dependency is in `cmake/download_asio_cpm.cmake`.
The `periodic_timer` header file has the stand-alone Asio library for a dependency. Specific version (or branch) specs for the Asio dependency is in [`cmake/download_asio_cpm.cmake`](cmake/download_asio_cpm.cmake).

## C++ Standard

Expand Down
2 changes: 1 addition & 1 deletion cmake/download_asio_cpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
find_package ( Threads REQUIRED )

CPMAddPackage ( "gh:chriskohlhoff/asio#asio-1-34-0@1.34.0" )
CPMAddPackage ( "gh:chriskohlhoff/asio#asio-1-36-0@1.36.0" )

# ASIO doesn't use CMake, we have to configure it manually. Extra notes for using on Windows:
#
Expand Down
2 changes: 1 addition & 1 deletion cmake/download_cpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.0/CPM.cmake
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.42.0/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ target_compile_features ( periodic_timer_test PRIVATE cxx_std_20 )
# add dependencies
include ( ../cmake/download_cpm.cmake )

CPMAddPackage ( "gh:catchorg/Catch2@3.8.0" )
CPMAddPackage ( "gh:catchorg/Catch2@3.11.0" )

set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
Expand Down
34 changes: 13 additions & 21 deletions test/periodic_timer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void wait_util (std::chrono::milliseconds ms, wk_guard& wg, std::thread& thr) {
template <typename Clock>
void test_util () {

GIVEN ( "A clock and a duration") {
SECTION ( "Setup clock and duration") {

asio::io_context ioc;
chops::periodic_timer<Clock> timer {ioc};
Expand All @@ -56,7 +56,7 @@ void test_util () {
std::thread thr([&ioc] () { ioc.run(); } );
count = 0;

WHEN ( "The duration is 100 ms" ) {
SECTION ( "100 ms duration" ) {
auto test_dur { 100 };
timer.start_duration_timer(std::chrono::milliseconds(test_dur),
[] (std::error_code err, typename Clock::duration elap) {
Expand All @@ -66,11 +66,9 @@ void test_util () {

wait_util (std::chrono::milliseconds((Expected+1)*test_dur), wg, thr);

THEN ( "the timer callback count should match expected") {
REQUIRE (count == Expected);
}
REQUIRE (count == Expected);
}
WHEN ( "The duration is 200 ms and the start time is 2 seconds in the future" ) {
SECTION ( "200 ms duration, start time is 2 seconds in the future" ) {
auto test_dur { 200 };
timer.start_duration_timer(std::chrono::milliseconds(test_dur), Clock::now() + std::chrono::seconds(2),
[] (std::error_code err, typename Clock::duration elap) {
Expand All @@ -80,11 +78,9 @@ void test_util () {

wait_util(std::chrono::milliseconds((Expected+1)*test_dur + 2000), wg, thr);

THEN ( "the timer callback count should match expected") {
REQUIRE (count == Expected);
}
REQUIRE (count == Expected);
}
WHEN ( "The duration is 100 ms and the timer pops on timepoints" ) {
SECTION ( "100 ms duration, timer pops on timepoints" ) {
auto test_dur { 100 };
timer.start_timepoint_timer(std::chrono::milliseconds(test_dur),
[] (std::error_code err, typename Clock::duration elap) {
Expand All @@ -94,11 +90,9 @@ void test_util () {

wait_util (std::chrono::milliseconds((Expected+1)*test_dur), wg, thr);

THEN ( "the timer callback count should match expected") {
REQUIRE (count == Expected);
}
REQUIRE (count == Expected);
}
WHEN ( "The duration is 200 ms and the timer pops on timepoints starting 2 seconds in the future" ) {
SECTION ( "200 ms duration, timer pops on timepoints starting 2 seconds in the future" ) {
auto test_dur { 200 };
timer.start_timepoint_timer(std::chrono::milliseconds(test_dur), Clock::now() + std::chrono::seconds(2),
[] (std::error_code err, typename Clock::duration elap) {
Expand All @@ -108,25 +102,23 @@ void test_util () {

wait_util(std::chrono::milliseconds((Expected+1)*test_dur + 2000), wg, thr);

THEN ( "the timer callback count should match expected") {
REQUIRE (count == Expected);
}
REQUIRE (count == Expected);
}

} // end given
}
}

SCENARIO ( "A periodic timer can be instantiated on the steady clock", "[periodic_timer] [steady_clock]" ) {
TEST_CASE ( "Steady clock periodic timer", "[periodic_timer] [steady_clock]" ) {

test_util<std::chrono::steady_clock>();

}
SCENARIO ( "A periodic timer can be instantiated on the system clock", "[periodic_timer] [system_clock]" ) {
TEST_CASE ( "System clock periodic timer", "[periodic_timer] [system_clock]" ) {

test_util<std::chrono::system_clock>();

}
SCENARIO ( "A periodic timer can be instantiated on the high resolution clock", "[periodic_timer] [high_resolution_clock]" ) {
TEST_CASE ( "High resolution clock periodic timer", "[periodic_timer] [high_resolution_clock]" ) {

test_util<std::chrono::high_resolution_clock>();

Expand Down