| 1 | #ifdef HAVE_CONFIG_H |
| 2 | #include <config.h> |
| 3 | #endif |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <inttypes.h> |
| 7 | #include <string.h> |
| 8 | #include <stdint.h> |
| 9 | #include "strto.h" |
| 10 | #include "strto.c" |
| 11 | |
| 12 | int main(void) |
| 13 | { |
| 14 | |
| 15 | #define TEST_strto_uint8_hex(input, expected_result) do { \ |
| 16 | if (strto_uint8_hex(input, strlen(input), NULL) != (expected_result)) {\ |
| 17 | fprintf(stderr, "strto_uint8_hex(%s) != %"PRIu8"\n", input, expected_result);\ |
| 18 | return 1;\ |
| 19 | }\ |
| 20 | } while (0) |
| 21 | |
| 22 | TEST_strto_uint8_hex("0", 0); |
| 23 | TEST_strto_uint8_hex("1", 1); |
| 24 | TEST_strto_uint8_hex("ff", 255); |
| 25 | TEST_strto_uint8_hex("FF", 255); |
| 26 | TEST_strto_uint8_hex("Ff", 255); |
| 27 | TEST_strto_uint8_hex("fF", 255); |
| 28 | TEST_strto_uint8_hex("10", 16); |
| 29 | TEST_strto_uint8_hex("11", 17); |
| 30 | TEST_strto_uint8_hex("a", 10); |
| 31 | TEST_strto_uint8_hex("0a", 10); |
| 32 | TEST_strto_uint8_hex("00", 0); |
| 33 | TEST_strto_uint8_hex("01", 1); |
| 34 | |
| 35 | #define TEST_strto_uint16_hex(input, expected_result) do { \ |
| 36 | if (strto_uint16_hex(input, strlen(input), NULL) != (expected_result)) {\ |
| 37 | fprintf(stderr, "strto_uint16_hex(%s) != %"PRIu16"\n", input, expected_result);\ |
| 38 | return 1;\ |
| 39 | }\ |
| 40 | } while (0) |
| 41 | |
| 42 | TEST_strto_uint16_hex("0", 0); |
| 43 | TEST_strto_uint16_hex("1", 1); |
| 44 | TEST_strto_uint16_hex("ff", 255); |
| 45 | TEST_strto_uint16_hex("FF", 255); |
| 46 | TEST_strto_uint16_hex("Ff", 255); |
| 47 | TEST_strto_uint16_hex("fF", 255); |
| 48 | TEST_strto_uint16_hex("10", 16); |
| 49 | TEST_strto_uint16_hex("11", 17); |
| 50 | TEST_strto_uint16_hex("a", 10); |
| 51 | TEST_strto_uint16_hex("0a", 10); |
| 52 | TEST_strto_uint16_hex("00", 0); |
| 53 | TEST_strto_uint16_hex("01", 1); |
| 54 | |
| 55 | TEST_strto_uint16_hex("fFfF", 0xffff); |
| 56 | TEST_strto_uint16_hex("FFFF", 0xffff); |
| 57 | TEST_strto_uint16_hex("ffff", 0xffff); |
| 58 | TEST_strto_uint16_hex("aaaa", 0xaaaa); |
| 59 | TEST_strto_uint16_hex("0101", 0x0101); |
| 60 | TEST_strto_uint16_hex("1010", 0x1010); |
| 61 | TEST_strto_uint16_hex("1111", 0x1111); |
| 62 | TEST_strto_uint16_hex("0000", 0x0000); |
| 63 | TEST_strto_uint16_hex("000", 0x000); |
| 64 | TEST_strto_uint16_hex("8000", 0x8000); |
| 65 | TEST_strto_uint16_hex("0", 0x0); |
| 66 | TEST_strto_uint16_hex("1234", 0x1234); |
| 67 | |
| 68 | return 0; |
| 69 | } |