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

136 lines
3.0 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-23
// PURPOSE: unit tests for the FRAM library
// https://github.com/RobTillaart/FRAM_I2C
// 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 "FRAM.h"
unittest_setup()
{
2021-12-18 09:02:32 -05:00
fprintf(stderr, "FRAM_LIB_VERSION: %s\n", (char*) FRAM_LIB_VERSION);
2021-01-29 06:31:58 -05:00
}
2021-12-18 09:02:32 -05:00
2021-01-29 06:31:58 -05:00
unittest_teardown()
{
}
2021-12-18 09:02:32 -05:00
unittest(test_constants)
2021-01-29 06:31:58 -05:00
{
2021-12-18 09:02:32 -05:00
assertEqual( 0, FRAM_OK );
assertEqual(-10, FRAM_ERROR_ADDR );
assertEqual(-11, FRAM_ERROR_I2C );
assertEqual(-12, FRAM_ERROR_CONNECT);
2023-02-26 09:02:10 -05:00
2022-03-25 05:04:48 -04:00
assertEqual(512, FRAM_MB85RC04 );
assertEqual(2048, FRAM_MB85RC16 );
assertEqual(8192, FRAM_MB85RC64T );
2023-09-07 08:07:49 -04:00
assertEqual(8192, FRAM_MB85RC64V );
2022-03-25 05:04:48 -04:00
assertEqual(16384, FRAM_MB85RC128A);
assertEqual(32768, FRAM_MB85RC256V);
assertEqual(65536, FRAM_MB85RC512T);
assertEqual(131072, FRAM_MB85RC1MT );
2021-01-29 06:31:58 -05:00
}
2021-12-18 09:02:32 -05:00
2021-01-29 06:31:58 -05:00
unittest(test_constructor)
{
FRAM fram49;
FRAM fram50;
FRAM fram52;
FRAM fram57;
Wire.begin();
2021-12-18 09:02:32 -05:00
fprintf(stderr, "\n Different constructors\n");
2021-01-29 06:31:58 -05:00
assertEqual(FRAM_ERROR_ADDR, fram49.begin(0x49));
assertEqual(FRAM_OK, fram50.begin());
assertEqual(FRAM_OK, fram52.begin(0x52));
assertEqual(FRAM_OK, fram57.begin(0x57, 4));
2021-12-18 09:02:32 -05:00
fprintf(stderr, "\n no writeProtect pin defined\n");
2021-01-29 06:31:58 -05:00
assertFalse(fram50.setWriteProtect(true));
assertFalse(fram50.getWriteProtect());
assertFalse(fram50.setWriteProtect(false));
assertFalse(fram50.getWriteProtect());
2021-12-18 09:02:32 -05:00
fprintf(stderr, "\n writeProtect pin defined\n");
2021-01-29 06:31:58 -05:00
assertTrue(fram57.setWriteProtect(true));
assertTrue(fram57.getWriteProtect());
assertTrue(fram57.setWriteProtect(false));
assertFalse(fram57.getWriteProtect());
2021-12-18 09:02:32 -05:00
fprintf(stderr, "\n all fail as nothing connected\n");
2023-09-07 08:07:49 -04:00
assertEqual(0xFFF, fram50.getManufacturerID());
assertEqual(0xFFF, fram50.getProductID());
2021-01-29 06:31:58 -05:00
assertEqual(0, fram50.getSize());
}
2021-12-18 09:02:32 -05:00
2022-03-25 05:04:48 -04:00
unittest(test_getSizeBytes)
{
FRAM fram;
Wire.begin();
2023-02-26 09:02:10 -05:00
2022-03-25 05:04:48 -04:00
assertEqual(0, fram.getSizeBytes());
fram.setSizeBytes(FRAM_MB85RC256V);
assertEqual(32768, fram.getSizeBytes());
2023-02-26 09:02:10 -05:00
2023-09-07 08:07:49 -04:00
FRAM32 f32;
assertEqual(0, f32.getSizeBytes());
f32.setSizeBytes(FRAM_MB85RC1MT);
assertEqual(131072, f32.getSizeBytes());
2023-02-26 09:02:10 -05:00
FRAM11 f11;
assertEqual(2, f11.getSize());
assertEqual(2048, f11.getSizeBytes());
FRAM9 f9;
assertEqual(0, f9.getSize());
assertEqual(512, f9.getSizeBytes());
2022-03-25 05:04:48 -04:00
}
unittest(test_clear)
{
FRAM fram;
Wire.begin();
2023-02-26 09:02:10 -05:00
2022-03-25 05:04:48 -04:00
// note size is not set.
assertEqual(0, fram.clear());
assertEqual(0, fram.clear(0xFF));
}
2021-01-29 06:31:58 -05:00
unittest_main()
2023-02-26 09:02:10 -05:00
// -- END OF FILE --