| | |
| | | err_buffer[0] = 0; |
| | | err_buffer_pos = 0; |
| | | |
| | | SCPI_RegClearBits(&scpi_context, SCPI_REG_STB, STB_QMA); |
| | | SCPI_EventClear(&scpi_context); |
| | | SCPI_ErrorClear(&scpi_context); |
| | | } |
| | |
| | | TEST_INPUT("*IDN?\r\n*IDN?\r\n*IDN?\r\n*IDN?\r\n", "MA,IN,0,VER\r\nMA,IN,0,VER\r\nMA,IN,0,VER\r\nMA,IN,0,VER\r\n"); |
| | | output_buffer_clear(); |
| | | |
| | | TEST_INPUT("*IDN?;*IDN?;*IDN?;*IDN?\r\n", "MA,IN,0,VER;MA,IN,0,VER;MA,IN,0,VER;MA,IN,0,VER\r\n"); |
| | | output_buffer_clear(); |
| | | |
| | | TEST_INPUT("*IDN?;*OPC;*IDN?\r\n", "MA,IN,0,VER;MA,IN,0,VER\r\n"); |
| | | output_buffer_clear(); |
| | | |
| | | /* Test one command in multiple buffers */ |
| | | TEST_INPUT("*IDN?", ""); |
| | | TEST_INPUT("\r\n", "MA,IN,0,VER\r\n"); |
| | |
| | | output_buffer_clear(); |
| | | |
| | | /* Test ctree traversal */ |
| | | TEST_INPUT("TEST:TREEA?;TREEB?\r\n", "10\r\n20\r\n"); |
| | | TEST_INPUT("TEST:TREEA?;TREEB?\r\n", "10;20\r\n"); |
| | | output_buffer_clear(); |
| | | |
| | | TEST_INPUT("TEST:TREEA?;:TEXT? \"PARAM1\", \"PARAM2\"\r\n", "10\r\n\"PARAM2\"\r\n"); |
| | | TEST_INPUT("TEST:TREEA?;:TEXT? \"PARAM1\", \"PARAM2\"\r\n", "10;\"PARAM2\"\r\n"); |
| | | output_buffer_clear(); |
| | | |
| | | CU_ASSERT_EQUAL(err_buffer_pos, 0); |
| | |
| | | |
| | | srq_val = 0; |
| | | TEST_IEEE4882("ABCD\r\n", ""); /* "Undefined header" cause command error */ |
| | | CU_ASSERT_EQUAL(srq_val, 96); /* value of STB as service request */ |
| | | TEST_IEEE4882("*STB?\r\n", "96\r\n"); /* Event status register + Service request */ |
| | | CU_ASSERT_EQUAL(srq_val, (STB_ESR | STB_SRQ | STB_QMA)); /* value of STB as service request */ |
| | | TEST_IEEE4882("*STB?\r\n", "100\r\n"); /* Event status register + Service request */ |
| | | TEST_IEEE4882("*ESR?\r\n", "32\r\n"); /* Command error */ |
| | | |
| | | TEST_IEEE4882("*STB?\r\n", "0\r\n"); |
| | | TEST_IEEE4882("*STB?\r\n", "68\r\n"); /* Error queue is still not empty */ |
| | | TEST_IEEE4882("*ESR?\r\n", "0\r\n"); |
| | | |
| | | TEST_IEEE4882("SYST:ERR:NEXT?\r\n", "-113,\"Undefined header\"\r\n"); |
| | | TEST_IEEE4882("SYST:ERR:NEXT?\r\n", "0,\"No error\"\r\n"); |
| | | |
| | | TEST_IEEE4882("*STB?\r\n", "0\r\n"); /* Error queue is now empty */ |
| | | |
| | | RST_executed = FALSE; |
| | | TEST_IEEE4882("*RST\r\n", ""); |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | |
| | | #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); |
| | | TEST_ParamCopyText("\"\"", TRUE, "", 0, TRUE, 0); |
| | | TEST_ParamCopyText("", FALSE, "", 0, FALSE, 0); |
| | | TEST_ParamCopyText("\"\"", FALSE, "", 0, TRUE, 0); |
| | | } |
| | | |
| | | |
| | | int main() { |
| | | unsigned int result; |
| | | CU_pSuite pSuite = NULL; |
| | | |
| | | /* Initialize the CUnit test registry */ |
| | |
| | | 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(); |
| | |
| | | /* 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(); |
| | | } |
| | | |