| | |
| | | #include "CUnit/Basic.h" |
| | | |
| | | #include "scpi/scpi.h" |
| | | #include "../src/utils.h" |
| | | #include "scpi/utils_private.h" |
| | | |
| | | /* |
| | | * CUnit Test Suite |
| | |
| | | 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_locateText() { |
| | | |
| | | const char * v; |
| | |
| | | } |
| | | |
| | | void test_matchPattern() { |
| | | bool_t result; |
| | | scpi_bool_t result; |
| | | |
| | | #define TEST_MATCH_PATTERN(p, s, r) \ |
| | | do { \ |
| | |
| | | } |
| | | |
| | | void test_matchCommand() { |
| | | bool_t result; |
| | | scpi_bool_t result; |
| | | |
| | | #define TEST_MATCH_COMMAND(p, s, r) \ |
| | | do { \ |
| | |
| | | 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 |
| | | } |
| | | |
| | | void test_composeCompoundCommand(void) { |
| | | |
| | | #define TEST_COMPOSE_COMMAND(b, c1_len, c2_pos, c2_len, c2_final, r) \ |
| | | { \ |
| | | char buffer[100]; \ |
| | | char * cmd_prev = buffer; \ |
| | | char * cmd = buffer + c2_pos; \ |
| | | size_t len_prev = c1_len; \ |
| | | size_t len = c2_len; \ |
| | | scpi_bool_t res; \ |
| | | \ |
| | | strcpy(buffer, b); \ |
| | | res = composeCompoundCommand(cmd_prev, len_prev, &cmd, &len); \ |
| | | CU_ASSERT_EQUAL(res, r); \ |
| | | CU_ASSERT_EQUAL(len, strlen(c2_final)); \ |
| | | CU_ASSERT_STRING_EQUAL(cmd, c2_final); \ |
| | | }\ |
| | | |
| | | TEST_COMPOSE_COMMAND("A:B;C", 3, 4, 1, "A:C", TRUE); |
| | | TEST_COMPOSE_COMMAND("A:B;DD", 3, 4, 2, "A:DD", TRUE); |
| | | TEST_COMPOSE_COMMAND("A:B", 0, 0, 3, "A:B", TRUE); |
| | | TEST_COMPOSE_COMMAND("*IDN? ; ABC", 5, 8, 3, "ABC", TRUE); |
| | | TEST_COMPOSE_COMMAND("A:B;*IDN?", 3, 4, 5, "*IDN?", TRUE); |
| | | TEST_COMPOSE_COMMAND("A:B;:C", 3, 4, 2, ":C", TRUE); |
| | | TEST_COMPOSE_COMMAND("B;C", 1, 2, 1, "C", TRUE); |
| | | TEST_COMPOSE_COMMAND("A:B;C:D", 3, 4, 3, "A:C:D", TRUE); |
| | | TEST_COMPOSE_COMMAND(":A:B;C", 4, 5, 1, ":A:C", TRUE); |
| | | TEST_COMPOSE_COMMAND(":A:B;:C", 4, 5, 2, ":C", TRUE); |
| | | TEST_COMPOSE_COMMAND(":A;C", 2, 3, 1, ":C", TRUE); |
| | | |
| | | scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); |
| | | |
| | | } |
| | | |
| | | int main() { |
| | |
| | | || (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, "locateText", test_locateText)) |
| | | || (NULL == CU_add_test(pSuite, "locateStr", test_locateStr)) |
| | | || (NULL == CU_add_test(pSuite, "matchPattern", test_matchPattern)) |
| | | || (NULL == CU_add_test(pSuite, "matchCommand", test_matchCommand)) |
| | | || (NULL == CU_add_test(pSuite, "composeCompoundCommand", test_composeCompoundCommand)) |
| | | ) { |
| | | CU_cleanup_registry(); |
| | | return CU_get_error(); |