From cb9a2ff1daf017a3aee23c70c5210608e19df681 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周三, 22 4月 2015 02:37:15 +0800
Subject: [PATCH] Add more compile checks and resolve warnings

---
 libscpi/test/test_scpi_utils.c |   68 ++++++++++++++++++++++++++--------
 1 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/libscpi/test/test_scpi_utils.c b/libscpi/test/test_scpi_utils.c
index 8fd42f5..4d1f634 100644
--- a/libscpi/test/test_scpi_utils.c
+++ b/libscpi/test/test_scpi_utils.c
@@ -39,21 +39,22 @@
 #include "CUnit/Basic.h"
 
 #include "scpi/scpi.h"
-#include "../src/utils.h"
+#include "scpi/utils_private.h"
+#include "scpi/utils.h"
 
 /*
  * CUnit Test Suite
  */
 
-int init_suite(void) {
+static int init_suite(void) {
     return 0;
 }
 
-int clean_suite(void) {
+static int clean_suite(void) {
     return 0;
 }
 
-void test_strnpbrk() {
+static void test_strnpbrk() {
     char str[] = "ahoj";
 
     CU_ASSERT(strnpbrk(str, 4, "a") == (str + 0));
@@ -63,24 +64,24 @@
     CU_ASSERT(strnpbrk(str, 4, "xo") == (str + 2));
 }
 
-void test_longToStr() {
+static void test_longToStr() {
     char str[32];
     size_t len;
 
-    len = longToStr(10, str, 32);
+    len = SCPI_LongToStr(10, str, 32, 10);
     CU_ASSERT(len == 2);
     CU_ASSERT(str[0] == '1');
     CU_ASSERT(str[1] == '0');
     CU_ASSERT(str[2] == '\0');
 }
 
-void test_doubleToStr() {
+static void test_doubleToStr() {
     size_t result;
     char str[50];
 
 #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)                                          \
@@ -96,7 +97,7 @@
     TEST_DOUBLE_TO_STR(-1.3e-30, 8, "-1.3e-30");
 }
 
-void test_strToLong() {
+static void test_strToLong() {
     size_t result;
     int32_t val;
 
@@ -121,7 +122,7 @@
     TEST_STR_TO_LONG("018", 2, 1); // octal 1, 8 is ignored
 }
 
-void test_strToDouble() {
+static void test_strToDouble() {
     double val;
     size_t result;
 
@@ -154,7 +155,7 @@
 
 }
 
-void test_compareStr() {
+static void test_compareStr() {
 
     CU_ASSERT_TRUE(compareStr("abcd", 1, "afgh", 1));
     CU_ASSERT_TRUE(compareStr("ABCD", 4, "abcd", 4));
@@ -165,7 +166,25 @@
     CU_ASSERT_FALSE(compareStr("ABCD", 4, "abcd", 3));
 }
 
-void test_locateText() {
+static 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));
+
+}
+
+static void test_locateText() {
 
     const char * v;
     const char * b;
@@ -215,7 +234,7 @@
     TEST_LOCATE_TEXT(" \"a\" , a ", TRUE, 2, 1);
 }
 
-void test_locateStr() {
+static void test_locateStr() {
 
     const char * v;
     const char * b;
@@ -263,7 +282,7 @@
     TEST_LOCATE_STR(" \"a\" , a ", TRUE, 1, 3);
 }
 
-void test_matchPattern() {
+static void test_matchPattern() {
     scpi_bool_t result;
     
 #define TEST_MATCH_PATTERN(p, s, r)                             \
@@ -279,7 +298,7 @@
     TEST_MATCH_PATTERN("AB", "a", FALSE);
 }
 
-void test_matchCommand() {
+static void test_matchCommand() {
     scpi_bool_t result;
     
     #define TEST_MATCH_COMMAND(p, s, r)                         \
@@ -387,9 +406,25 @@
     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) {
+static void test_composeCompoundCommand(void) {
     
 #define TEST_COMPOSE_COMMAND(b, c1_len, c2_pos, c2_len, c2_final, r)    \
     {                                                                   \
@@ -445,6 +480,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, "locateText", test_locateText))
             || (NULL == CU_add_test(pSuite, "locateStr", test_locateStr))
             || (NULL == CU_add_test(pSuite, "matchPattern", test_matchPattern))

--
Gitblit v1.9.1