2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2020-12-18
|
|
|
|
// PURPOSE: unit tests for the DEVNULL library
|
|
|
|
// https://github.com/RobTillaart/
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "DEVNULL.h"
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-15 11:18:40 -05:00
|
|
|
fprintf(stderr, "DEVNULL_LIB_VERSION: %s\n", (char *) DEVNULL_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_all)
|
|
|
|
{
|
|
|
|
DEVNULL dn;
|
2021-12-15 11:18:40 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual(0, dn.available());
|
|
|
|
assertEqual(EOF, dn.peek());
|
|
|
|
assertEqual(EOF, dn.read());
|
2022-09-21 04:45:14 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual(1, dn.write('a'));
|
2022-09-21 04:45:14 -04:00
|
|
|
assertEqual('a', dn.lastByte());
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual(11, dn.print("hello world"));
|
2022-09-21 04:45:14 -04:00
|
|
|
assertEqual('d', dn.lastByte());
|
2021-12-15 11:18:40 -05:00
|
|
|
assertEqual(13, dn.println("hello world"));
|
2022-09-21 04:45:14 -04:00
|
|
|
assertEqual(10, dn.lastByte()); // 10 == newline
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|