#include "test/framework/catch.hpp" #include "src/shellmatta_utils.c" #include TEST_CASE( "shellmatta_utils.c - itoa - 123456 base 10") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(123456, buffer, 10) == 6); REQUIRE_THAT(buffer, Catch::Matchers::Equals("123456")); } TEST_CASE( "shellmatta_utils.c - itoa - 0x0ABBCCDD base 16") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(0x0ABBCCDD, buffer, 16) == 7); REQUIRE_THAT(buffer, Catch::Matchers::Equals("ABBCCDD")); } TEST_CASE( "shellmatta_utils.c - itoa - -574236 base 10") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(-574236, buffer, 10) == 7); REQUIRE_THAT(buffer, Catch::Matchers::Equals("-574236")); } TEST_CASE( "shellmatta_utils.c - itoa - 0x80000000 base 2") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(0x80000000, buffer, 2) == 33); REQUIRE_THAT(buffer, Catch::Matchers::Equals("-10000000000000000000000000000000")); } TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 2") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(0x7FFFFFFF, buffer, 2) == 31); REQUIRE_THAT(buffer, Catch::Matchers::Equals("1111111111111111111111111111111")); } TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 1 - wrong base") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(0x7FFFFFFF, buffer, 1) == 0); REQUIRE_THAT(buffer, Catch::Matchers::Equals("\0")); } TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 17 - wrong base") { char buffer[64]; memset(buffer, 0, sizeof(buffer)); CHECK(utils_shellItoa(0x7FFFFFFF, buffer, 17) == 0); REQUIRE_THAT(buffer, Catch::Matchers::Equals("\0")); }