itoa.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "test/framework/catch.hpp"
  2. #include "src/shellmatta_utils.c"
  3. #include <string.h>
  4. TEST_CASE( "shellmatta_utils.c - itoa - 123456 base 10" ) {
  5. char buffer[64];
  6. memset(buffer, 0, sizeof(buffer));
  7. CHECK( utils_shellItoa(123456, buffer, 10) == 6 );
  8. REQUIRE( strcmp(buffer, "123456") == 0);
  9. }
  10. TEST_CASE( "shellmatta_utils.c - itoa - 0x0ABBCCDD base 16") {
  11. char buffer[64];
  12. memset(buffer, 0, sizeof(buffer));
  13. CHECK( utils_shellItoa(0x0ABBCCDD, buffer, 16) == 7 );
  14. REQUIRE( strcmp(buffer, "ABBCCDD") == 0);
  15. }
  16. TEST_CASE( "shellmatta_utils.c - itoa - -574236 base 10") {
  17. char buffer[64];
  18. memset(buffer, 0, sizeof(buffer));
  19. CHECK( utils_shellItoa(-574236, buffer, 10) == 7 );
  20. REQUIRE( strcmp(buffer, "-574236") == 0);
  21. }
  22. TEST_CASE( "shellmatta_utils.c - itoa - 0x80000000 base 2") {
  23. char buffer[64];
  24. memset(buffer, 0, sizeof(buffer));
  25. CHECK( utils_shellItoa(0x80000000, buffer, 2) == 33 );
  26. REQUIRE( strcmp(buffer, "-10000000000000000000000000000000") == 0);
  27. }
  28. TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 2") {
  29. char buffer[64];
  30. memset(buffer, 0, sizeof(buffer));
  31. CHECK( utils_shellItoa(0x7FFFFFFF, buffer, 2) == 31 );
  32. REQUIRE( strcmp(buffer, "1111111111111111111111111111111") == 0);
  33. }
  34. TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 1 - wrong base") {
  35. char buffer[64];
  36. memset(buffer, 0, sizeof(buffer));
  37. CHECK( utils_shellItoa(0x7FFFFFFF, buffer, 1) == 0 );
  38. REQUIRE( strcmp(buffer, "\0") == 0);
  39. }
  40. TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 17 - wrong base") {
  41. char buffer[64];
  42. memset(buffer, 0, sizeof(buffer));
  43. CHECK( utils_shellItoa(0x7FFFFFFF, buffer, 17) == 0 );
  44. REQUIRE( strcmp(buffer, "\0") == 0);
  45. }