enable_alignment_1.cpp 920 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #define ARDUINOJSON_ENABLE_ALIGNMENT 1
  2. #include <ArduinoJson.h>
  3. #include <catch.hpp>
  4. TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 1") {
  5. using namespace ARDUINOJSON_NAMESPACE;
  6. const size_t N = sizeof(void*);
  7. SECTION("isAligned()") {
  8. CHECK(isAligned(0) == true);
  9. CHECK(isAligned(1) == false);
  10. CHECK(isAligned(N) == true);
  11. CHECK(isAligned(N + 1) == false);
  12. CHECK(isAligned(2 * N) == true);
  13. CHECK(isAligned(2 * N + 1) == false);
  14. }
  15. SECTION("addPadding()") {
  16. CHECK(addPadding(0) == 0);
  17. CHECK(addPadding(1) == N);
  18. CHECK(addPadding(N) == N);
  19. CHECK(addPadding(N + 1) == 2 * N);
  20. }
  21. SECTION("AddPadding<>") {
  22. const size_t a = AddPadding<0>::value;
  23. CHECK(a == 0);
  24. const size_t b = AddPadding<1>::value;
  25. CHECK(b == N);
  26. const size_t c = AddPadding<N>::value;
  27. CHECK(c == N);
  28. const size_t d = AddPadding<N + 1>::value;
  29. CHECK(d == 2 * N);
  30. }
  31. }