From 6acc53b725ddd75772ea5f0777b2dcabf1583b50 Mon Sep 17 00:00:00 2001
From: Iztok Jeras <iztok.jeras@redpitaya.com>
Date: 摹曛, 08 10月 2015 03:00:34 +0800
Subject: [PATCH] integer parser: make buffer sizes more explicit, as sum of bitlength and NULL termination

---
 libscpi/test/test_scpi_utils.c |  384 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 301 insertions(+), 83 deletions(-)

diff --git a/libscpi/test/test_scpi_utils.c b/libscpi/test/test_scpi_utils.c
index dd3bfcc..e24ab1b 100644
--- a/libscpi/test/test_scpi_utils.c
+++ b/libscpi/test/test_scpi_utils.c
@@ -66,33 +66,248 @@
 
 }
 
-static void test_longToStr() {
-    char str[32];
+static void test_Int32ToStr() {
+    const size_t max=32+1;
+    char str[max];
     size_t len;
 
-    len = SCPI_LongToStr(10, str, 32, 10);
-    CU_ASSERT(len == 2);
-    CU_ASSERT_STRING_EQUAL(str, "10");
+    // test conversion to decimal numbers
+    len = SCPI_Int32ToStr(0, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
     CU_ASSERT(str[len] == '\0');
 
-    len = SCPI_LongToStr(10, str, 32, 2);
-    CU_ASSERT(len == 4);
-    CU_ASSERT(str[0] == '1');
-    CU_ASSERT(str[1] == '0');
-    CU_ASSERT(str[2] == '1');
-    CU_ASSERT(str[3] == '0');
-    CU_ASSERT(str[4] == '\0');
-
-    len = SCPI_LongToStr(10, str, 32, 16);
+    len = SCPI_Int32ToStr(1, str, max, 10);
     CU_ASSERT(len == 1);
-    CU_ASSERT(str[0] == 'A');
-    CU_ASSERT(str[1] == '\0');
-    
-    len = SCPI_LongToStr(10, str, 32, 8);
+    CU_ASSERT_STRING_EQUAL(str, "1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(-1, str, max, 10);
     CU_ASSERT(len == 2);
-    CU_ASSERT(str[0] == '1');
-    CU_ASSERT(str[1] == '2');    
-    CU_ASSERT(str[2] == '\0');    
+    CU_ASSERT_STRING_EQUAL(str, "-1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0x7fffffff, str, max, 10);
+    CU_ASSERT(len == 10);
+    CU_ASSERT_STRING_EQUAL(str, "2147483647");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0x80000000, str, max, 10);
+    CU_ASSERT(len == 11);
+    CU_ASSERT_STRING_EQUAL(str, "-2147483648");
+    CU_ASSERT(str[len] == '\0');
+
+    // test conversion to binary numbers
+    len = SCPI_Int32ToStr(0, str, max, 2);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(1, str, max, 2);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(-1, str, max, 2);
+    CU_ASSERT(len == 32);
+    CU_ASSERT_STRING_EQUAL(str, "11111111111111111111111111111111");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0x01234567, str, max, 2);
+    CU_ASSERT(len == 25);
+    CU_ASSERT_STRING_EQUAL(str, "1001000110100010101100111");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0x89abcdef, str, max, 2);
+    CU_ASSERT(len == 32);
+    CU_ASSERT_STRING_EQUAL(str, "10001001101010111100110111101111");
+    CU_ASSERT(str[len] == '\0');
+
+    // test conversion to hexadecimal numbers
+    len = SCPI_Int32ToStr(0x0, str, max, 16);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0x01234567, str, max, 16);
+    CU_ASSERT(len == 7);
+    CU_ASSERT_STRING_EQUAL(str, "1234567");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0x89ABCDEF, str, max, 16);
+    CU_ASSERT(len == 8);
+    CU_ASSERT_STRING_EQUAL(str, "89ABCDEF");
+    CU_ASSERT(str[len] == '\0');
+
+    // test conversion to octal numbers
+    len = SCPI_Int32ToStr(0, str, max, 8);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(0xffffffff, str, max, 8);
+    CU_ASSERT(len == 11);
+    CU_ASSERT_STRING_EQUAL(str, "37777777777");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int32ToStr(076543210, str, max, 8);
+    CU_ASSERT(len == 8);
+    CU_ASSERT_STRING_EQUAL(str, "76543210");
+    CU_ASSERT(str[len] == '\0');
+}
+
+static void test_UInt32ToStr() {
+    const size_t max=32+1;
+    char str[max];
+    size_t len;
+
+    // test conversion to decimal numbers
+    len = SCPI_UInt32ToStr(0, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt32ToStr(1, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt32ToStr(-1, str, max, 10);
+    CU_ASSERT(len == 10);
+    CU_ASSERT_STRING_EQUAL(str, "4294967295");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt32ToStr(0x7fffffff, str, max, 10);
+    CU_ASSERT(len == 10);
+    CU_ASSERT_STRING_EQUAL(str, "2147483647");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt32ToStr(0x80000000, str, max, 10);
+    CU_ASSERT(len == 10);
+    CU_ASSERT_STRING_EQUAL(str, "2147483648");
+    CU_ASSERT(str[len] == '\0');
+}
+
+static void test_Int64ToStr() {
+    const size_t max=64+1;
+    char str[max];
+    size_t len;
+
+    // test conversion to decimal numbers
+    len = SCPI_Int64ToStr(0, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(1, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(-1, str, max, 10);
+    CU_ASSERT(len == 2);
+    CU_ASSERT_STRING_EQUAL(str, "-1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0x7fffffffffffffff, str, max, 10);
+    CU_ASSERT(len == 19);
+    CU_ASSERT_STRING_EQUAL(str, "9223372036854775807");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0x8000000000000000, str, max, 10);
+    CU_ASSERT(len == 20);
+    CU_ASSERT_STRING_EQUAL(str, "-9223372036854775808");
+    CU_ASSERT(str[len] == '\0');
+
+    // test conversion to binary numbers
+    len = SCPI_Int64ToStr(0, str, max, 2);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(1, str, max, 2);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(-1, str, max, 2);
+    CU_ASSERT(len == 64);
+    CU_ASSERT_STRING_EQUAL(str, "1111111111111111111111111111111111111111111111111111111111111111");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0x0123456789abcdef, str, max, 2);
+    CU_ASSERT(len == 57);
+    CU_ASSERT_STRING_EQUAL(str, "100100011010001010110011110001001101010111100110111101111");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0xfedcba9876543210, str, max, 2);
+    CU_ASSERT(len == 64);
+    CU_ASSERT_STRING_EQUAL(str, "1111111011011100101110101001100001110110010101000011001000010000");
+    CU_ASSERT(str[len] == '\0');
+
+    // test conversion to hexadecimal numbers
+    len = SCPI_Int64ToStr(0x0, str, max, 16);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0x0123456789abcdef, str, max, 16);
+    CU_ASSERT(len == 15);
+    CU_ASSERT_STRING_EQUAL(str, "123456789ABCDEF");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0xfedcba9876543210, str, max, 16);
+    CU_ASSERT(len == 16);
+    CU_ASSERT_STRING_EQUAL(str, "FEDCBA9876543210");
+    CU_ASSERT(str[len] == '\0');
+
+    // test conversion to octal numbers
+    len = SCPI_Int64ToStr(0, str, max, 8);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(0xffffffffffffffff, str, max, 8);
+    CU_ASSERT(len == 22);
+    CU_ASSERT_STRING_EQUAL(str, "1777777777777777777777");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_Int64ToStr(076543210, str, max, 8);
+    CU_ASSERT(len == 8);
+    CU_ASSERT_STRING_EQUAL(str, "76543210");
+    CU_ASSERT(str[len] == '\0');
+}
+
+static void test_UInt64ToStr() {
+    const size_t max=64+1;
+    char str[max];
+    size_t len;
+
+    // test conversion to decimal numbers
+    len = SCPI_UInt64ToStr(0, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "0");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt64ToStr(1, str, max, 10);
+    CU_ASSERT(len == 1);
+    CU_ASSERT_STRING_EQUAL(str, "1");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt64ToStr(-1, str, max, 10);
+    CU_ASSERT(len == 20);
+    CU_ASSERT_STRING_EQUAL(str, "18446744073709551615");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt64ToStr(0x7fffffffffffffff, str, max, 10);
+    CU_ASSERT(len == 19);
+    CU_ASSERT_STRING_EQUAL(str, "9223372036854775807");
+    CU_ASSERT(str[len] == '\0');
+
+    len = SCPI_UInt64ToStr(0x8000000000000000, str, max, 10);
+    CU_ASSERT(len == 19);
+    CU_ASSERT_STRING_EQUAL(str, "9223372036854775808");
+    CU_ASSERT(str[len] == '\0');
 }
 
 static void test_doubleToStr() {
@@ -117,17 +332,17 @@
     TEST_DOUBLE_TO_STR(-1.3e-30, 8, "-1.3e-30");
 }
 
-static void test_strToLong() {
+static void test_strToInt32() {
     size_t result;
     int32_t val;
 
 #define TEST_STR_TO_LONG(s, r, v, b)                    \
     do {                                                \
-        result = strToLong(s, &val, b);                 \
+        result = strToInt32(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);
@@ -142,29 +357,29 @@
     TEST_STR_TO_LONG("18", 1, 1, 8); // octal 1, 8 is ignored
 }
 
-static void test_strToULong() {
+static void test_strToUInt32() {
     size_t result;
     uint32_t val;
 
 #define TEST_STR_TO_ULONG(s, r, v, b)                    \
     do {                                                \
-        result = strToULong(s, &val, b);                 \
+        result = strToUInt32(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
+
+    TEST_STR_TO_ULONG("", 0, 0, 10);
+    TEST_STR_TO_ULONG("1", 1, 1, 10);
+    TEST_STR_TO_ULONG("10", 2, 10, 10);
+    TEST_STR_TO_ULONG("100MHz", 3, 100, 10);
+    TEST_STR_TO_ULONG("MHz", 0, 0, 10);
+    TEST_STR_TO_ULONG("1.4", 1, 1, 10);
+    TEST_STR_TO_ULONG(" 1", 2, 1, 10);
+    TEST_STR_TO_ULONG(" +100", 5, 100, 10); // space and +
+    TEST_STR_TO_ULONG("FF", 2, 255, 16); // hexadecimal FF
+    TEST_STR_TO_ULONG("77", 2, 63, 8); // octal 77
+    TEST_STR_TO_ULONG("18", 1, 1, 8); // octal 1, 8 is ignored
+    TEST_STR_TO_ULONG("FFFFFFFF", 8, 0xffffffffu, 16); // octal 1, 8 is ignored
 }
 
 static void test_strToDouble() {
@@ -230,17 +445,17 @@
 
 #define TEST_COMPARE_STR_AND_NUM(s1, l1, s2, l2, v, r)              \
     do {                                                            \
-        num = 0;                                                    \
+        num = -1;                                                    \
         CU_ASSERT_EQUAL(compareStrAndNum(s1, l1, s2, l2, &num),r);  \
         CU_ASSERT_EQUAL(num, v);                                    \
     } while(0);                                                     \
 
-    TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcd", 4, 1, TRUE);
+    TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcd", 4, -1, TRUE);
     TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcd1", 5, 1, TRUE);
     TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcd123", 7, 123, TRUE);
-    TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcd12A", 7, 0, FALSE);
-    TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcdB12", 7, 0, FALSE);
-    TEST_COMPARE_STR_AND_NUM("abdd", 4, "abcd132", 7, 0, FALSE);
+    TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcd12A", 7, -1, FALSE);
+    TEST_COMPARE_STR_AND_NUM("abcd", 4, "abcdB12", 7, -1, FALSE);
+    TEST_COMPARE_STR_AND_NUM("abdd", 4, "abcd132", 7, -1, FALSE);
 }
 
 static void test_matchPattern() {
@@ -268,23 +483,21 @@
 
     #define TEST_MATCH_COMMAND(p, s, r)                         \
     do {                                                        \
-        result = matchCommand(p, s, strlen(s), NULL, 0);        \
+        result = matchCommand(p, s, strlen(s), NULL, 0, 0);     \
         CU_ASSERT_EQUAL(result, r);                             \
     } while(0)                                                  \
 
-    #define TEST_MATCH_COMMAND2(p, s, r, ...)                   \
+    #define NOPAREN(...) __VA_ARGS__
+
+    #define TEST_MATCH_COMMAND2(p, s, r, v)                     \
     do {                                                        \
-        int32_t evalues[] = {__VA_ARGS__};                      \
+        int32_t evalues[] = {NOPAREN v};                        \
         unsigned int cnt = (sizeof(evalues)/4);                 \
-        result = matchCommand(p, s, strlen(s), values, 20);     \
+        result = matchCommand(p, s, strlen(s), values, 20, -1); \
         CU_ASSERT_EQUAL(result, r);                             \
-        if (cnt > 0) CU_ASSERT_EQUAL(evalues[0], values[0]);    \
-        if (cnt > 1) CU_ASSERT_EQUAL(evalues[1], values[1]);    \
-        if (cnt > 2) CU_ASSERT_EQUAL(evalues[2], values[2]);    \
-        if (cnt > 3) CU_ASSERT_EQUAL(evalues[3], values[3]);    \
-        if (cnt > 4) CU_ASSERT_EQUAL(evalues[4], values[4]);    \
-        if (cnt > 5) CU_ASSERT_EQUAL(evalues[5], values[5]);    \
-        if (cnt > 6) CU_ASSERT_EQUAL(evalues[6], values[6]);    \
+        {unsigned int i; for (i = 0; i<cnt; i++) {              \
+            CU_ASSERT_EQUAL(evalues[i], values[i]);             \
+        }}                                                      \
     } while(0)                                                  \
 
     TEST_MATCH_COMMAND("A", "a", TRUE);
@@ -403,32 +616,32 @@
     TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "outp1:fm2", TRUE); // test numeric parameter
     TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE); // test numeric parameter
 
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp3:mod10:fm", TRUE, 3, 10, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output3:mod10:fm", TRUE, 3, 10, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp30:modulation:fm5", TRUE, 30, 1, 5); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output:mod:fm", TRUE, 1, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm", TRUE, 3, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:mod10:fm", TRUE, 3, 10, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm2", TRUE, 3, 1, 2); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE, 1, 1, 1); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp3:mod10:fm", TRUE, (3, 10, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output3:mod10:fm", TRUE, (3, 10, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "outp30:modulation:fm5", TRUE, (30, -1, 5)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM#", "output:mod:fm", TRUE, (-1, -1, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm", TRUE, (3, -1, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:mod10:fm", TRUE, (3, 10, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "outp3:fm2", TRUE, (3, -1, 2)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE, (-1, -1, -1)); // test numeric parameter
 
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp3:mod:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output3:mod:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp30:modulation:fm5", TRUE, 30, 5); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output:mod:fm", TRUE, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:mod:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm2", TRUE, 3, 2); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "output:fm", TRUE, 1, 1); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp3:mod:fm", TRUE, (3, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output3:mod:fm", TRUE, (3, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "outp30:modulation:fm5", TRUE, (30, 5)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation:FM#", "output:mod:fm", TRUE, (-1, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm", TRUE, (3, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:mod:fm", TRUE, (3, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "outp3:fm2", TRUE, (3, 2)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation]:FM#", "output:fm", TRUE, (-1, -1)); // test numeric parameter
 
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp3:mod10:fm", TRUE, 3, 10); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output3:mod10:fm", TRUE, 3, 10); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp30:modulation:fm", TRUE, 30, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output:mod:fm", TRUE, 1, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:mod10:fm", TRUE, 3, 10); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, 3, 1); // test numeric parameter
-    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "output:fm", TRUE, 1, 1); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp3:mod10:fm", TRUE, (3, 10)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output3:mod10:fm", TRUE, (3, 10)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "outp30:modulation:fm", TRUE, (30, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#:MODulation#:FM", "output:mod:fm", TRUE, (-1, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, (3, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:mod10:fm", TRUE, (3, 10)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "outp3:fm", TRUE, (3, -1)); // test numeric parameter
+    TEST_MATCH_COMMAND2("OUTPut#[:MODulation#]:FM", "output:fm", TRUE, (-1, -1)); // test numeric parameter
 }
 
 static void test_composeCompoundCommand(void) {
@@ -464,6 +677,7 @@
 }
 
 int main() {
+    unsigned int result;
     CU_pSuite pSuite = NULL;
 
     /* Initialize the CUnit test registry */
@@ -480,10 +694,13 @@
     /* Add the tests to the suite */
     if (0
             || (NULL == CU_add_test(pSuite, "strnpbrk", test_strnpbrk))
-            || (NULL == CU_add_test(pSuite, "longToStr", test_longToStr))
+            || (NULL == CU_add_test(pSuite, "Int32ToStr", test_Int32ToStr))
+            || (NULL == CU_add_test(pSuite, "UInt32ToStr", test_UInt32ToStr))
+            || (NULL == CU_add_test(pSuite, "Int64ToStr", test_Int64ToStr))
+            || (NULL == CU_add_test(pSuite, "UInt64ToStr", test_UInt64ToStr))
             || (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, "strToInt32", test_strToInt32))
+            || (NULL == CU_add_test(pSuite, "strToUInt32", test_strToUInt32))
             || (NULL == CU_add_test(pSuite, "strToDouble", test_strToDouble))
             || (NULL == CU_add_test(pSuite, "compareStr", test_compareStr))
             || (NULL == CU_add_test(pSuite, "compareStrAndNum", test_compareStrAndNum))
@@ -498,6 +715,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