]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-itype: Convert unittests to new FAIL/PASS API
authorHaleema Khan <hsadia538@gmail.com>
Fri, 21 Oct 2022 02:16:45 +0000 (07:16 +0500)
committerVictor Julien <vjulien@oisf.net>
Fri, 28 Oct 2022 10:22:07 +0000 (12:22 +0200)
Bug: #5589

src/detect-itype.c

index 799692b8b2205719ed9b9def39e94b2b13d74af5..d8168600f5d2ab180ed3b4466b92c8a5310b4c19 100644 (file)
@@ -221,14 +221,13 @@ static bool PrefilterITypeIsPrefilterable(const Signature *s)
 static int DetectITypeParseTest01(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, "8");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->mode == DETECT_UINT_EQ)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_EQ);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -238,14 +237,13 @@ static int DetectITypeParseTest01(void)
 static int DetectITypeParseTest02(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, ">8");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->mode == DETECT_UINT_GT)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_GT);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -255,14 +253,13 @@ static int DetectITypeParseTest02(void)
 static int DetectITypeParseTest03(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, "<8");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->mode == DETECT_UINT_LT)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_LT);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -272,14 +269,14 @@ static int DetectITypeParseTest03(void)
 static int DetectITypeParseTest04(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, "8<>20");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->arg2 == 20 && itd->mode == DETECT_UINT_RA)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->arg2 == 20);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_RA);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -289,14 +286,13 @@ static int DetectITypeParseTest04(void)
 static int DetectITypeParseTest05(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, "   8 ");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->mode == DETECT_UINT_EQ)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_EQ);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -306,14 +302,13 @@ static int DetectITypeParseTest05(void)
 static int DetectITypeParseTest06(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, "  >  8  ");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->mode == DETECT_UINT_GT)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_GT);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -323,14 +318,14 @@ static int DetectITypeParseTest06(void)
 static int DetectITypeParseTest07(void)
 {
     DetectU8Data *itd = NULL;
-    int result = 0;
     itd = DetectITypeParse(NULL, "  8  <> 20  ");
-    if (itd != NULL) {
-        if (itd->arg1 == 8 && itd->arg2 == 20 && itd->mode == DETECT_UINT_RA)
-            result = 1;
-        DetectITypeFree(NULL, itd);
-    }
-    return result;
+    FAIL_IF_NULL(itd);
+    FAIL_IF_NOT(itd->arg1 == 8);
+    FAIL_IF_NOT(itd->arg2 == 20);
+    FAIL_IF_NOT(itd->mode == DETECT_UINT_RA);
+    DetectITypeFree(NULL, itd);
+
+    PASS;
 }
 
 /**
@@ -340,10 +335,10 @@ static int DetectITypeParseTest08(void)
 {
     DetectU8Data *itd = NULL;
     itd = DetectITypeParse(NULL, "> 8 <> 20");
-    if (itd == NULL)
-        return 1;
+    FAIL_IF_NOT_NULL(itd);
     DetectITypeFree(NULL, itd);
-    return 0;
+
+    PASS;
 }
 
 /**