From 3f4398cc90f3b8d57b9426fe823b332e5163d799 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 18 Jan 2021 15:50:57 +0100 Subject: [PATCH] decode: minor unittest cleanups --- src/decode-chdlc.c | 3 +-- src/decode-gre.c | 36 ++++++++++-------------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/decode-chdlc.c b/src/decode-chdlc.c index 6ecb6b44ba..a7ed61869d 100644 --- a/src/decode-chdlc.c +++ b/src/decode-chdlc.c @@ -75,8 +75,7 @@ static int DecodeCHDLCTest01 (void) 0x02,0x04,0x05,0xb4,0x01,0x01,0x04,0x02 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-gre.c b/src/decode-gre.c index 058c529b85..a55352a733 100644 --- a/src/decode-gre.c +++ b/src/decode-gre.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2020 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 @@ -286,8 +286,7 @@ static int DecodeGREtest01 (void) { uint8_t raw_gre[] = { 0x00 ,0x6e ,0x62 }; Packet *p = PacketGetFromAlloc(); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); ThreadVars tv; DecodeThreadVars dtv; @@ -295,14 +294,10 @@ static int DecodeGREtest01 (void) memset(&dtv, 0, sizeof(DecodeThreadVars)); DecodeGRE(&tv, &dtv, p, raw_gre, sizeof(raw_gre)); - - if(ENGINE_ISSET_EVENT(p,GRE_PKT_TOO_SMALL)) { - SCFree(p); - return 1; - } + FAIL_IF_NOT(ENGINE_ISSET_EVENT(p, GRE_PKT_TOO_SMALL)); SCFree(p); - return 0; + PASS; } /** @@ -327,8 +322,7 @@ static int DecodeGREtest02 (void) 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = PacketGetFromAlloc(); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); ThreadVars tv; DecodeThreadVars dtv; @@ -336,14 +330,10 @@ static int DecodeGREtest02 (void) memset(&dtv, 0, sizeof(DecodeThreadVars)); DecodeGRE(&tv, &dtv, p, raw_gre, sizeof(raw_gre)); - - if(ENGINE_ISSET_EVENT(p,GRE_WRONG_VERSION)) { - SCFree(p); - return 1; - } + FAIL_IF_NOT(ENGINE_ISSET_EVENT(p, GRE_WRONG_VERSION)); SCFree(p); - return 0; + PASS; } @@ -369,8 +359,7 @@ static int DecodeGREtest03 (void) 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = PacketGetFromAlloc(); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); ThreadVars tv; DecodeThreadVars dtv; @@ -378,15 +367,10 @@ static int DecodeGREtest03 (void) memset(&dtv, 0, sizeof(DecodeThreadVars)); DecodeGRE(&tv, &dtv, p, raw_gre, sizeof(raw_gre)); - - if(p->greh == NULL) { - SCFree(p); - return 0; - } - + FAIL_IF_NULL(p->greh); SCFree(p); - return 1; + PASS; } #endif /* UNITTESTS */ -- 2.47.2