Jan Breuer
2015-04-22 c49b34ae42b691518a1100346d7c749e35bc3ba3
libscpi/test/test_scpi_utils.c
@@ -61,17 +61,40 @@
    CU_ASSERT(strnpbrk(str, 4, "b") == NULL);
    CU_ASSERT(strnpbrk(str, 1, "h") == NULL);
    CU_ASSERT(strnpbrk(str, 4, "xo") == (str + 2));
    CU_ASSERT(strnpbrk(str, 4, "j") == (str + 3));
}
void test_longToStr() {
    char str[32];
    size_t len;
    len = longToStr(10, str, 32, 10);
    len = SCPI_LongToStr(10, str, 32, 10);
    CU_ASSERT(len == 2);
    CU_ASSERT_STRING_EQUAL(str, "10");
    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] == '\0');
    CU_ASSERT(str[2] == '1');
    CU_ASSERT(str[3] == '0');
    CU_ASSERT(str[4] == '\0');
    len = SCPI_LongToStr(10, str, 32, 16);
    CU_ASSERT(len == 1);
    CU_ASSERT(str[0] == 'A');
    CU_ASSERT(str[1] == '\0');
    len = SCPI_LongToStr(10, str, 32, 8);
    CU_ASSERT(len == 2);
    CU_ASSERT(str[0] == '1');
    CU_ASSERT(str[1] == '2');
    CU_ASSERT(str[2] == '\0');
}
void test_doubleToStr() {
@@ -80,7 +103,7 @@
#define TEST_DOUBLE_TO_STR(v, r, s)                     \
    do {                                                \
        result = doubleToStr(v, str, sizeof(str));      \
        result = SCPI_DoubleToStr(v, str, sizeof(str));      \
        CU_ASSERT_EQUAL(result, r);                     \
        CU_ASSERT_STRING_EQUAL(str, s);                 \
    } while(0)                                          \
@@ -163,6 +186,24 @@
    CU_ASSERT_FALSE(compareStr("abcd", 1, "efgh", 1));
    CU_ASSERT_FALSE(compareStr("ABCD", 4, "abcd", 3));
}
void test_compareStrAndNum() {
    CU_ASSERT_TRUE(compareStrAndNum("abcd", 1, "afgh", 1));
    CU_ASSERT_TRUE(compareStrAndNum("ABCD", 4, "abcd", 4));
    CU_ASSERT_TRUE(compareStrAndNum("AbCd", 3, "AbCE", 3));
    CU_ASSERT_TRUE(compareStrAndNum("ABCD", 1, "a", 1));
    CU_ASSERT_FALSE(compareStrAndNum("abcd", 1, "efgh", 1));
    CU_ASSERT_FALSE(compareStrAndNum("ABCD", 4, "abcd", 3));
    CU_ASSERT_TRUE(compareStrAndNum("abcd", 4, "abcd1", 5));
    CU_ASSERT_TRUE(compareStrAndNum("abcd", 4, "abcd123", 7));
    CU_ASSERT_FALSE(compareStrAndNum("abcd", 4, "abcd12A", 7));
    CU_ASSERT_FALSE(compareStrAndNum("abcd", 4, "abcdB12", 7));
    CU_ASSERT_FALSE(compareStrAndNum("abdd", 4, "abcd132", 7));
}
void test_matchPattern() {
@@ -289,6 +330,22 @@
    TEST_MATCH_COMMAND("*IDN?", ":idn?", FALSE); // common command
    TEST_MATCH_COMMAND("*IDN?", ":*idn", FALSE); // common command
    TEST_MATCH_COMMAND("*IDN?", ":*idn?", FALSE); // common command
    TEST_MATCH_COMMAND("ABCdef#", "abc", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("ABCdef#", "abc1324", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("ABCdef#", "abcDef1324", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("ABCdef#", "abcDef124b", FALSE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#:MODulation#:FM#", "abc", FALSE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#:MODulation#:FM#", "outp1:mod10:fm", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#:MODulation#:FM#", "output1:mod10:fm", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#:MODulation#:FM#", "outp1:modulation:fm5", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#:MODulation#:FM#", "output:mod:fm", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#:MODulation#:FM#", "outp1:mod10a:fm", FALSE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "outp1:fm", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "outp1:mod10:fm", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "outp1:fm2", TRUE); // test numeric parameter
    TEST_MATCH_COMMAND("OUTPut#[:MODulation#]:FM#", "output:fm", TRUE); // test numeric parameter
}
int main() {
@@ -313,6 +370,7 @@
            || (NULL == CU_add_test(pSuite, "strToLong", test_strToLong))
            || (NULL == CU_add_test(pSuite, "strToDouble", test_strToDouble))
            || (NULL == CU_add_test(pSuite, "compareStr", test_compareStr))
            || (NULL == CU_add_test(pSuite, "compareStrAndNum", test_compareStrAndNum))
            || (NULL == CU_add_test(pSuite, "matchPattern", test_matchPattern))
            || (NULL == CU_add_test(pSuite, "matchCommand", test_matchCommand))
            ) {