|
@@ -0,0 +1,156 @@
|
|
|
+#include "test/framework/catch.hpp"
|
|
|
+#include "src/shellmatta_utils.c"
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+SCENARIO("Check utils_shellAsciiToUInt32 with valid strings")
|
|
|
+{
|
|
|
+ GIVEN("Initialized shellmatta utils module")
|
|
|
+ {
|
|
|
+ shellmatta_retCode_t ret;
|
|
|
+ uint32_t result = 0xFFFFFFFFu;
|
|
|
+ WHEN("Passing 123456789 with base 10")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"123456789", &result, 10u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 123456789);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing 4294967295 with base 10")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"4294967295", &result, 10u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 4294967295);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing 110100100001110011100011 with base 2")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"110100100001110011100011", &result, 2u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 0b110100100001110011100011);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing 435476600 with base 8")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"435476600", &result, 8u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 0435476600);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing AABBCCDD with base 16")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"AABBCCDD", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 0xAABBCCDDu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing deadbeef with base 16")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"deadbeef", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 0xdeadbeefu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing an empty string with base 16")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns successfully")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ REQUIRE(result == 0u);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+SCENARIO("Check utils_shellAsciiToUInt32 with invalid strings")
|
|
|
+{
|
|
|
+ GIVEN("Initialized shellmatta utils module")
|
|
|
+ {
|
|
|
+ shellmatta_retCode_t ret;
|
|
|
+ uint32_t result = 0xFFFFFFFFu;
|
|
|
+ WHEN("Passing 4294967296 with base 10 - overflow")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"4294967296", &result, 10u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ REQUIRE(ret == SHELLMATTA_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing 123456 with base 2 - wrong base")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"123456", &result, 2u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ REQUIRE(ret == SHELLMATTA_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing FOOBAR with base 16 - wrong characters")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"FOOBAR", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ REQUIRE(ret == SHELLMATTA_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing = with base 16 - wrong characters")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"=", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ REQUIRE(ret == SHELLMATTA_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing / with base 16 - wrong characters")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"/", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ REQUIRE(ret == SHELLMATTA_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing } with base 16 - wrong characters")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"}", &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ REQUIRE(ret == SHELLMATTA_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing invalid string")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32(NULL, &result, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_USE_FAULT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing invalid result")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"", NULL, 16u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_USE_FAULT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WHEN("Passing invalid base")
|
|
|
+ {
|
|
|
+ ret = utils_shellAsciiToUInt32((char*)"", &result, 17u);
|
|
|
+ THEN("utils_shellAsciiToUInt32 returns an error")
|
|
|
+ {
|
|
|
+ CHECK(ret == SHELLMATTA_USE_FAULT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|