From 8614bff0178659bcd2c94e49d3aba50a30fe7844 Mon Sep 17 00:00:00 2001 From: Alice Akaki Date: Tue, 18 Oct 2022 12:11:57 -0400 Subject: [PATCH] detect-filemagic: convert unittests to FAIL/PASS APIs Task: #4034 --- src/detect-filemagic.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/detect-filemagic.c b/src/detect-filemagic.c index cccd44ebb2..b30414a1aa 100644 --- a/src/detect-filemagic.c +++ b/src/detect-filemagic.c @@ -590,11 +590,9 @@ static int PrefilterMpmFilemagicRegister(DetectEngineCtx *de_ctx, static int DetectFilemagicTestParse01 (void) { DetectFilemagicData *dnd = DetectFilemagicParse(NULL, "secret.pdf", false); - if (dnd != NULL) { - DetectFilemagicFree(NULL, dnd); - return 1; - } - return 0; + FAIL_IF_NULL(dnd); + DetectFilemagicFree(NULL, dnd); + PASS; } /** @@ -602,18 +600,12 @@ static int DetectFilemagicTestParse01 (void) */ static int DetectFilemagicTestParse02 (void) { - int result = 0; - DetectFilemagicData *dnd = DetectFilemagicParse(NULL, "backup.tar.gz", false); - if (dnd != NULL) { - if (dnd->len == 13 && memcmp(dnd->name, "backup.tar.gz", 13) == 0) { - result = 1; - } - - DetectFilemagicFree(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); + DetectFilemagicFree(NULL, dnd); + PASS; } /** @@ -621,18 +613,12 @@ static int DetectFilemagicTestParse02 (void) */ static int DetectFilemagicTestParse03 (void) { - int result = 0; - DetectFilemagicData *dnd = DetectFilemagicParse(NULL, "cmd.exe", false); - if (dnd != NULL) { - if (dnd->len == 7 && memcmp(dnd->name, "cmd.exe", 7) == 0) { - result = 1; - } - - DetectFilemagicFree(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); + DetectFilemagicFree(NULL, dnd); + PASS; } /** -- 2.47.2