From b4565004c7f7585e69e29d5e11b5d28bb66125fa Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 2 Sep 2016 12:47:11 +0200 Subject: [PATCH] detect-template: modernize --- src/detect-template.c | 43 ++++++++++++++----------------------------- src/detect-template.h | 2 +- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/detect-template.c b/src/detect-template.c index b415783a60..b3ffb08e79 100644 --- a/src/detect-template.c +++ b/src/detect-template.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Open Information Security Foundation +/* Copyright (C) 2015-2016 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 @@ -229,40 +229,25 @@ static void DetectTemplateFree(void *ptr) { * \test description of the test */ -static int DetectTemplateParseTest01 (void) { - DetectTemplateData *templated = NULL; - uint8_t res = 0; - - templated = DetectTemplateParse("1,10"); - if (templated != NULL) { - if (templated->arg1 == 1 && templated->arg2 == 10) - res = 1; - - DetectTemplateFree(templated); - } - - return res; +static int DetectTemplateParseTest01 (void) +{ + DetectTemplateData *templated = DetectTemplateParse("1,10"); + FAIL_IF_NULL(templated); + FAIL_IF(!(templated->arg1 == 1 && templated->arg2 == 10)); + DetectTemplateFree(templated); + PASS; } -static int DetectTemplateSignatureTest01 (void) { - uint8_t res = 0; - +static int DetectTemplateSignatureTest01 (void) +{ DetectEngineCtx *de_ctx = DetectEngineCtxInit(); - if (de_ctx == NULL) - goto end; + FAIL_IF_NULL(de_ctx); Signature *sig = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any (template:1,10; sid:1; rev:1;)"); - if (sig == NULL) { - printf("parsing signature failed: "); - goto end; - } + FAIL_IF_NULL(sig); - /* if we get here, all conditions pass */ - res = 1; -end: - if (de_ctx != NULL) - DetectEngineCtxFree(de_ctx); - return res; + DetectEngineCtxFree(de_ctx); + PASS; } #endif /* UNITTESTS */ diff --git a/src/detect-template.h b/src/detect-template.h index d86c0083bb..6b2b4435ef 100644 --- a/src/detect-template.h +++ b/src/detect-template.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Open Information Security Foundation +/* Copyright (C) 2015-2016 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