From 66d496c25560a175a39eab1ea379348568541563 Mon Sep 17 00:00:00 2001 From: Martin Beyer Date: Mon, 24 Jan 2011 12:19:08 +0100 Subject: [PATCH] Added case sensitive unit test to util-mpm-ac --- src/util-mpm-ac.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 8ac77d0adb..1b88845fbb 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -2176,6 +2176,66 @@ static int SCACTest26(void) return result; } +static int SCACTest27(void) +{ + int result = 0; + MpmCtx mpm_ctx; + MpmThreadCtx mpm_thread_ctx; + + memset(&mpm_ctx, 0, sizeof(MpmCtx)); + memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); + MpmInitCtx(&mpm_ctx, MPM_AC, -1); + SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx, 0); + + /* 0 match */ + SCACAddPatternCS(&mpm_ctx, (uint8_t *)"ONE", 3, 0, 0, 0, 0, 0); + + SCACPreparePatterns(&mpm_ctx); + + char *buf = "tone"; + uint32_t cnt = SCACSearch(&mpm_ctx, &mpm_thread_ctx, NULL, + (uint8_t *)buf, strlen(buf)); + + if (cnt == 0) + result = 1; + else + printf("0 != %" PRIu32 " ",cnt); + + SCACDestroyCtx(&mpm_ctx); + SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx); + return result; +} + +static int SCACTest28(void) +{ + int result = 0; + MpmCtx mpm_ctx; + MpmThreadCtx mpm_thread_ctx; + + memset(&mpm_ctx, 0, sizeof(MpmCtx)); + memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); + MpmInitCtx(&mpm_ctx, MPM_AC, -1); + SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx, 0); + + /* 0 match */ + SCACAddPatternCS(&mpm_ctx, (uint8_t *)"one", 3, 0, 0, 0, 0, 0); + + SCACPreparePatterns(&mpm_ctx); + + char *buf = "tONE"; + uint32_t cnt = SCACSearch(&mpm_ctx, &mpm_thread_ctx, NULL, + (uint8_t *)buf, strlen(buf)); + + if (cnt == 0) + result = 1; + else + printf("0 != %" PRIu32 " ",cnt); + + SCACDestroyCtx(&mpm_ctx); + SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx); + return result; +} + #endif /* UNITTESTS */ void SCACRegisterTests(void) @@ -2208,6 +2268,8 @@ void SCACRegisterTests(void) UtRegisterTest("SCACTest24", SCACTest24, 1); UtRegisterTest("SCACTest25", SCACTest25, 1); UtRegisterTest("SCACTest26", SCACTest26, 1); + UtRegisterTest("SCACTest27", SCACTest27, 1); + UtRegisterTest("SCACTest28", SCACTest28, 1); #endif return;