]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-gid: convert unittests to FAIL/PASS APIs
authorModupe Falodun <falodunmodupeola@gmail.com>
Thu, 4 Nov 2021 20:35:06 +0000 (21:35 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 6 Nov 2021 15:25:45 +0000 (16:25 +0100)
Bug: #4041

src/detect-gid.c

index 313e7b7d38f70d14a2be99e930f9fca8cac96d65..6a37c1ad3e5d72728ea446e8a46189a235c6ce40 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -99,77 +99,50 @@ static int DetectGidSetup (DetectEngineCtx *de_ctx, Signature *s, const char *ra
 #ifdef UNITTESTS
 /**
  * \test GidTestParse01 is a test for a  valid gid value
- *
- *  \retval 1 on succces
- *  \retval 0 on failure
  */
 static int GidTestParse01 (void)
 {
-    int result = 0;
-    Signature *s = NULL;
-
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
-    if (de_ctx == NULL)
-        goto end;
-
-    s = DetectEngineAppendSig(de_ctx, "alert tcp 1.2.3.4 any -> any any (sid:1; gid:1;)");
-    if (s == NULL || s->gid != 1)
-        goto end;
-
-    result = 1;
-end:
-    if (de_ctx != NULL)
-        DetectEngineCtxFree(de_ctx);
-    return result;
+    FAIL_IF_NULL(de_ctx);
+
+    Signature *s =
+            DetectEngineAppendSig(de_ctx, "alert tcp 1.2.3.4 any -> any any (sid:1; gid:1;)");
+
+    FAIL_IF_NULL(s);
+    FAIL_IF(s->gid != 1);
+
+    DetectEngineCtxFree(de_ctx);
+    PASS;
 }
 
 /**
  * \test GidTestParse02 is a test for an invalid gid value
- *
- *  \retval 1 on succces
- *  \retval 0 on failure
  */
 static int GidTestParse02 (void)
 {
-    int result = 0;
-
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
-    if (de_ctx == NULL)
-        goto end;
+    FAIL_IF_NULL(de_ctx);
 
-    if (DetectEngineAppendSig(de_ctx, "alert tcp 1.2.3.4 any -> any any (sid:1; gid:a;)") != NULL)
-        goto end;
+    FAIL_IF_NOT_NULL(
+            DetectEngineAppendSig(de_ctx, "alert tcp 1.2.3.4 any -> any any (sid:1; gid:a;)"));
 
-    result = 1;
-end:
-    if (de_ctx != NULL)
-        DetectEngineCtxFree(de_ctx);
-    return result;
+    DetectEngineCtxFree(de_ctx);
+    PASS;
 }
 
 /**
  * \test Test a gid consisting of a single quote.
- *
- * \retval 1 on succces
- * \retval 0 on failure
  */
 static int GidTestParse03 (void)
 {
-    int result = 0;
-
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
-    if (de_ctx == NULL)
-        goto end;
-
-    if (DetectEngineAppendSig(de_ctx,
-            "alert tcp any any -> any any (content:\"ABC\"; gid:\";)") != NULL)
-        goto end;
-
-    result = 1;
-end:
-    if (de_ctx != NULL)
-        DetectEngineCtxFree(de_ctx);
-    return result;
+    FAIL_IF_NULL(de_ctx);
+
+    FAIL_IF_NOT_NULL(DetectEngineAppendSig(
+            de_ctx, "alert tcp any any -> any any (content:\"ABC\"; gid:\";)"));
+
+    DetectEngineCtxFree(de_ctx);
+    PASS;
 }
 
 /**