UtilityTests.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "../Tests.hpp"
  2. #include "core/utils/Utility.hpp"
  3. static void testPopCount() {
  4. CORE_TEST_EQUAL(4, Core::popCount(0xF));
  5. CORE_TEST_EQUAL(0, Core::popCount(0x0));
  6. CORE_TEST_EQUAL(2, Core::popCount(0x6));
  7. CORE_TEST_EQUAL(7, Core::popCount(0x7F));
  8. CORE_TEST_EQUAL(3, Core::popCount(0x2A));
  9. CORE_TEST_EQUAL(32, Core::popCount(0xFFFFFFFF));
  10. CORE_TEST_EQUAL(64, Core::popCount(0xFFFFFFFFFFFFFFFFL));
  11. CORE_TEST_EQUAL(44, Core::popCount(0xFFFF0FFFFFFF));
  12. CORE_TEST_EQUAL(32, Core::popCount(-1));
  13. }
  14. static void testIf() {
  15. CORE_TEST_TRUE((Core::IsSame<Core::If<true, int, double>, int>));
  16. CORE_TEST_TRUE((Core::IsSame<Core::If<false, int, double>, double>));
  17. }
  18. static void testNegativeArguments() {
  19. char from[16];
  20. Core::memorySet(from, 1, sizeof(from));
  21. Core::memorySet(from, 0, -1);
  22. char to[16];
  23. Core::memorySet(to, 1, sizeof(to));
  24. Core::memoryCopy(to, from, -1);
  25. CORE_TEST_TRUE(Core::memoryCompare(from, to, sizeof(from)));
  26. }
  27. static void testNegativeRellocate() {
  28. char* buffer = nullptr;
  29. CORE_TEST_ERROR(Core::reallocate(buffer, 16));
  30. CORE_TEST_TRUE(buffer != nullptr);
  31. CORE_TEST_ERROR(Core::reallocate(buffer, -1));
  32. CORE_TEST_TRUE(buffer == nullptr);
  33. }
  34. void Core::testUtility() {
  35. testPopCount();
  36. testIf();
  37. testNegativeArguments();
  38. testNegativeRellocate();
  39. }