2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2020-12-03
|
|
|
|
// PURPOSE: unit tests for the CountDown Library
|
|
|
|
// https://github.com/RobTillaart/CountDown
|
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
|
|
|
//
|
|
|
|
|
|
|
|
// supported assertions
|
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42
|
|
|
|
// ----------------------------
|
|
|
|
// assertEqual(expected, actual)
|
|
|
|
// assertNotEqual(expected, actual)
|
|
|
|
// assertLess(expected, actual)
|
|
|
|
// assertMore(expected, actual)
|
|
|
|
// assertLessOrEqual(expected, actual)
|
|
|
|
// assertMoreOrEqual(expected, actual)
|
|
|
|
// assertTrue(actual)
|
|
|
|
// assertFalse(actual)
|
|
|
|
// assertNull(actual)
|
|
|
|
// assertNotNull(actual)
|
|
|
|
|
2021-10-19 15:40:11 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "CountDown.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2023-01-11 05:04:32 -05:00
|
|
|
fprintf(stderr, "COUNTDOWN_LIB_VERSION: %s\n", (char *) COUNTDOWN_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2021-10-19 15:40:11 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
unittest(test_constants)
|
|
|
|
{
|
|
|
|
assertEqual('M', CountDown::MINUTES);
|
|
|
|
assertEqual('s', CountDown::SECONDS);
|
|
|
|
assertEqual('m', CountDown::MILLIS);
|
|
|
|
assertEqual('u', CountDown::MICROS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
|
|
|
CountDown a(CountDown::MINUTES);
|
|
|
|
CountDown b(CountDown::SECONDS);
|
|
|
|
CountDown c(CountDown::MILLIS);
|
|
|
|
CountDown d(CountDown::MICROS);
|
|
|
|
CountDown e; // default MILLIS
|
|
|
|
|
|
|
|
assertEqual(CountDown::MINUTES, a.resolution());
|
|
|
|
assertEqual(CountDown::SECONDS, b.resolution());
|
|
|
|
assertEqual(CountDown::MILLIS, c.resolution());
|
|
|
|
assertEqual(CountDown::MICROS, d.resolution());
|
|
|
|
assertEqual(CountDown::MILLIS, e.resolution());
|
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
assertEqual('M', a.getUnits());
|
|
|
|
assertEqual('s', b.getUnits());
|
|
|
|
assertEqual('m', c.getUnits());
|
|
|
|
assertEqual('u', d.getUnits());
|
|
|
|
assertEqual('m', e.getUnits());
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
fprintf(stderr, "\nisRunning\n");
|
|
|
|
|
|
|
|
assertFalse(a.isRunning());
|
|
|
|
assertFalse(b.isRunning());
|
|
|
|
assertFalse(c.isRunning());
|
|
|
|
assertFalse(d.isRunning());
|
|
|
|
assertFalse(e.isRunning());
|
|
|
|
|
|
|
|
fprintf(stderr, "\nbase\n");
|
|
|
|
|
|
|
|
a.setResolution(CountDown::SECONDS);
|
|
|
|
assertTrue(a.start(10));
|
|
|
|
assertTrue(a.isRunning());
|
|
|
|
|
|
|
|
a.stop();
|
|
|
|
assertFalse(a.isRunning());
|
|
|
|
|
|
|
|
a.cont();
|
|
|
|
assertTrue(a.isRunning());
|
|
|
|
|
|
|
|
a.stop();
|
|
|
|
assertFalse(a.isRunning());
|
|
|
|
|
|
|
|
assertTrue(a.start(0));
|
|
|
|
assertFalse(a.isRunning());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_run)
|
|
|
|
{
|
|
|
|
CountDown cd(CountDown::MILLIS);
|
|
|
|
assertEqual(CountDown::MILLIS, cd.resolution());
|
|
|
|
|
|
|
|
assertFalse(cd.isRunning());
|
2023-01-11 05:04:32 -05:00
|
|
|
assertTrue(cd.isStopped());
|
2021-01-29 06:31:58 -05:00
|
|
|
cd.start(10);
|
|
|
|
assertTrue(cd.isRunning());
|
2023-01-11 05:04:32 -05:00
|
|
|
assertFalse(cd.isStopped());
|
2021-01-29 06:31:58 -05:00
|
|
|
delay(5);
|
|
|
|
cd.stop();
|
|
|
|
assertFalse(cd.isRunning());
|
2023-01-11 05:04:32 -05:00
|
|
|
assertTrue(cd.isStopped());
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual(5, cd.remaining());
|
|
|
|
|
|
|
|
cd.start(10);
|
|
|
|
assertTrue(cd.isRunning());
|
2023-01-11 05:04:32 -05:00
|
|
|
assertFalse(cd.isStopped());
|
2021-01-29 06:31:58 -05:00
|
|
|
delay(15);
|
|
|
|
assertFalse(cd.isRunning());
|
2023-01-11 05:04:32 -05:00
|
|
|
assertTrue(cd.isStopped());
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual(0, cd.remaining());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_overflow)
|
|
|
|
{
|
|
|
|
CountDown cd;
|
2023-01-11 05:04:32 -05:00
|
|
|
assertEqual(CountDown::MILLIS, cd.resolution());
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
assertFalse(cd.isRunning());
|
|
|
|
assertFalse(cd.start(50, 0, 0));
|
2023-01-11 05:04:32 -05:00
|
|
|
assertEqual(CountDown::MINUTES, cd.resolution());
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
assertFalse(cd.start(50, 0, 0, 0));
|
2023-01-11 05:04:32 -05:00
|
|
|
assertEqual(CountDown::SECONDS, cd.resolution());
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
assertFalse(cd.start(0, 1200, 0));
|
|
|
|
assertFalse(cd.start(0, 1200, 0, 0));
|
|
|
|
|
|
|
|
assertFalse(cd.start(0, 0, 72000));
|
|
|
|
assertFalse(cd.start(0, 0, 72000, 0));
|
|
|
|
|
|
|
|
assertFalse(cd.start(0, 0, 0, 4320000));
|
|
|
|
}
|
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_main()
|
|
|
|
|
2023-01-11 05:04:32 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|