#include "../../src/ErrorSimulator.hpp" #include "../Tests.hpp" #include "core/utils/Utility.hpp" static void testPopCount() { CORE_TEST_EQUAL(4, Core::popCount(0xF)); CORE_TEST_EQUAL(0, Core::popCount(0x0)); CORE_TEST_EQUAL(2, Core::popCount(0x6)); CORE_TEST_EQUAL(7, Core::popCount(0x7F)); CORE_TEST_EQUAL(3, Core::popCount(0x2A)); CORE_TEST_EQUAL(32, Core::popCount(0xFFFFFFFF)); CORE_TEST_EQUAL(64, Core::popCount(0xFFFFFFFFFFFFFFFFL)); CORE_TEST_EQUAL(44, Core::popCount(0xFFFF0FFFFFFF)); CORE_TEST_EQUAL(32, Core::popCount(-1)); } static void testIf() { CORE_TEST_TRUE((Core::IsSame, int>)); CORE_TEST_TRUE((Core::IsSame, double>)); } static void testZeroRellocate() { char* buffer = nullptr; CORE_TEST_ERROR(Core::reallocate(buffer, 16)); CORE_TEST_TRUE(buffer != nullptr); CORE_TEST_ERROR(Core::reallocate(buffer, 0)); CORE_TEST_TRUE(buffer == nullptr); } static void testReallocateFail() { #ifdef ERROR_SIMULATOR char* buffer = nullptr; Core::Fail::realloc = true; CORE_TEST_EQUAL(Core::ErrorCode::OUT_OF_MEMORY, Core::reallocate(buffer, 16)); CORE_TEST_TRUE(buffer == nullptr); Core::Fail::realloc = false; #endif } void Core::testUtility() { testPopCount(); testIf(); testZeroRellocate(); testReallocateFail(); }