From da9c3c9f74c0a7eef863798770c24ac955d770de Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周日, 04 10月 2015 18:25:40 +0800 Subject: [PATCH] Resolve #3: Chanel lists parsing --- libscpi/test/test_scpi_utils.c | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-) diff --git a/libscpi/test/test_scpi_utils.c b/libscpi/test/test_scpi_utils.c index af5aadf..b89c485 100644 --- a/libscpi/test/test_scpi_utils.c +++ b/libscpi/test/test_scpi_utils.c @@ -142,6 +142,31 @@ TEST_STR_TO_LONG("18", 1, 1, 8); // octal 1, 8 is ignored } +static void test_strToULong() { + size_t result; + uint32_t val; + +#define TEST_STR_TO_ULONG(s, r, v, b) \ + do { \ + result = strToULong(s, &val, b); \ + CU_ASSERT_EQUAL(val, v); \ + CU_ASSERT_EQUAL(result, r); \ + } while(0) \ + + 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("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 + TEST_STR_TO_LONG("FFFFFFFF", 8, 0xffffffffu, 16); // octal 1, 8 is ignored +} + static void test_strToDouble() { double val; size_t result; @@ -439,6 +464,7 @@ } int main() { + unsigned int result; CU_pSuite pSuite = NULL; /* Initialize the CUnit test registry */ @@ -458,6 +484,7 @@ || (NULL == CU_add_test(pSuite, "longToStr", test_longToStr)) || (NULL == CU_add_test(pSuite, "doubleToStr", test_doubleToStr)) || (NULL == CU_add_test(pSuite, "strToLong", test_strToLong)) + || (NULL == CU_add_test(pSuite, "strToULong", test_strToULong)) || (NULL == CU_add_test(pSuite, "strToDouble", test_strToDouble)) || (NULL == CU_add_test(pSuite, "compareStr", test_compareStr)) || (NULL == CU_add_test(pSuite, "compareStrAndNum", test_compareStrAndNum)) @@ -472,6 +499,7 @@ /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); + result = CU_get_number_of_tests_failed(); CU_cleanup_registry(); - return CU_get_error(); + return result ? result : CU_get_error(); } -- Gitblit v1.9.1