From 8fbdbb12aabda25b0da53016b2819fa3a14f359b Mon Sep 17 00:00:00 2001 From: koeart <koeart@zwoelfelf.org> Date: 周一, 24 8月 2015 06:07:53 +0800 Subject: [PATCH] Update parser example with ParamCopyText --- libscpi/test/test_parser.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 files changed, 39 insertions(+), 3 deletions(-) diff --git a/libscpi/test/test_parser.c b/libscpi/test/test_parser.c index 84761c5..5365f84 100644 --- a/libscpi/test/test_parser.c +++ b/libscpi/test/test_parser.c @@ -367,6 +367,7 @@ TEST_ParamDouble("#B101010", TRUE, 42, TRUE, 0); TEST_ParamDouble("#H101010", TRUE, 1052688, TRUE, 0); TEST_ParamDouble("#Q10", TRUE, 8, TRUE, 0); + TEST_ParamDouble("#HFFFFFFFF", TRUE, 0xFFFFFFFFu, TRUE, 0); TEST_ParamDouble("", TRUE, 0, FALSE, -109); // missing parameter TEST_ParamDouble("abcd", TRUE, 0, FALSE, -104); // Data type error @@ -406,6 +407,40 @@ } +#define TEST_ParamCopyText(data, mandatory, expected_value, expected_len, expected_result, expected_error_code) \ +{ \ + char value[100]; \ + size_t value_len; \ + scpi_bool_t result; \ + int16_t errCode; \ + \ + SCPI_CoreCls(&scpi_context); \ + scpi_context.input_count = 0; \ + scpi_context.param_list.lex_state.buffer = data; \ + scpi_context.param_list.lex_state.len = strlen(scpi_context.param_list.lex_state.buffer);\ + scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer; \ + result = SCPI_ParamCopyText(&scpi_context, value, sizeof(value), &value_len, mandatory);\ + /*printf("%.*s\r\n", (int)value_len, value);*/ \ + errCode = SCPI_ErrorPop(&scpi_context); \ + CU_ASSERT_EQUAL(result, expected_result); \ + if (expected_result) { \ + CU_ASSERT_STRING_EQUAL(value, expected_value); \ + CU_ASSERT_EQUAL(value_len, expected_len); \ + } \ + CU_ASSERT_EQUAL(errCode, expected_error_code); \ +} + +static void testSCPI_ParamCopyText(void) { + TEST_ParamCopyText("\'abc\'", TRUE, "abc", 3, TRUE, 0); + TEST_ParamCopyText("\"abc\"", TRUE, "abc", 3, TRUE, 0); + TEST_ParamCopyText("\'a\'", TRUE, "a", 1, TRUE, 0); + TEST_ParamCopyText("\'a\'\'c\'", TRUE, "a\'c", 3, TRUE, 0); + TEST_ParamCopyText("\'a\"c\'", TRUE, "a\"c", 3, TRUE, 0); + TEST_ParamCopyText("\"a\"\"c\"", TRUE, "a\"c", 3, TRUE, 0); + TEST_ParamCopyText("\"a\'c\"", TRUE, "a\'c", 3, TRUE, 0); +} + + int main() { CU_pSuite pSuite = NULL; @@ -424,9 +459,10 @@ if ((NULL == CU_add_test(pSuite, "SCPI_ParamInt", testSCPI_ParamInt)) || (NULL == CU_add_test(pSuite, "SCPI_ParamDouble", testSCPI_ParamDouble)) || (NULL == CU_add_test(pSuite, "SCPI_ParamCharacters", testSCPI_ParamCharacters)) - || (NULL == CU_add_test(pSuite, "Commands handling", testCommandsHandling)) - || (NULL == CU_add_test(pSuite, "Error handling", testErrorHandling)) - || (NULL == CU_add_test(pSuite, "IEEE 488.2 Mandatory commands", testIEEE4882)) + || (NULL == CU_add_test(pSuite, "SCPI_ParamCopyText", testSCPI_ParamCopyText)) + || (NULL == CU_add_test(pSuite, "Commands handling", testCommandsHandling)) + || (NULL == CU_add_test(pSuite, "Error handling", testErrorHandling)) + || (NULL == CU_add_test(pSuite, "IEEE 488.2 Mandatory commands", testIEEE4882)) ) { CU_cleanup_registry(); return CU_get_error(); -- Gitblit v1.9.1