suricata
detect-template.c
Go to the documentation of this file.
1 /* Copyright (C) 2015-2018 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "../suricata-common.h"
19 #include "../util-unittest.h"
20 
21 #include "../detect-parse.h"
22 #include "../detect-engine.h"
23 
24 #include "../detect-template.h"
25 
26 /**
27  * \test test keyword parsing
28  */
29 
30 static int DetectTemplateParseTest01 (void)
31 {
32  DetectU8Data *templated = DetectU8Parse("10");
33  FAIL_IF_NULL(templated);
34  FAIL_IF(!(templated->arg1 == 10 && templated->mode == DetectUintModeEqual));
35  DetectTemplateFree(NULL, templated);
36  PASS;
37 }
38 
39 /**
40  * \test test signature parsing
41  */
42 
43 static int DetectTemplateSignatureTest01 (void)
44 {
47 
49  de_ctx, "alert ip any any -> any any (template:<10; sid:1; rev:1;)");
50  FAIL_IF_NULL(sig);
51 
53  PASS;
54 }
55 
56 /**
57  * \brief this function registers unit tests for DetectTemplate
58  */
60 {
61  UtRegisterTest("DetectTemplateParseTest01", DetectTemplateParseTest01);
62  UtRegisterTest("DetectTemplateSignatureTest01",
63  DetectTemplateSignatureTest01);
64 }
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:937
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2652
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3478
DetectU8Parse
DetectUintData_u8 * DetectU8Parse(const char *u8str)
This function is used to parse u8 options passed via some u8 keyword.
Definition: detect-engine-uint.c:85
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:19
DetectU8Data
DetectUintData_u8 DetectU8Data
Definition: detect-engine-uint.h:43
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
Signature_
Signature container.
Definition: detect.h:672
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2613
DetectTemplateRegisterTests
void DetectTemplateRegisterTests(void)
this function registers unit tests for DetectTemplate
Definition: detect-template.c:59