From dd88e46f0cd8c2c16393148289d698a4f4323f9b Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 13 Jun 2010 10:23:59 +0200 Subject: [PATCH] Fix detect engine state unittest, add another. --- src/detect-engine-state.c | 50 ++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/detect-engine-state.c b/src/detect-engine-state.c index fbb58bfcc6..82961f0740 100644 --- a/src/detect-engine-state.c +++ b/src/detect-engine-state.c @@ -609,23 +609,56 @@ static int DeStateTest02(void) { goto end; } - if (state->head->next->next == NULL) { + if (state->head->store[15].sid != 155) { goto end; } - if (state->head->next->next->next == NULL) { + if (state->head->next->store[0].sid != 166) { goto end; } - if (state->head->next->next->next->next == NULL) { + result = 1; +end: + if (state != NULL) { + DetectEngineStateFree(state); + } + return result; +} + +static int DeStateTest03(void) { + int result = 0; + + DetectEngineState *state = DetectEngineStateAlloc(); + if (state == NULL) { + printf("d == NULL: "); + goto end; + } + + Signature s; + memset(&s, 0x00, sizeof(s)); + + s.num = 11; + DeStateSignatureAppend(state, &s, NULL, 0); + s.num = 22; + DeStateSignatureAppend(state, &s, NULL, 1); + + if (state->head == NULL) { + goto end; + } + + if (state->head->store[0].sid != 11) { goto end; } - if (state->head->next->next->next->store[3].sid != 155) { + if (state->head->store[0].flags & DE_STATE_FLAG_URI_MATCH) { goto end; } - if (state->head->next->next->next->next->store[0].sid != 166) { + if (state->head->store[1].sid != 22) { + goto end; + } + + if (!(state->head->store[1].flags & DE_STATE_FLAG_URI_MATCH)) { goto end; } @@ -637,7 +670,7 @@ end: return result; } -static int DeStateTest03(void) { +static int DeStateSigTest01(void) { int result = 0; Signature *s = NULL; DetectEngineThreadCtx *det_ctx = NULL; @@ -766,7 +799,7 @@ end: } /** \test multiple pipelined http transactions */ -static int DeStateTest04(void) { +static int DeStateSigTest02(void) { int result = 0; Signature *s = NULL; DetectEngineThreadCtx *det_ctx = NULL; @@ -951,7 +984,8 @@ void DeStateRegisterTests(void) { UtRegisterTest("DeStateTest01", DeStateTest01, 1); UtRegisterTest("DeStateTest02", DeStateTest02, 1); UtRegisterTest("DeStateTest03", DeStateTest03, 1); - UtRegisterTest("DeStateTest04", DeStateTest04, 1); + UtRegisterTest("DeStateSigTest01", DeStateSigTest01, 1); + UtRegisterTest("DeStateSigTest02", DeStateSigTest02, 1); #endif }