GY-63_MS5611/libraries/DAC8552/test/unit_test_001.cpp

120 lines
2.8 KiB
C++
Raw Normal View History

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 DAC8552
// 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 "Arduino.h"
#include "DAC8552.h"
unittest_setup()
{
2021-12-15 06:48:53 -05:00
fprintf(stderr, "DAC8552_LIB_VERSION: %s\n", (char *) DAC8552_LIB_VERSION);
2021-01-29 06:31:58 -05:00
}
unittest_teardown()
{
}
2021-12-15 06:48:53 -05:00
unittest(test_constants)
{
assertEqual(0, DAC8552_POWERDOWN_NORMAL );
assertEqual(1, DAC8552_POWERDOWN_1K );
assertEqual(2, DAC8552_POWERDOWN_100K );
assertEqual(3, DAC8552_POWERDOWN_HIGH_IMP);
}
2021-01-29 06:31:58 -05:00
unittest(test_HW_constructor)
{
DAC8552 mydac(10);
mydac.begin();
for (uint8_t channel = 0; channel < 2; channel++)
{
fprintf(stderr, "CHANNEL %d\n", channel);
for (uint16_t val = 0; val < 65500; val += 30)
{
mydac.setValue(channel, val);
if (mydac.getValue(channel) != val)
{
fprintf(stderr, "%d -> %d\n", val, mydac.getValue(channel));
}
}
mydac.setValue(channel, 100);
assertEqual(100, mydac.getValue(channel));
}
}
unittest(test_SW_constructor)
{
DAC8552 mydac(4, 5, 6);
mydac.begin();
for (uint8_t channel = 0; channel < 2; channel++)
{
fprintf(stderr, "CHANNEL %d\n", channel);
for (uint16_t val = 0; val < 65500; val += 30)
{
mydac.setValue(channel, val);
if (mydac.getValue(channel) != val)
{
fprintf(stderr, "%d -> %d\n", val, mydac.getValue(channel));
}
}
mydac.setValue(channel, 100);
assertEqual(100, mydac.getValue(channel));
}
}
unittest(test_powerDown)
{
DAC8552 mydac(4, 5, 6);
mydac.begin();
for (uint8_t channel = 0; channel < 2; channel++)
{
fprintf(stderr, "CHANNEL %d\n", channel);
mydac.setPowerDown(channel, DAC8552_POWERDOWN_NORMAL);
assertEqual(DAC8552_POWERDOWN_NORMAL, mydac.getPowerDownMode(channel));
mydac.setPowerDown(channel, DAC8552_POWERDOWN_1K);
assertEqual(DAC8552_POWERDOWN_1K, mydac.getPowerDownMode(channel));
mydac.setPowerDown(channel, DAC8552_POWERDOWN_100K);
assertEqual(DAC8552_POWERDOWN_100K, mydac.getPowerDownMode(channel));
mydac.setPowerDown(channel, DAC8552_POWERDOWN_HIGH_IMP);
assertEqual(DAC8552_POWERDOWN_HIGH_IMP, mydac.getPowerDownMode(channel));
}
}
unittest_main()
// --------