detect-tcp-window: Convert unittests to new FAIL/PASS API

Task #6339
pull/9701/head
Hadiqa Alamdar Bukhari 3 years ago committed by Victor Julien
parent 4ff52f26d7
commit 68d3c0c388

@ -226,15 +226,13 @@ void DetectWindowFree(DetectEngineCtx *de_ctx, void *ptr)
*/ */
static int DetectWindowTestParse01 (void) static int DetectWindowTestParse01 (void)
{ {
int result = 0;
DetectWindowData *wd = NULL; DetectWindowData *wd = NULL;
wd = DetectWindowParse(NULL, "35402"); wd = DetectWindowParse(NULL, "35402");
if (wd != NULL &&wd->size==35402) { FAIL_IF_NULL(wd);
DetectWindowFree(NULL, wd); FAIL_IF_NOT(wd->size == 35402);
result = 1;
}
return result; DetectWindowFree(NULL, wd);
PASS;
} }
/** /**
@ -242,19 +240,14 @@ static int DetectWindowTestParse01 (void)
*/ */
static int DetectWindowTestParse02 (void) static int DetectWindowTestParse02 (void)
{ {
int result = 0;
DetectWindowData *wd = NULL; DetectWindowData *wd = NULL;
wd = DetectWindowParse(NULL, "!35402"); wd = DetectWindowParse(NULL, "!35402");
if (wd != NULL) { FAIL_IF_NULL(wd);
if (wd->negated == 1 && wd->size==35402) { FAIL_IF_NOT(wd->negated == 1);
result = 1; FAIL_IF_NOT(wd->size == 35402);
} else {
printf("expected wd->negated=1 and wd->size=35402\n");
}
DetectWindowFree(NULL, wd);
}
return result; DetectWindowFree(NULL, wd);
PASS;
} }
/** /**
@ -262,17 +255,12 @@ static int DetectWindowTestParse02 (void)
*/ */
static int DetectWindowTestParse03 (void) static int DetectWindowTestParse03 (void)
{ {
int result = 0;
DetectWindowData *wd = NULL; DetectWindowData *wd = NULL;
wd = DetectWindowParse(NULL, ""); wd = DetectWindowParse(NULL, "");
if (wd == NULL) { FAIL_IF_NOT_NULL(wd);
result = 1;
} else {
printf("expected a NULL pointer (It was an empty string)\n");
}
DetectWindowFree(NULL, wd);
return result; DetectWindowFree(NULL, wd);
PASS;
} }
/** /**
@ -280,16 +268,12 @@ static int DetectWindowTestParse03 (void)
*/ */
static int DetectWindowTestParse04 (void) static int DetectWindowTestParse04 (void)
{ {
int result = 0;
DetectWindowData *wd = NULL; DetectWindowData *wd = NULL;
wd = DetectWindowParse(NULL, "1235402"); wd = DetectWindowParse(NULL, "1235402");
if (wd != NULL) { FAIL_IF_NOT_NULL(wd);
printf("expected a NULL pointer (It was exceeding the MAX window size)\n");
DetectWindowFree(NULL, wd);
}else
result=1;
return result; DetectWindowFree(NULL, wd);
PASS;
} }
/** /**
@ -297,7 +281,6 @@ static int DetectWindowTestParse04 (void)
*/ */
static int DetectWindowTestPacket01 (void) static int DetectWindowTestPacket01 (void)
{ {
int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!"; uint8_t *buf = (uint8_t *)"Hi all!";
uint16_t buflen = strlen((char *)buf); uint16_t buflen = strlen((char *)buf);
Packet *p[3]; Packet *p[3];
@ -305,8 +288,7 @@ static int DetectWindowTestPacket01 (void)
p[1] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP); p[1] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
p[2] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_ICMP); p[2] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_ICMP);
if (p[0] == NULL || p[1] == NULL ||p[2] == NULL) FAIL_IF(p[0] == NULL || p[1] == NULL || p[2] == NULL);
goto end;
/* TCP wwindow = 40 */ /* TCP wwindow = 40 */
p[0]->tcph->th_win = htons(40); p[0]->tcph->th_win = htons(40);
@ -327,11 +309,10 @@ static int DetectWindowTestPacket01 (void)
{0, 1}, {0, 1},
/* packet 2 should not match */ /* packet 2 should not match */
{0, 0} }; {0, 0} };
result = UTHGenericTest(p, 3, sigs, sid, (uint32_t *) results, 2); FAIL_IF(UTHGenericTest(p, 3, sigs, sid, (uint32_t *)results, 2) == 0);
UTHFreePackets(p, 3); UTHFreePackets(p, 3);
end: PASS;
return result;
} }
/** /**

Loading…
Cancel
Save