From: Modupe Falodun Date: Thu, 4 Nov 2021 20:35:06 +0000 (+0100) Subject: detect-gid: convert unittests to FAIL/PASS APIs X-Git-Tag: suricata-7.0.0-beta1~1259 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a59299d128747c7cee0fcc25d1095cd948be4e66;p=thirdparty%2Fsuricata.git detect-gid: convert unittests to FAIL/PASS APIs Bug: #4041 --- diff --git a/src/detect-gid.c b/src/detect-gid.c index 313e7b7d38..6a37c1ad3e 100644 --- a/src/detect-gid.c +++ b/src/detect-gid.c @@ -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; } /**