test_compressed_enum_table.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "catch.hpp"
  14. #include "compressed_enum_table.hpp"
  15. #include <cstring>
  16. TEST_CASE("test if CompressedEnumTable works as expected", "[enumtable]")
  17. {
  18. enum class TEnum1 : uint32_t {
  19. ZERO = 0,
  20. ONE = 1,
  21. TWO = 2,
  22. THREE = 3,
  23. };
  24. CompressedEnumTable<TEnum1, 2, 252> table;
  25. memset(table.data(), 0xff, table.byteSize());
  26. for (size_t i = 0; i < table.count(); ++i) {
  27. CHECK(table.get(i) == TEnum1::THREE);
  28. }
  29. table.set(0, TEnum1::ONE);
  30. table.set(1, TEnum1::TWO);
  31. table.set(2, TEnum1::ZERO);
  32. table.set(3, TEnum1::ONE);
  33. table.set(4, TEnum1::TWO);
  34. table.set(5, TEnum1::ZERO);
  35. table.set(6, TEnum1::ONE);
  36. table.set(7, TEnum1::TWO);
  37. table.set(8, TEnum1::ZERO);
  38. table.set(9, TEnum1::ZERO);
  39. table.set(10, TEnum1::ONE);
  40. table.set(11, TEnum1::TWO);
  41. // table.set(12, ...
  42. table.set(13, TEnum1::ZERO);
  43. table.set(14, TEnum1::ONE);
  44. table.set(15, TEnum1::TWO);
  45. // b10010011100100001001001001001001
  46. // h 9 3 9 0 9 2 4 9
  47. CHECK(table.data()[0] == 0x93909249);
  48. }