From ba22a750093f5b918aefd58ba698f38dff6a14e1 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: ćšć, 20 6æ 2013 22:03:49 +0800 Subject: [PATCH] Unexpected character handling --- libscpi/test/test_scpi_utils.c | 43 +++++++++++++++++++++++-------------------- 1 files changed, 23 insertions(+), 20 deletions(-) diff --git a/libscpi/test/test_scpi_utils.c b/libscpi/test/test_scpi_utils.c index 9d2b41a..b3ab4c0 100644 --- a/libscpi/test/test_scpi_utils.c +++ b/libscpi/test/test_scpi_utils.c @@ -38,7 +38,7 @@ char str[32]; size_t len; - len = longToStr(10, str, 32); + len = longToStr(10, str, 32, 10); CU_ASSERT(len == 2); CU_ASSERT(str[0] == '1'); CU_ASSERT(str[1] == '0'); @@ -71,25 +71,25 @@ size_t result; int32_t val; -#define TEST_STR_TO_LONG(s, r, v) \ +#define TEST_STR_TO_LONG(s, r, v, b) \ do { \ - result = strToLong(s, &val); \ + result = strToLong(s, &val, b); \ CU_ASSERT_EQUAL(val, v); \ CU_ASSERT_EQUAL(result, r); \ } while(0) \ - TEST_STR_TO_LONG("", 0, 0); - TEST_STR_TO_LONG("1", 1, 1); - TEST_STR_TO_LONG("10", 2, 10); - TEST_STR_TO_LONG("-50", 3, -50); - TEST_STR_TO_LONG("100MHz", 3, 100); - TEST_STR_TO_LONG("MHz", 0, 0); - TEST_STR_TO_LONG("1.4", 1, 1); - TEST_STR_TO_LONG(" 1", 2, 1); - TEST_STR_TO_LONG(" +100", 5, 100); // space and + - TEST_STR_TO_LONG("0xFF", 4, 255); // hexadecimal FF - TEST_STR_TO_LONG("077", 3, 63); // octal 77 - TEST_STR_TO_LONG("018", 2, 1); // octal 1, 8 is ignored + TEST_STR_TO_LONG("", 0, 0, 10); + TEST_STR_TO_LONG("1", 1, 1, 10); + TEST_STR_TO_LONG("10", 2, 10, 10); + TEST_STR_TO_LONG("-50", 3, -50, 10); + TEST_STR_TO_LONG("100MHz", 3, 100, 10); + TEST_STR_TO_LONG("MHz", 0, 0, 10); + TEST_STR_TO_LONG("1.4", 1, 1, 10); + TEST_STR_TO_LONG(" 1", 2, 1, 10); + TEST_STR_TO_LONG(" +100", 5, 100, 10); // space and + + TEST_STR_TO_LONG("FF", 2, 255, 16); // hexadecimal FF + TEST_STR_TO_LONG("77", 2, 63, 8); // octal 77 + TEST_STR_TO_LONG("18", 1, 1, 8); // octal 1, 8 is ignored } void test_strToDouble() { @@ -138,8 +138,8 @@ void test_locateText() { - char * v; - char * b; + const char * v; + const char * b; size_t l; int result; @@ -152,7 +152,7 @@ result = locateText(v, strlen(v), &b, &l); \ CU_ASSERT(result == ex_res); \ if (result == TRUE) { \ - CU_ASSERT(b == (s + ex_off)); \ + CU_ASSERT(b == (v + ex_off)); \ CU_ASSERT(l == ex_len); \ } else { \ CU_ASSERT(b == NULL); \ @@ -162,6 +162,8 @@ TEST_LOCATE_TEXT("", TRUE, 0, 0); + TEST_LOCATE_TEXT(",", TRUE, 0, 0); + TEST_LOCATE_TEXT("\"\",", TRUE, 1, 0); TEST_LOCATE_TEXT(" ", TRUE, 3, 0); TEST_LOCATE_TEXT("a", TRUE, 0, 1); TEST_LOCATE_TEXT("ab", TRUE, 0, 2); @@ -186,8 +188,8 @@ void test_locateStr() { - char * v; - char * b; + const char * v; + const char * b; size_t l; int result; @@ -209,6 +211,7 @@ } while(0) \ TEST_LOCATE_STR("", TRUE, 0, 0); + TEST_LOCATE_STR(",", TRUE, 0, 0); TEST_LOCATE_STR(" ", TRUE, 3, 0); TEST_LOCATE_STR("a", TRUE, 0, 1); TEST_LOCATE_STR("ab", TRUE, 0, 2); -- Gitblit v1.9.1