]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-filename: convert unittests to FAIL/PASS APIs
authorAlice Akaki <akakialice@gmail.com>
Mon, 17 Oct 2022 21:44:15 +0000 (17:44 -0400)
committerVictor Julien <vjulien@oisf.net>
Mon, 24 Oct 2022 09:20:02 +0000 (11:20 +0200)
Task: #4036

src/detect-filename.c

index e953b03dbe8c8d52367f4f070ed46b6b850f427c..4ad6fab867e3b8dfe3cd57b3675c40fcbe78a653 100644 (file)
@@ -505,11 +505,9 @@ static int DetectFilenameSignatureParseTest01(void)
 static int DetectFilenameTestParse01 (void)
 {
     DetectFilenameData *dnd = DetectFilenameParse(NULL, "secret.pdf", false);
-    if (dnd != NULL) {
-        DetectFilenameFree(NULL, dnd);
-        return 1;
-    }
-    return 0;
+    FAIL_IF_NULL(dnd);
+    DetectFilenameFree(NULL, dnd);
+    PASS;
 }
 
 /**
@@ -517,18 +515,12 @@ static int DetectFilenameTestParse01 (void)
  */
 static int DetectFilenameTestParse02 (void)
 {
-    int result = 0;
-
     DetectFilenameData *dnd = DetectFilenameParse(NULL, "backup.tar.gz", false);
-    if (dnd != NULL) {
-        if (dnd->len == 13 && memcmp(dnd->name, "backup.tar.gz", 13) == 0) {
-            result = 1;
-        }
-
-        DetectFilenameFree(NULL, dnd);
-        return result;
-    }
-    return 0;
+    FAIL_IF_NULL(dnd);
+    FAIL_IF_NOT(dnd->len == 13);
+    FAIL_IF_NOT(memcmp(dnd->name, "backup.tar.gz", 13) == 0);
+    DetectFilenameFree(NULL, dnd);
+    PASS;
 }
 
 /**
@@ -536,21 +528,14 @@ static int DetectFilenameTestParse02 (void)
  */
 static int DetectFilenameTestParse03 (void)
 {
-    int result = 0;
-
     DetectFilenameData *dnd = DetectFilenameParse(NULL, "cmd.exe", false);
-    if (dnd != NULL) {
-        if (dnd->len == 7 && memcmp(dnd->name, "cmd.exe", 7) == 0) {
-            result = 1;
-        }
-
-        DetectFilenameFree(NULL, dnd);
-        return result;
-    }
-    return 0;
+    FAIL_IF_NULL(dnd);
+    FAIL_IF_NOT(dnd->len == 7);
+    FAIL_IF_NOT(memcmp(dnd->name, "cmd.exe", 7) == 0);
+    DetectFilenameFree(NULL, dnd);
+    PASS;
 }
 
-
 /**
  * \brief this function registers unit tests for DetectFilename
  */