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

121 lines
2.2 KiB
C++
Raw Normal View History

2022-06-14 09:20:04 -04:00
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2022-06-14
// PURPOSE: unit tests for the UUID library
// https://github.com/RobTillaart/UUID
// 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 "UUID.h"
unittest_setup()
{
fprintf(stderr, "UUID_LIB_VERSION: %s\n", (char *) UUID_LIB_VERSION);
}
2023-02-02 08:42:13 -05:00
2022-06-14 09:20:04 -04:00
unittest_teardown()
{
}
2022-06-15 01:34:09 -04:00
unittest(test_constants)
{
assertEqual(0, UUID_MODE_VARIANT4);
assertEqual(1, UUID_MODE_RANDOM);
}
2022-06-14 09:20:04 -04:00
unittest(test_generate)
{
UUID uuid;
char u[40], v[40], w[40];
uuid.generate();
strcpy(u, uuid.toCharArray());
assertEqual(36, strlen(u));
strcpy(v, uuid.toCharArray());
assertEqual(36, strlen(v));
assertEqual(u, v);
uuid.generate();
strcpy(v, uuid.toCharArray());
assertEqual(36, strlen(v));
uuid.generate();
strcpy(w, uuid.toCharArray());
assertEqual(36, strlen(w));
assertNotEqual(u, v);
assertNotEqual(u, w);
assertNotEqual(w, v);
}
unittest(test_layout)
{
UUID uuid;
char u[40];
uuid.generate();
strcpy(u, uuid.toCharArray());
fprintf(stderr, ">%s<\n", uuid.toCharArray());
assertEqual(36, strlen(u));
assertEqual('-', u[8]);
assertEqual('-', u[13]);
2022-06-15 01:34:09 -04:00
assertEqual('4', u[15]);
2022-06-14 09:20:04 -04:00
assertEqual('-', u[18]);
assertEqual('-', u[23]);
}
2022-06-15 01:34:09 -04:00
unittest(test_mode)
{
UUID uuid;
assertEqual(UUID_MODE_VARIANT4, uuid.getMode());
uuid.setRandomMode();
assertEqual(UUID_MODE_RANDOM, uuid.getMode());
uuid.setVariant4Mode();
assertEqual(UUID_MODE_VARIANT4, uuid.getMode());
}
unittest(test_printTo)
{
UUID uuid;
assertEqual(36, Serial.print(uuid)); // 36
assertEqual(38, Serial.println(uuid)); // 36 + \n\r
}
2022-06-14 09:20:04 -04:00
unittest_main()
2023-02-02 08:42:13 -05:00
// -- END OF FILE --
2022-06-14 09:20:04 -04:00