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 DHT2pin library
|
2023-01-29 14:16:17 -05:00
|
|
|
// https://github.com/RobTillaart/dht2pin
|
2021-01-29 06:31:58 -05:00
|
|
|
// 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 "Arduino.h"
|
|
|
|
#include "DHT2pin.h"
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-16 07:42:53 -05:00
|
|
|
fprintf(stderr, "DHT2PIN_LIB_VERSION: %s\n", (char *) DHT2PIN_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2023-01-29 14:16:17 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-29 14:16:17 -05:00
|
|
|
unittest(test_constants)
|
|
|
|
{
|
|
|
|
assertEqual(00, DHTLIB_OK);
|
|
|
|
assertEqual(-1, DHTLIB_ERROR_CHECKSUM);
|
|
|
|
assertEqual(-2, DHTLIB_ERROR_TIMEOUT);
|
|
|
|
assertEqual(-3, DHTLIB_ERROR_CONNECT);
|
|
|
|
assertEqual(-4, DHTLIB_ERROR_ACK_L);
|
|
|
|
assertEqual(-5, DHTLIB_ERROR_ACK_H);
|
|
|
|
assertEqual(-999, DHTLIB_INVALID_VALUE);
|
|
|
|
|
|
|
|
assertEqual(18, DHTLIB_DHT11_WAKEUP);
|
|
|
|
assertEqual(01, DHTLIB_DHT_WAKEUP);
|
|
|
|
|
|
|
|
// just printing.
|
|
|
|
fprintf(stderr, "DHTLIB_TIMEOUT: %d\n", DHTLIB_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
|
|
|
DHT2pin DHT(2, 3);
|
2021-12-16 07:42:53 -05:00
|
|
|
|
2023-01-29 14:16:17 -05:00
|
|
|
assertEqualFloat(0, DHT.temperature(), 0.001);
|
|
|
|
assertEqualFloat(0, DHT.humidity(), 0.001);
|
|
|
|
|
|
|
|
int chk = DHT.read();
|
|
|
|
// Nothing connected so timeout expected
|
|
|
|
assertEqual(DHTLIB_ERROR_TIMEOUT, chk);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2023-01-29 14:16:17 -05:00
|
|
|
// This will set the temperature and humidity to -999
|
|
|
|
assertEqualFloat(-999, DHT.temperature(), 0.001);
|
|
|
|
assertEqualFloat(-999, DHT.humidity(), 0.001);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2022-11-01 15:26:33 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_main()
|
|
|
|
|
2023-01-29 14:16:17 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|