]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unittests: add signature parse test helper
authorVictor Julien <victor@inliniac.net>
Wed, 28 Nov 2018 08:33:56 +0000 (09:33 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 29 Jan 2019 12:27:56 +0000 (13:27 +0100)
src/util-unittest-helper.c
src/util-unittest-helper.h

index 47c67c0b6777d6d1f7e757350d38c32dc9d8ba0d..a2baf67ee2ffeab1a259e9725f163a4806dfbcf2 100644 (file)
@@ -925,6 +925,24 @@ uint32_t UTHBuildPacketOfFlows(uint32_t start, uint32_t end, uint8_t dir)
     return i;
 }
 
+/** \brief parser a sig and see if the expected result is correct */
+int UTHParseSignature(const char *str, bool expect)
+{
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    FAIL_IF_NULL(de_ctx);
+    de_ctx->flags |= DE_QUIET;
+
+    Signature *s = DetectEngineAppendSig(de_ctx, str);
+    if (expect)
+        FAIL_IF_NULL(s);
+    else
+        FAIL_IF_NOT_NULL(s);
+
+    DetectEngineCtxFree(de_ctx);
+    PASS;
+}
+
+
 /*
  * unittests for the unittest helpers
  */
index 7d463359a7ac1e476ccfd94583e4bdfaf3796544..8ce2a4653aa83ee4c3af09e18318c128ec9e29f5 100644 (file)
@@ -60,6 +60,8 @@ int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int);
 uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t);
 Packet *UTHBuildPacketIPV6Real(uint8_t *, uint16_t , uint8_t ipproto, const char *, const char *,
                            uint16_t , uint16_t );
+
+int UTHParseSignature(const char *str, bool expect);
 #endif
 
 void UTHRegisterTests(void);