From 3a0d40729383c42af1cef194abc56182955fb9c9 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周日, 24 4月 2016 16:57:16 +0800
Subject: [PATCH] Fix test and examples to work with extended errors

---
 libscpi/test/test_parser.c |  115 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 61 insertions(+), 54 deletions(-)

diff --git a/libscpi/test/test_parser.c b/libscpi/test/test_parser.c
index 580a721..f08f692 100644
--- a/libscpi/test/test_parser.c
+++ b/libscpi/test/test_parser.c
@@ -184,7 +184,7 @@
 static char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH];
 
 #define SCPI_ERROR_QUEUE_SIZE 4
-static int16_t scpi_error_queue_data[SCPI_ERROR_QUEUE_SIZE];
+static scpi_error_t scpi_error_queue_data[SCPI_ERROR_QUEUE_SIZE];
 
 static int init_suite(void) {
     SCPI_Init(&scpi_context,
@@ -193,7 +193,8 @@
             scpi_units_def,
             "MA", "IN", NULL, "VER",
             scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH,
-            scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE);
+            scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE,
+            NULL, 0);
 
     return 0;
 }
@@ -387,7 +388,7 @@
 {                                                                                       \
     int32_t value;                                                                      \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -396,12 +397,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamInt32(&scpi_context, &value, mandatory);                         \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value, expected_value);                                         \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamInt32(void) {
@@ -426,7 +427,7 @@
 {                                                                                       \
     uint32_t value;                                                                     \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -435,12 +436,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamUInt32(&scpi_context, &value, mandatory);                        \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value, expected_value);                                         \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamUInt32(void) {
@@ -465,7 +466,7 @@
 {                                                                                       \
     int64_t value;                                                                      \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -474,12 +475,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamInt64(&scpi_context, &value, mandatory);                         \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value, expected_value);                                         \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamInt64(void) {
@@ -506,7 +507,7 @@
 {                                                                                       \
     uint64_t value;                                                                     \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -515,12 +516,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamUInt64(&scpi_context, &value, mandatory);                        \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value, expected_value);                                         \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamUInt64(void) {
@@ -548,7 +549,7 @@
 {                                                                                       \
     float value;                                                                        \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -557,12 +558,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamFloat(&scpi_context, &value, mandatory);                         \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_DOUBLE_EQUAL(value, expected_value, 0.000001);                        \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamFloat(void) {
@@ -584,7 +585,7 @@
 {                                                                                       \
     double value;                                                                       \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -593,12 +594,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamDouble(&scpi_context, &value, mandatory);                        \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_DOUBLE_EQUAL(value, expected_value, 0.000001);                        \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamDouble(void) {
@@ -621,7 +622,7 @@
     const char * value;                                                                 \
     size_t value_len;                                                                   \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -630,12 +631,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamCharacters(&scpi_context, &value, &value_len, mandatory);        \
     /*printf("%.*s\r\n",  (int)value_len, value);*/                                     \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_NSTRING_EQUAL(value, expected_value, value_len);                      \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamCharacters(void) {
@@ -653,7 +654,7 @@
     char value[100];                                                                    \
     size_t value_len;                                                                   \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -662,13 +663,13 @@
     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);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     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);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testSCPI_ParamCopyText(void) {
@@ -689,21 +690,21 @@
     const char * value;                                                                 \
     size_t value_len;                                                                   \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_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_ParamArbitraryBlock(&scpi_context, &value, &value_len, mandatory);        \
+    result = SCPI_ParamArbitraryBlock(&scpi_context, &value, &value_len, mandatory);    \
     /*printf("%.*s\r\n",  (int)value_len, value);*/                                     \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_NSTRING_EQUAL(value, expected_value, value_len);                      \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 static void testSCPI_ParamArbitraryBlock(void) {
     TEST_ParamArbitraryBlock("#204ABCD", TRUE, "ABCD", TRUE, 0);
@@ -714,21 +715,21 @@
 {                                                                                       \
     scpi_bool_t value;                                                                  \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_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_ParamBool(&scpi_context, &value, mandatory);                         \
+    result = SCPI_ParamBool(&scpi_context, &value, mandatory);                          \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value, expected_value);                                         \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 static void testSCPI_ParamBool(void) {
     TEST_ParamBool("ON", TRUE, TRUE, TRUE, 0);
@@ -743,7 +744,7 @@
 {                                                                                       \
     int32_t value;                                                                      \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -752,12 +753,12 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamChoice(&scpi_context, test_options, &value, mandatory);          \
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value, expected_value);                                         \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 static void testSCPI_ParamChoice(void) {
     scpi_choice_def_t test_options[] = {
@@ -778,7 +779,7 @@
 {                                                                                       \
     scpi_bool_t result;                                                                 \
     scpi_expr_result_t result2;                                                         \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
     scpi_parameter_t param;                                                             \
     int32_t val_from, val_to;                                                           \
     scpi_bool_t val_range;                                                              \
@@ -790,7 +791,7 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_Parameter(&scpi_context, &param, TRUE);                               \
     result2 = SCPI_ExprNumericListEntryInt(&scpi_context, &param, index, &val_range, &val_from, &val_to);\
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result2, expected_result);                                          \
     if (expected_result == SCPI_EXPR_OK) {                                              \
         CU_ASSERT_EQUAL(val_range, expected_range);                                     \
@@ -799,14 +800,14 @@
             CU_ASSERT_EQUAL(val_to, expected_to);                                       \
         }                                                                               \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 #define TEST_NumericListDouble(data, index, expected_range, expected_from, expected_to, expected_result, expected_error_code) \
 {                                                                                       \
     scpi_bool_t result;                                                                 \
     scpi_expr_result_t result2;                                                         \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
     scpi_parameter_t param;                                                             \
     double val_from, val_to;                                                            \
     scpi_bool_t val_range;                                                              \
@@ -818,7 +819,7 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_Parameter(&scpi_context, &param, TRUE);                               \
     result2 = SCPI_ExprNumericListEntryDouble(&scpi_context, &param, index, &val_range, &val_from, &val_to);\
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result2, expected_result);                                          \
     if (expected_result == SCPI_EXPR_OK) {                                              \
         CU_ASSERT_EQUAL(val_range, expected_range);                                     \
@@ -827,7 +828,7 @@
             CU_ASSERT_DOUBLE_EQUAL(val_to, expected_to, 0.0001);                        \
         }                                                                               \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testNumericList(void) {
@@ -864,7 +865,7 @@
 {                                                                                       \
     scpi_bool_t result;                                                                 \
     scpi_expr_result_t result2;                                                         \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
     scpi_parameter_t param;                                                             \
     int32_t val_from[val_len], val_to[val_len];                                         \
     scpi_bool_t val_range;                                                              \
@@ -879,7 +880,7 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_Parameter(&scpi_context, &param, TRUE);                               \
     result2 = SCPI_ExprChannelListEntry(&scpi_context, &param, index, &val_range, val_from, val_to, val_len, &val_dimensions);\
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result2, expected_result);                                          \
     if (expected_result == SCPI_EXPR_OK) {                                              \
         CU_ASSERT_EQUAL(val_dimensions, expected_dimensions);                           \
@@ -893,7 +894,7 @@
             }}                                                                          \
         }                                                                               \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testChannelList(void) {
@@ -935,7 +936,7 @@
 {                                                                                       \
     scpi_number_t value;                                                                \
     scpi_bool_t result;                                                                 \
-    int16_t errCode;                                                                    \
+    scpi_error_t errCode;                                                               \
                                                                                         \
     SCPI_CoreCls(&scpi_context);                                                        \
     scpi_context.input_count = 0;                                                       \
@@ -944,7 +945,7 @@
     scpi_context.param_list.lex_state.pos = scpi_context.param_list.lex_state.buffer;   \
     result = SCPI_ParamNumber(&scpi_context, scpi_special_numbers_def, &value, mandatory);\
                                                                                         \
-    errCode = SCPI_ErrorPop(&scpi_context);                                             \
+    SCPI_ErrorPop(&scpi_context, &errCode);                                             \
     CU_ASSERT_EQUAL(result, expected_result);                                           \
     if (expected_result) {                                                              \
         CU_ASSERT_EQUAL(value.special, expected_special);                               \
@@ -953,7 +954,7 @@
         CU_ASSERT_EQUAL(value.unit, expected_unit);                                     \
         CU_ASSERT_EQUAL(value.base, expected_base);                                     \
     }                                                                                   \
-    CU_ASSERT_EQUAL(errCode, expected_error_code);                                      \
+    CU_ASSERT_EQUAL(errCode.error_code, expected_error_code);                           \
 }
 
 static void testParamNumber(void) {
@@ -1282,6 +1283,7 @@
 }
 
 static void testErrorQueue(void) {
+    scpi_error_t val;
     SCPI_ErrorClear(&scpi_context);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 0);
     SCPI_ErrorPush(&scpi_context, -1);
@@ -1297,15 +1299,20 @@
     SCPI_ErrorPush(&scpi_context, -6);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 4);
 
-    CU_ASSERT_EQUAL(SCPI_ErrorPop(&scpi_context), -1);
+    SCPI_ErrorPop(&scpi_context, &val);
+    CU_ASSERT_EQUAL(val.error_code, -1);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 3);
-    CU_ASSERT_EQUAL(SCPI_ErrorPop(&scpi_context), -2);
+    SCPI_ErrorPop(&scpi_context, &val);
+    CU_ASSERT_EQUAL(val.error_code, -2);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 2);
-    CU_ASSERT_EQUAL(SCPI_ErrorPop(&scpi_context), -3);
+    SCPI_ErrorPop(&scpi_context, &val);
+    CU_ASSERT_EQUAL(val.error_code, -3);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 1);
-    CU_ASSERT_EQUAL(SCPI_ErrorPop(&scpi_context), SCPI_ERROR_QUEUE_OVERFLOW);
+    SCPI_ErrorPop(&scpi_context, &val);
+    CU_ASSERT_EQUAL(val.error_code, SCPI_ERROR_QUEUE_OVERFLOW);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 0);
-    CU_ASSERT_EQUAL(SCPI_ErrorPop(&scpi_context), 0);
+    SCPI_ErrorPop(&scpi_context, &val);
+    CU_ASSERT_EQUAL(val.error_code, 0);
     CU_ASSERT_EQUAL(SCPI_ErrorCount(&scpi_context), 0);
 
     SCPI_ErrorClear(&scpi_context);

--
Gitblit v1.9.1