2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// VERSION: 0.3.0
|
|
|
|
// DATE: 2020-12-03
|
|
|
|
// PURPOSE: unit tests for I2C digital PotentioMeter AD5241 AD5242
|
|
|
|
// https://github.com/RobTillaart/AD524X
|
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
|
|
|
//
|
|
|
|
|
|
|
|
// supported assertions
|
|
|
|
// ----------------------------
|
|
|
|
// assertEqual(expected, actual)
|
|
|
|
// assertNotEqual(expected, actual)
|
|
|
|
// assertLess(expected, actual)
|
|
|
|
// assertMore(expected, actual)
|
|
|
|
// assertLessOrEqual(expected, actual)
|
|
|
|
// assertMoreOrEqual(expected, actual)
|
|
|
|
// assertTrue(actual)
|
|
|
|
// assertFalse(actual)
|
|
|
|
// assertNull(actual)
|
|
|
|
|
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
#include "AD524X.h"
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2022-08-13 13:31:52 -04:00
|
|
|
fprintf(stderr, "\nAD524X_LIB_VERSION: %s\n", (char *) AD524X_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_constructors)
|
|
|
|
{
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
AD524X ADx(0x2C); // AD0 & AD1 == GND
|
|
|
|
assertEqual(127, ADx.read(0));
|
|
|
|
assertEqual(127, ADx.read(1));
|
|
|
|
|
|
|
|
AD5241 AD1(0x2C);
|
|
|
|
assertEqual(127, AD1.read(0));
|
|
|
|
assertEqual(127, AD1.read(1));
|
|
|
|
|
|
|
|
AD5242 AD2(0x2C);
|
|
|
|
assertEqual(127, AD2.read(0));
|
|
|
|
assertEqual(127, AD2.read(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_reset)
|
|
|
|
{
|
|
|
|
AD524X AD(0x2C); // AD0 & AD1 == GND
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
assertEqual(127, AD.read(0));
|
|
|
|
assertEqual(127, AD.read(1));
|
|
|
|
|
|
|
|
AD.zeroAll();
|
|
|
|
assertEqual(0, AD.read(0));
|
|
|
|
assertEqual(0, AD.read(1));
|
|
|
|
|
|
|
|
AD.reset();
|
|
|
|
assertEqual(127, AD.read(0));
|
|
|
|
assertEqual(127, AD.read(1));
|
|
|
|
|
|
|
|
AD.zeroAll();
|
|
|
|
assertEqual(0, AD.read(0));
|
|
|
|
assertEqual(0, AD.read(1));
|
|
|
|
|
|
|
|
AD.midScaleReset(0);
|
|
|
|
assertEqual(127, AD.read(0));
|
|
|
|
AD.midScaleReset(1);
|
|
|
|
assertEqual(127, AD.read(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_write_read)
|
|
|
|
{
|
|
|
|
AD524X AD(0x2C); // AD0 & AD1 == GND
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
assertEqual(127, AD.read(0));
|
|
|
|
assertEqual(127, AD.read(1));
|
|
|
|
|
|
|
|
AD.write(0, 42);
|
|
|
|
assertEqual(42, AD.read(0));
|
|
|
|
assertEqual(127, AD.read(1));
|
|
|
|
|
|
|
|
AD.write(1, 42);
|
|
|
|
assertEqual(42, AD.read(0));
|
|
|
|
assertEqual(42, AD.read(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_O1_O2)
|
|
|
|
{
|
|
|
|
AD524X AD(0x2C); // AD0 & AD1 == GND
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
assertEqual(0, AD.getO1());
|
|
|
|
assertEqual(0, AD.getO2());
|
|
|
|
|
|
|
|
AD.setO1();
|
|
|
|
assertEqual(1, AD.getO1());
|
|
|
|
assertEqual(0, AD.getO2());
|
|
|
|
|
|
|
|
AD.setO2();
|
|
|
|
assertEqual(1, AD.getO1());
|
|
|
|
assertEqual(1, AD.getO2());
|
|
|
|
|
|
|
|
AD.setO1(0);
|
|
|
|
assertEqual(0, AD.getO1());
|
|
|
|
assertEqual(1, AD.getO2());
|
|
|
|
|
|
|
|
AD.setO2(0);
|
|
|
|
assertEqual(0, AD.getO1());
|
|
|
|
assertEqual(0, AD.getO2());
|
|
|
|
|
|
|
|
AD.write(0, 0, 1, 1);
|
|
|
|
assertEqual(1, AD.getO1());
|
|
|
|
assertEqual(1, AD.getO2());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-10 08:52:27 -05:00
|
|
|
unittest(test_constants)
|
|
|
|
{
|
|
|
|
assertEqual(0, AD524X_OK);
|
|
|
|
assertEqual(100, AD524X_ERROR);
|
2023-01-11 10:35:57 -05:00
|
|
|
assertEqual(127, AD524X_MIDPOINT);
|
2021-12-10 08:52:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|