From 52983bf314dc7f84c6295141fa5ed6c5f0b9a88f Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 6 Apr 2016 15:35:13 -0600 Subject: [PATCH] tests: convert all test to return 0 on failure, 1 on success --- src/app-layer-smtp.c | 25 ++++---- src/counters.c | 12 ++-- src/decode-ethernet.c | 4 +- src/decode-icmpv4.c | 4 +- src/decode-icmpv6.c | 4 +- src/decode-ipv4.c | 4 +- src/decode-raw.c | 25 ++++---- src/decode-tcp.c | 8 +-- src/decode-udp.c | 8 +-- src/detect-detection-filter.c | 18 +++--- src/detect-engine-event.c | 12 ++-- src/detect-engine-filedata-smtp.c | 4 +- src/detect-file-data.c | 18 +++--- src/detect-flags.c | 41 +++++++------ src/detect-flowbits.c | 24 ++++---- src/detect-fragbits.c | 13 ++-- src/detect-fragoffset.c | 6 +- src/detect-icmp-seq.c | 6 +- src/detect-ipopts.c | 13 ++-- src/detect-iprep.c | 16 ++--- src/detect-mark.c | 12 ++-- src/detect-replace.c | 20 +++---- src/detect-threshold.c | 12 ++-- src/util-decode-mime.c | 98 +++++++++++++++---------------- src/util-threshold-config.c | 4 +- src/util-unittest.c | 6 +- 26 files changed, 210 insertions(+), 207 deletions(-) diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index 94693a2339..534d92e8d4 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -4868,7 +4868,7 @@ int SMTPProcessDataChunkTest01(void){ int ret; ret = SMTPProcessDataChunk(NULL, 0, state); - return ret; + return ret == 0; } @@ -4925,8 +4925,7 @@ int SMTPProcessDataChunkTest02(void){ int ret; ret = SMTPProcessDataChunk((uint8_t *)mimemsg, sizeof(mimemsg), state); - - return ret; + return ret == 0; } @@ -4981,7 +4980,7 @@ int SMTPProcessDataChunkTest03(void){ if(ret) goto end; end: - return ret; + return ret == 0; } @@ -5022,7 +5021,7 @@ int SMTPProcessDataChunkTest04(void){ if(SMTPProcessDataChunk((uint8_t *)mimemsg11, sizeof(mimemsg11), state) != 0) goto end; end: - return ret; + return ret == 0; } int SMTPProcessDataChunkTest05(void){ @@ -5057,13 +5056,13 @@ int SMTPProcessDataChunkTest05(void){ if(ret){goto end;} printf("%u\t%u\n", (uint32_t) file->size, (uint32_t) file_size); if(file->size == file_size){ - return 0; - }else{ return 1; + }else{ + return 0; } end: - return ret; + return ret == 0; } #endif /* UNITTESTS */ @@ -5085,11 +5084,11 @@ void SMTPParserRegisterTests(void) UtRegisterTest("SMTPParserTest12", SMTPParserTest12, 1); UtRegisterTest("SMTPParserTest13", SMTPParserTest13, 1); UtRegisterTest("SMTPParserTest14", SMTPParserTest14, 1); - UtRegisterTest("SMTPProcessDataChunkTest01", SMTPProcessDataChunkTest01, 0); - UtRegisterTest("SMTPProcessDataChunkTest02", SMTPProcessDataChunkTest02, 0); - UtRegisterTest("SMTPProcessDataChunkTest03", SMTPProcessDataChunkTest03, 0); - UtRegisterTest("SMTPProcessDataChunkTest04", SMTPProcessDataChunkTest04, 0); - UtRegisterTest("SMTPProcessDataChunkTest05", SMTPProcessDataChunkTest05, 0); + UtRegisterTest("SMTPProcessDataChunkTest01", SMTPProcessDataChunkTest01, 1); + UtRegisterTest("SMTPProcessDataChunkTest02", SMTPProcessDataChunkTest02, 1); + UtRegisterTest("SMTPProcessDataChunkTest03", SMTPProcessDataChunkTest03, 1); + UtRegisterTest("SMTPProcessDataChunkTest04", SMTPProcessDataChunkTest04, 1); + UtRegisterTest("SMTPProcessDataChunkTest05", SMTPProcessDataChunkTest05, 1); #endif /* UNITTESTS */ return; diff --git a/src/counters.c b/src/counters.c index 325442f2d6..1086e10c36 100644 --- a/src/counters.c +++ b/src/counters.c @@ -1286,7 +1286,7 @@ static int StatsTestCounterReg02() memset(&pctx, 0, sizeof(StatsPublicThreadContext)); - return RegisterCounter(NULL, NULL, &pctx); + return RegisterCounter(NULL, NULL, &pctx) == 0; } static int StatsTestCounterReg03() @@ -1384,7 +1384,7 @@ static int StatsTestCntArraySize07() StatsReleaseCounters(tv.perf_public_ctx.head); StatsReleasePrivateThreadContext(pca); - return result; + return result == 2; } static int StatsTestUpdateCounter08() @@ -1409,7 +1409,7 @@ static int StatsTestUpdateCounter08() StatsReleaseCounters(tv.perf_public_ctx.head); StatsReleasePrivateThreadContext(pca); - return result; + return result == 101; } static int StatsTestUpdateCounter09() @@ -1519,13 +1519,13 @@ static int StatsTestCounterValues11() void StatsRegisterTests() { #ifdef UNITTESTS - UtRegisterTest("StatsTestCounterReg02", StatsTestCounterReg02, 0); + UtRegisterTest("StatsTestCounterReg02", StatsTestCounterReg02, 1); UtRegisterTest("StatsTestCounterReg03", StatsTestCounterReg03, 1); UtRegisterTest("StatsTestCounterReg04", StatsTestCounterReg04, 1); UtRegisterTest("StatsTestGetCntArray05", StatsTestGetCntArray05, 1); UtRegisterTest("StatsTestGetCntArray06", StatsTestGetCntArray06, 1); - UtRegisterTest("StatsTestCntArraySize07", StatsTestCntArraySize07, 2); - UtRegisterTest("StatsTestUpdateCounter08", StatsTestUpdateCounter08, 101); + UtRegisterTest("StatsTestCntArraySize07", StatsTestCntArraySize07, 1); + UtRegisterTest("StatsTestUpdateCounter08", StatsTestUpdateCounter08, 1); UtRegisterTest("StatsTestUpdateCounter09", StatsTestUpdateCounter09, 1); UtRegisterTest("StatsTestUpdateGlobalCounter10", StatsTestUpdateGlobalCounter10, 1); diff --git a/src/decode-ethernet.c b/src/decode-ethernet.c index ee4157236c..0bc85cf5a7 100644 --- a/src/decode-ethernet.c +++ b/src/decode-ethernet.c @@ -132,7 +132,7 @@ static int DecodeEthernetTest01 (void) DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL); SCFree(p); - return 0; + return 1; } #endif /* UNITTESTS */ @@ -144,7 +144,7 @@ static int DecodeEthernetTest01 (void) void DecodeEthernetRegisterTests(void) { #ifdef UNITTESTS - UtRegisterTest("DecodeEthernetTest01", DecodeEthernetTest01, 0); + UtRegisterTest("DecodeEthernetTest01", DecodeEthernetTest01, 1); #endif /* UNITTESTS */ } /** diff --git a/src/decode-icmpv4.c b/src/decode-icmpv4.c index 45b213f670..e67b68455e 100644 --- a/src/decode-icmpv4.c +++ b/src/decode-icmpv4.c @@ -665,7 +665,7 @@ static int ICMPV4CalculateInvalidChecksumtest06(void) 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38}; csum = *( ((uint16_t *)raw_icmpv4) + 1); - return (csum == ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4, sizeof(raw_icmpv4))); + return (csum != ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4, sizeof(raw_icmpv4))); } static int ICMPV4InvalidType07(void) @@ -777,7 +777,7 @@ void DecodeICMPV4RegisterTests(void) UtRegisterTest("ICMPV4CalculateValidChecksumtest05", ICMPV4CalculateValidChecksumtest05, 1); UtRegisterTest("ICMPV4CalculateInvalidChecksumtest06", - ICMPV4CalculateInvalidChecksumtest06, 0); + ICMPV4CalculateInvalidChecksumtest06, 1); UtRegisterTest("DecodeICMPV4InvalidType", ICMPV4InvalidType07, 1); UtRegisterTest("DecodeICMPV4test08", DecodeICMPV4test08, 1); #endif /* UNITTESTS */ diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c index a7a77b5a19..d2e19aa366 100644 --- a/src/decode-icmpv6.c +++ b/src/decode-icmpv6.c @@ -422,7 +422,7 @@ static int ICMPV6CalculateInvalidChecksumtest02(void) csum = *( ((uint16_t *)(raw_ipv6 + 56))); - return (csum == ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8), + return (csum != ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8), (uint16_t *)(raw_ipv6 + 54), 68)); } @@ -1613,7 +1613,7 @@ void DecodeICMPV6RegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("ICMPV6CalculateValidChecksumtest01", ICMPV6CalculateValidChecksumtest01, 1); - UtRegisterTest("ICMPV6CalculateInValidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02, 0); + UtRegisterTest("ICMPV6CalculateInValidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02, 1); UtRegisterTest("ICMPV6ParamProbTest01 (Valid)", ICMPV6ParamProbTest01, 1); UtRegisterTest("ICMPV6DestUnreachTest01 (Valid)", ICMPV6DestUnreachTest01, 1); diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c index 63aae4ede4..7979e975bb 100644 --- a/src/decode-ipv4.c +++ b/src/decode-ipv4.c @@ -1449,7 +1449,7 @@ static int IPV4CalculateInvalidChecksumtest02(void) csum = *( ((uint16_t *)raw_ipv4) + 5); - return (csum == IPV4CalculateChecksum((uint16_t *)raw_ipv4, sizeof(raw_ipv4))); + return (csum != IPV4CalculateChecksum((uint16_t *)raw_ipv4, sizeof(raw_ipv4))); } /** @@ -1902,7 +1902,7 @@ void DecodeIPV4RegisterTests(void) UtRegisterTest("IPV4CalculateValidChecksumtest01", IPV4CalculateValidChecksumtest01, 1); UtRegisterTest("IPV4CalculateInvalidChecksumtest02", - IPV4CalculateInvalidChecksumtest02, 0); + IPV4CalculateInvalidChecksumtest02, 1); UtRegisterTest("DecodeIPV4DefragTest01", DecodeIPV4DefragTest01, 1); UtRegisterTest("DecodeIPV4DefragTest02", DecodeIPV4DefragTest02, 1); UtRegisterTest("DecodeIPV4DefragTest03", DecodeIPV4DefragTest03, 1); diff --git a/src/decode-raw.c b/src/decode-raw.c index 22e1b9e1e9..8df2bc845d 100644 --- a/src/decode-raw.c +++ b/src/decode-raw.c @@ -100,7 +100,7 @@ static int DecodeRawTest01 (void) if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) { SCFree(p); - return 1; + return 0; } FlowInitConfig(FLOW_QUIET); @@ -110,13 +110,13 @@ static int DecodeRawTest01 (void) printf("expected a valid ipv6 header but it was NULL: "); FlowShutdown(); SCFree(p); - return 1; + return 0; } PACKET_RECYCLE(p); FlowShutdown(); SCFree(p); - return 0; + return 1; } /** DecodeRawtest02 @@ -146,7 +146,7 @@ static int DecodeRawTest02 (void) if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) { SCFree(p); - return 1; + return 0; } FlowInitConfig(FLOW_QUIET); @@ -157,13 +157,13 @@ static int DecodeRawTest02 (void) PACKET_RECYCLE(p); FlowShutdown(); SCFree(p); - return 1; + return 0; } PACKET_RECYCLE(p); FlowShutdown(); SCFree(p); - return 0; + return 1; } /** DecodeRawtest03 * \brief Valid Raw packet @@ -194,18 +194,17 @@ static int DecodeRawTest03 (void) if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) { SCFree(p); - return 1; + return 0; } FlowInitConfig(FLOW_QUIET); DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p), NULL); - if (ENGINE_ISSET_EVENT(p,IPRAW_INVALID_IPV)) { + if (!ENGINE_ISSET_EVENT(p,IPRAW_INVALID_IPV)) { + printf("expected IPRAW_INVALID_IPV to be set but it wasn't: "); FlowShutdown(); SCFree(p); return 0; - } else { - printf("expected IPRAW_INVALID_IPV to be set but it wasn't: "); } PACKET_RECYCLE(p); FlowShutdown(); @@ -222,9 +221,9 @@ static int DecodeRawTest03 (void) void DecodeRawRegisterTests(void) { #ifdef UNITTESTS - UtRegisterTest("DecodeRawTest01", DecodeRawTest01, 0); - UtRegisterTest("DecodeRawTest02", DecodeRawTest02, 0); - UtRegisterTest("DecodeRawTest03", DecodeRawTest03, 0); + UtRegisterTest("DecodeRawTest01", DecodeRawTest01, 1); + UtRegisterTest("DecodeRawTest02", DecodeRawTest02, 1); + UtRegisterTest("DecodeRawTest03", DecodeRawTest03, 1); #endif /* UNITTESTS */ } /** diff --git a/src/decode-tcp.c b/src/decode-tcp.c index ae3650be11..d7f3522c05 100644 --- a/src/decode-tcp.c +++ b/src/decode-tcp.c @@ -253,7 +253,7 @@ static int TCPCalculateInvalidChecksumtest02(void) csum = *( ((uint16_t *)raw_tcp) + 8); - return (csum == TCPCalculateChecksum((uint16_t *) raw_ipshdr, + return (csum != TCPCalculateChecksum((uint16_t *) raw_ipshdr, (uint16_t *)raw_tcp, sizeof(raw_tcp))); } @@ -299,7 +299,7 @@ static int TCPV6CalculateInvalidChecksumtest04(void) csum = *( ((uint16_t *)(raw_ipv6 + 70))); - return (csum == TCPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8), + return (csum != TCPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8), (uint16_t *)(raw_ipv6 + 54), 32)); } @@ -513,11 +513,11 @@ void DecodeTCPRegisterTests(void) UtRegisterTest("TCPCalculateValidChecksumtest01", TCPCalculateValidChecksumtest01, 1); UtRegisterTest("TCPCalculateInvalidChecksumtest02", - TCPCalculateInvalidChecksumtest02, 0); + TCPCalculateInvalidChecksumtest02, 1); UtRegisterTest("TCPV6CalculateValidChecksumtest03", TCPV6CalculateValidChecksumtest03, 1); UtRegisterTest("TCPV6CalculateInvalidChecksumtest04", - TCPV6CalculateInvalidChecksumtest04, 0); + TCPV6CalculateInvalidChecksumtest04, 1); UtRegisterTest("TCPGetWscaleTest01", TCPGetWscaleTest01, 1); UtRegisterTest("TCPGetWscaleTest02", TCPGetWscaleTest02, 1); UtRegisterTest("TCPGetWscaleTest03", TCPGetWscaleTest03, 1); diff --git a/src/decode-udp.c b/src/decode-udp.c index 14ba7887d3..cef9a45488 100644 --- a/src/decode-udp.c +++ b/src/decode-udp.c @@ -150,7 +150,7 @@ static int UDPV4CalculateInvalidChecksumtest02(void) csum = *( ((uint16_t *)raw_udp) + 3); - return (csum == UDPV4CalculateChecksum((uint16_t *) raw_ipshdr, + return (csum != UDPV4CalculateChecksum((uint16_t *) raw_ipshdr, (uint16_t *)raw_udp, sizeof(raw_udp))); } @@ -195,7 +195,7 @@ static int UDPV6CalculateInvalidChecksumtest04(void) csum = *( ((uint16_t *)(raw_ipv6 + 60))); - return (csum == UDPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8), + return (csum != UDPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8), (uint16_t *)(raw_ipv6 + 54), 20)); } #endif /* UNITTESTS */ @@ -206,11 +206,11 @@ void DecodeUDPV4RegisterTests(void) UtRegisterTest("UDPV4CalculateValidChecksumtest01", UDPV4CalculateValidChecksumtest01, 1); UtRegisterTest("UDPV4CalculateInvalidChecksumtest02", - UDPV4CalculateInvalidChecksumtest02, 0); + UDPV4CalculateInvalidChecksumtest02, 1); UtRegisterTest("UDPV6CalculateValidChecksumtest03", UDPV6CalculateValidChecksumtest03, 1); UtRegisterTest("UDPV6CalculateInvalidChecksumtest04", - UDPV6CalculateInvalidChecksumtest04, 0); + UDPV6CalculateInvalidChecksumtest04, 1); #endif /* UNITTESTS */ } /** diff --git a/src/detect-detection-filter.c b/src/detect-detection-filter.c index 7e1ee8bc9b..7a95446f8b 100644 --- a/src/detect-detection-filter.c +++ b/src/detect-detection-filter.c @@ -322,10 +322,10 @@ int DetectDetectionFilterTestParse02 (void) df = DetectDetectionFilterParse("track both,count 10,seconds 60"); if (df && (df->track == TRACK_DST || df->track == TRACK_SRC) && (df->count == 10) && (df->seconds == 60)) { DetectDetectionFilterFree(df); - return 1; + return 0; } - return 0; + return 1; } /** @@ -359,10 +359,10 @@ int DetectDetectionFilterTestParse04 (void) df = DetectDetectionFilterParse("count 10, track by_dst, seconds 60, count 10"); if (df && (df->track == TRACK_DST) && (df->count == 10) && (df->seconds == 60)) { DetectDetectionFilterFree(df); - return 1; + return 0; } - return 0; + return 1; } /** @@ -395,10 +395,10 @@ int DetectDetectionFilterTestParse06 (void) df = DetectDetectionFilterParse("count 10, track by_dst, seconds 0"); if (df && (df->track == TRACK_DST) && (df->count == 10) && (df->seconds == 0)) { DetectDetectionFilterFree(df); - return 1; + return 0; } - return 0; + return 1; } /** @@ -652,11 +652,11 @@ void DetectDetectionFilterRegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("DetectDetectionFilterTestParse01", DetectDetectionFilterTestParse01, 1); - UtRegisterTest("DetectDetectionFilterTestParse02", DetectDetectionFilterTestParse02, 0); + UtRegisterTest("DetectDetectionFilterTestParse02", DetectDetectionFilterTestParse02, 1); UtRegisterTest("DetectDetectionFilterTestParse03", DetectDetectionFilterTestParse03, 1); - UtRegisterTest("DetectDetectionFilterTestParse04", DetectDetectionFilterTestParse04, 0); + UtRegisterTest("DetectDetectionFilterTestParse04", DetectDetectionFilterTestParse04, 1); UtRegisterTest("DetectDetectionFilterTestParse05", DetectDetectionFilterTestParse05, 1); - UtRegisterTest("DetectDetectionFilterTestParse06", DetectDetectionFilterTestParse06, 0); + UtRegisterTest("DetectDetectionFilterTestParse06", DetectDetectionFilterTestParse06, 1); UtRegisterTest("DetectDetectionFilterTestSig1", DetectDetectionFilterTestSig1, 1); UtRegisterTest("DetectDetectionFilterTestSig2", DetectDetectionFilterTestSig2, 1); UtRegisterTest("DetectDetectionFilterTestSig3", DetectDetectionFilterTestSig3, 1); diff --git a/src/detect-engine-event.c b/src/detect-engine-event.c index 9a8e23967e..a03c630933 100644 --- a/src/detect-engine-event.c +++ b/src/detect-engine-event.c @@ -332,10 +332,10 @@ int EngineEventTestParse04 (void) de = DetectEngineEventParse("decoder.IPV6.INVALID_EVENT"); if (de) { DetectEngineEventFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -347,10 +347,10 @@ int EngineEventTestParse05 (void) de = DetectEngineEventParse("decoder.IPV-6,INVALID_CHAR"); if (de) { DetectEngineEventFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -409,8 +409,8 @@ void EngineEventRegisterTests(void) UtRegisterTest("EngineEventTestParse01", EngineEventTestParse01, 1); UtRegisterTest("EngineEventTestParse02", EngineEventTestParse02, 1); UtRegisterTest("EngineEventTestParse03", EngineEventTestParse03, 1); - UtRegisterTest("EngineEventTestParse04", EngineEventTestParse04, 0); - UtRegisterTest("EngineEventTestParse05", EngineEventTestParse05, 0); + UtRegisterTest("EngineEventTestParse04", EngineEventTestParse04, 1); + UtRegisterTest("EngineEventTestParse05", EngineEventTestParse05, 1); UtRegisterTest("EngineEventTestParse06", EngineEventTestParse06, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-engine-filedata-smtp.c b/src/detect-engine-filedata-smtp.c index 80fec628dc..1f7c666404 100644 --- a/src/detect-engine-filedata-smtp.c +++ b/src/detect-engine-filedata-smtp.c @@ -585,7 +585,7 @@ end: StreamTcpFreeConfig(TRUE); FLOW_DESTROY(&f); UTHFreePackets(&p, 1); - return result; + return result == 0; } #endif /* UNITTESTS */ @@ -598,7 +598,7 @@ void DetectEngineSMTPFiledataRegisterTests(void) UtRegisterTest("DetectEngineSMTPFiledataTest02", DetectEngineSMTPFiledataTest02, 1); UtRegisterTest("DetectEngineSMTPFiledataTest03", - DetectEngineSMTPFiledataTest03, 0); + DetectEngineSMTPFiledataTest03, 1); #endif /* UNITTESTS */ return; diff --git a/src/detect-file-data.c b/src/detect-file-data.c index 258a135cf0..f8654b017f 100644 --- a/src/detect-file-data.c +++ b/src/detect-file-data.c @@ -213,6 +213,9 @@ end: return result; } +/** + * \test Test the file_data fails with flow:to_server. + */ static int DetectFiledataParseTest04(void) { DetectEngineCtx *de_ctx = NULL; @@ -227,11 +230,9 @@ static int DetectFiledataParseTest04(void) "alert smtp any any -> any any " "(msg:\"test\"; flow:to_client,established; file_data; content:\"abc\"; sid:1;)"); if (de_ctx->sig_list == NULL) { - printf("sig parse failed: "); - goto end; + result = 1; } - result = 1; end: SigGroupCleanup(de_ctx); SigCleanSignatures(de_ctx); @@ -240,6 +241,9 @@ end: return result; } +/** + * \test Test the file_data fails with flow:to_server. + */ static int DetectFiledataParseTest05(void) { DetectEngineCtx *de_ctx = NULL; @@ -254,11 +258,9 @@ static int DetectFiledataParseTest05(void) "alert http any any -> any any " "(msg:\"test\"; flow:to_server,established; file_data; content:\"abc\"; sid:1;)"); if (de_ctx->sig_list == NULL) { - printf("sig parse failed: "); - goto end; + result = 1; } - result = 1; end: SigGroupCleanup(de_ctx); SigCleanSignatures(de_ctx); @@ -274,7 +276,7 @@ void DetectFiledataRegisterTests(void) UtRegisterTest("DetectFiledataParseTest01", DetectFiledataParseTest01, 1); UtRegisterTest("DetectFiledataParseTest02", DetectFiledataParseTest02, 1); UtRegisterTest("DetectFiledataParseTest03", DetectFiledataParseTest03, 1); - UtRegisterTest("DetectFiledataParseTest04", DetectFiledataParseTest04, 0); - UtRegisterTest("DetectFiledataParseTest05", DetectFiledataParseTest05, 0); + UtRegisterTest("DetectFiledataParseTest04", DetectFiledataParseTest04, 1); + UtRegisterTest("DetectFiledataParseTest05", DetectFiledataParseTest05, 1); #endif } diff --git a/src/detect-flags.c b/src/detect-flags.c index 51768f1797..bdf3147d0c 100644 --- a/src/detect-flags.c +++ b/src/detect-flags.c @@ -595,10 +595,10 @@ static int FlagsTestParse02 (void) de = DetectFlagsParse("G"); if (de) { DetectFlagsFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -701,14 +701,15 @@ static int FlagsTestParse04 (void) if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 1; + return 0; } + /* Error expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 0; + return 1; } /** @@ -756,14 +757,15 @@ static int FlagsTestParse05 (void) if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 1; + return 0; } + /* Error expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 0; + return 1; } /** @@ -866,14 +868,15 @@ static int FlagsTestParse07 (void) if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 1; + return 0; } + /* Error expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 0; + return 1; } /** @@ -1086,14 +1089,15 @@ static int FlagsTestParse11 (void) if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 1; + return 0; } + /* Expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 0; + return 1; } /** @@ -1143,14 +1147,15 @@ static int FlagsTestParse12 (void) if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 1; + return 0; } + /* Expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 0; + return 1; } /** @@ -1359,17 +1364,17 @@ void FlagsRegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("FlagsTestParse01", FlagsTestParse01, 1); - UtRegisterTest("FlagsTestParse02", FlagsTestParse02, 0); + UtRegisterTest("FlagsTestParse02", FlagsTestParse02, 1); UtRegisterTest("FlagsTestParse03", FlagsTestParse03, 1); - UtRegisterTest("FlagsTestParse04", FlagsTestParse04, 0); - UtRegisterTest("FlagsTestParse05", FlagsTestParse05, 0); + UtRegisterTest("FlagsTestParse04", FlagsTestParse04, 1); + UtRegisterTest("FlagsTestParse05", FlagsTestParse05, 1); UtRegisterTest("FlagsTestParse06", FlagsTestParse06, 1); - UtRegisterTest("FlagsTestParse07", FlagsTestParse07, 0); + UtRegisterTest("FlagsTestParse07", FlagsTestParse07, 1); UtRegisterTest("FlagsTestParse08", FlagsTestParse08, 1); UtRegisterTest("FlagsTestParse09", FlagsTestParse09, 1); UtRegisterTest("FlagsTestParse10", FlagsTestParse10, 1); - UtRegisterTest("FlagsTestParse11", FlagsTestParse11, 0); - UtRegisterTest("FlagsTestParse12", FlagsTestParse12, 0); + UtRegisterTest("FlagsTestParse11", FlagsTestParse11, 1); + UtRegisterTest("FlagsTestParse12", FlagsTestParse12, 1); UtRegisterTest("FlagsTestParse13", FlagsTestParse13, 1); UtRegisterTest("FlagsTestParse14", FlagsTestParse14, 1); UtRegisterTest("FlagsTestParse15", FlagsTestParse15, 1); diff --git a/src/detect-flowbits.c b/src/detect-flowbits.c index 2c10f49955..792c1e1ef7 100644 --- a/src/detect-flowbits.c +++ b/src/detect-flowbits.c @@ -452,7 +452,7 @@ end: } SCFree(p); - return result; + return result == 0; } /** @@ -574,7 +574,7 @@ end: } SCFree(p); - return result; + return result == 0; } /** @@ -652,7 +652,7 @@ end: SCFree(p); - return result; + return result == 0; } /** @@ -1004,7 +1004,7 @@ static int FlowBitsTestSig07(void) FLOW_DESTROY(&f); SCFree(p); - return result; + return result == 0; end: if (de_ctx != NULL) { @@ -1024,7 +1024,7 @@ end: FLOW_DESTROY(&f); SCFree(p); - return result; + return result == 0; } /** @@ -1113,7 +1113,7 @@ static int FlowBitsTestSig08(void) FLOW_DESTROY(&f); SCFree(p); - return result; + return result == 0; end: if (de_ctx != NULL) { @@ -1133,7 +1133,7 @@ end: FLOW_DESTROY(&f); SCFree(p); - return result; + return result == 0; } #endif /* UNITTESTS */ @@ -1144,13 +1144,13 @@ void FlowBitsRegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("FlowBitsTestParse01", FlowBitsTestParse01, 1); - UtRegisterTest("FlowBitsTestSig01", FlowBitsTestSig01, 0); - UtRegisterTest("FlowBitsTestSig02", FlowBitsTestSig02, 0); - UtRegisterTest("FlowBitsTestSig03", FlowBitsTestSig03, 0); + UtRegisterTest("FlowBitsTestSig01", FlowBitsTestSig01, 1); + UtRegisterTest("FlowBitsTestSig02", FlowBitsTestSig02, 1); + UtRegisterTest("FlowBitsTestSig03", FlowBitsTestSig03, 1); UtRegisterTest("FlowBitsTestSig04", FlowBitsTestSig04, 1); UtRegisterTest("FlowBitsTestSig05", FlowBitsTestSig05, 1); UtRegisterTest("FlowBitsTestSig06", FlowBitsTestSig06, 1); - UtRegisterTest("FlowBitsTestSig07", FlowBitsTestSig07, 0); - UtRegisterTest("FlowBitsTestSig08", FlowBitsTestSig08, 0); + UtRegisterTest("FlowBitsTestSig07", FlowBitsTestSig07, 1); + UtRegisterTest("FlowBitsTestSig08", FlowBitsTestSig08, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-fragbits.c b/src/detect-fragbits.c index 7a564ba01a..663735cc14 100644 --- a/src/detect-fragbits.c +++ b/src/detect-fragbits.c @@ -362,10 +362,10 @@ static int FragBitsTestParse02 (void) de = DetectFragBitsParse("G"); if (de) { DetectFragBitsFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -554,16 +554,17 @@ static int FragBitsTestParse04 (void) PACKET_RECYCLE(p); FlowShutdown(); SCFree(p); - return 1; + return 0; } + /* Error expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); PACKET_RECYCLE(p); FlowShutdown(); SCFree(p); - return 0; + return 1; } #endif /* UNITTESTS */ @@ -574,8 +575,8 @@ void FragBitsRegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("FragBitsTestParse01", FragBitsTestParse01, 1); - UtRegisterTest("FragBitsTestParse02", FragBitsTestParse02, 0); + UtRegisterTest("FragBitsTestParse02", FragBitsTestParse02, 1); UtRegisterTest("FragBitsTestParse03", FragBitsTestParse03, 1); - UtRegisterTest("FragBitsTestParse04", FragBitsTestParse04, 0); + UtRegisterTest("FragBitsTestParse04", FragBitsTestParse04, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-fragoffset.c b/src/detect-fragoffset.c index c887b7b979..62e1852d29 100644 --- a/src/detect-fragoffset.c +++ b/src/detect-fragoffset.c @@ -299,9 +299,9 @@ int DetectFragOffsetParseTest03 (void) fragoff = DetectFragOffsetParse("badc"); if (fragoff != NULL) { DetectFragOffsetFree(fragoff); - return 1; + return 0; } - return 0; + return 1; } /** @@ -389,7 +389,7 @@ void DetectFragOffsetRegisterTests (void) #ifdef UNITTESTS UtRegisterTest("DetectFragOffsetParseTest01", DetectFragOffsetParseTest01, 1); UtRegisterTest("DetectFragOffsetParseTest02", DetectFragOffsetParseTest02, 1); - UtRegisterTest("DetectFragOffsetParseTest03", DetectFragOffsetParseTest03, 0); + UtRegisterTest("DetectFragOffsetParseTest03", DetectFragOffsetParseTest03, 1); UtRegisterTest("DetectFragOffsetMatchTest01", DetectFragOffsetMatchTest01, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-icmp-seq.c b/src/detect-icmp-seq.c index 4e3fe1ac19..4c57842101 100644 --- a/src/detect-icmp-seq.c +++ b/src/detect-icmp-seq.c @@ -310,9 +310,9 @@ int DetectIcmpSeqParseTest03 (void) iseq = DetectIcmpSeqParse("badc"); if (iseq != NULL) { DetectIcmpSeqFree(iseq); - return 1; + return 0; } - return 0; + return 1; } /** @@ -383,7 +383,7 @@ void DetectIcmpSeqRegisterTests (void) #ifdef UNITTESTS UtRegisterTest("DetectIcmpSeqParseTest01", DetectIcmpSeqParseTest01, 1); UtRegisterTest("DetectIcmpSeqParseTest02", DetectIcmpSeqParseTest02, 1); - UtRegisterTest("DetectIcmpSeqParseTest03", DetectIcmpSeqParseTest03, 0); + UtRegisterTest("DetectIcmpSeqParseTest03", DetectIcmpSeqParseTest03, 1); UtRegisterTest("DetectIcmpSeqMatchTest01", DetectIcmpSeqMatchTest01, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-ipopts.c b/src/detect-ipopts.c index 159578ee0e..fbe143abea 100644 --- a/src/detect-ipopts.c +++ b/src/detect-ipopts.c @@ -261,10 +261,10 @@ int IpOptsTestParse02 (void) de = DetectIpOptsParse("invalidopt"); if (de) { DetectIpOptsFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -361,14 +361,15 @@ int IpOptsTestParse04 (void) if(ret) { SCFree(p); - return 1; + return 0; } + /* Error expected. */ error: if (de) SCFree(de); if (sm) SCFree(sm); SCFree(p); - return 0; + return 1; } #endif /* UNITTESTS */ @@ -379,8 +380,8 @@ void IpOptsRegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("IpOptsTestParse01", IpOptsTestParse01, 1); - UtRegisterTest("IpOptsTestParse02", IpOptsTestParse02, 0); + UtRegisterTest("IpOptsTestParse02", IpOptsTestParse02, 1); UtRegisterTest("IpOptsTestParse03", IpOptsTestParse03, 1); - UtRegisterTest("IpOptsTestParse04", IpOptsTestParse04, 0); + UtRegisterTest("IpOptsTestParse04", IpOptsTestParse04, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-iprep.c b/src/detect-iprep.c index 4e47acdcb6..6944a71f2c 100644 --- a/src/detect-iprep.c +++ b/src/detect-iprep.c @@ -757,7 +757,7 @@ end: DetectEngineCtxFree(de_ctx); HostShutdown(); - return result; + return result == 0; } static int DetectIPRepTest06(void) @@ -819,7 +819,7 @@ end: DetectEngineCtxFree(de_ctx); HostShutdown(); - return result; + return result == 0; } static int DetectIPRepTest07(void) @@ -881,7 +881,7 @@ end: DetectEngineCtxFree(de_ctx); HostShutdown(); - return result; + return result == 0; } static int DetectIPRepTest08(void) @@ -944,7 +944,7 @@ end: DetectEngineCtxFree(de_ctx); HostShutdown(); - return result; + return result == 0; } static int DetectIPRepTest09(void) @@ -1021,10 +1021,10 @@ void IPRepRegisterTests(void) UtRegisterTest("DetectIPRepTest02", DetectIPRepTest02, 1); UtRegisterTest("DetectIPRepTest03", DetectIPRepTest03, 1); UtRegisterTest("DetectIPRepTest04", DetectIPRepTest04, 1); - UtRegisterTest("DetectIPRepTest05", DetectIPRepTest05, 0); - UtRegisterTest("DetectIPRepTest06", DetectIPRepTest06, 0); - UtRegisterTest("DetectIPRepTest07", DetectIPRepTest07, 0); - UtRegisterTest("DetectIPRepTest08", DetectIPRepTest08, 0); + UtRegisterTest("DetectIPRepTest05", DetectIPRepTest05, 1); + UtRegisterTest("DetectIPRepTest06", DetectIPRepTest06, 1); + UtRegisterTest("DetectIPRepTest07", DetectIPRepTest07, 1); + UtRegisterTest("DetectIPRepTest08", DetectIPRepTest08, 1); UtRegisterTest("DetectIPRepTest09", DetectIPRepTest09, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-mark.c b/src/detect-mark.c index 695a7b412c..74edf3ce34 100644 --- a/src/detect-mark.c +++ b/src/detect-mark.c @@ -288,11 +288,11 @@ static int MarkTestParse02 (void) data = DetectMarkParse("4"); if (data == NULL) { - return 0; + return 1; } DetectMarkDataFree(data); - return 1; + return 0; } /** @@ -328,11 +328,11 @@ static int MarkTestParse04 (void) data = DetectMarkParse("0x1g/0xff"); if (data == NULL) { - return 0; + return 1; } DetectMarkDataFree(data); - return 1; + return 0; } @@ -346,8 +346,8 @@ void MarkRegisterTests(void) { #if defined UNITTESTS && defined NFQ UtRegisterTest("MarkTestParse01", MarkTestParse01, 1); - UtRegisterTest("MarkTestParse02", MarkTestParse02, 0); + UtRegisterTest("MarkTestParse02", MarkTestParse02, 1); UtRegisterTest("MarkTestParse03", MarkTestParse03, 1); - UtRegisterTest("MarkTestParse04", MarkTestParse04, 0); + UtRegisterTest("MarkTestParse04", MarkTestParse04, 1); #endif /* UNITTESTS */ } diff --git a/src/detect-replace.c b/src/detect-replace.c index 57e06e7aeb..082f598320 100644 --- a/src/detect-replace.c +++ b/src/detect-replace.c @@ -443,7 +443,7 @@ static int DetectReplaceMatchTest05(void) " content:\"th\"; replace:\"TH\"; content:\"nutella\"; sid:1;)"; char *sig_rep = "alert tcp any any -> any any (msg:\"replace worked\";" " content:\"TH\"; sid:2;)"; - return DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); + return !DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); } /** @@ -456,7 +456,7 @@ static int DetectReplaceMatchTest06(void) " content:\"nutella\"; replace:\"commode\"; content:\"this is\"; sid:1;)"; char *sig_rep = "alert tcp any any -> any any (msg:\"replace worked\";" " content:\"commode\"; sid:2;)"; - return DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); + return !DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); } /** @@ -492,7 +492,7 @@ static int DetectReplaceMatchTest09(void) " content:\"big\"; depth:16; replace:\"pig\"; sid:1;)"; char *sig_rep = "alert tcp any any -> any any (msg:\"replace worked\";" " content:\"this is a pig test\"; sid:2;)"; - return DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); + return !DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); } /** @@ -528,7 +528,7 @@ static int DetectReplaceMatchTest12(void) " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 4; sid:1;)"; char *sig_rep = "alert tcp any any -> any any (msg:\"replace worked\";" " content:\"pig\"; depth:17; offset:14; sid:2;)"; - return DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); + return !DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); } /** @@ -552,7 +552,7 @@ static int DetectReplaceMatchTest14(void) " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 2; sid:1;)"; char *sig_rep = "alert tcp any any -> any any (msg:\"replace worked\";" " content:\"pig\"; depth:17; offset:14; sid:2;)"; - return DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); + return !DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2); } /** @@ -822,16 +822,16 @@ void DetectReplaceRegisterTests(void) UtRegisterTest("DetectReplaceMatchTest02", DetectReplaceMatchTest02, 1); UtRegisterTest("DetectReplaceMatchTest03", DetectReplaceMatchTest03, 1); UtRegisterTest("DetectReplaceMatchTest04", DetectReplaceMatchTest04, 1); - UtRegisterTest("DetectReplaceMatchTest05", DetectReplaceMatchTest05, 0); - UtRegisterTest("DetectReplaceMatchTest06", DetectReplaceMatchTest06, 0); + UtRegisterTest("DetectReplaceMatchTest05", DetectReplaceMatchTest05, 1); + UtRegisterTest("DetectReplaceMatchTest06", DetectReplaceMatchTest06, 1); UtRegisterTest("DetectReplaceMatchTest07", DetectReplaceMatchTest07, 1); UtRegisterTest("DetectReplaceMatchTest08", DetectReplaceMatchTest08, 1); - UtRegisterTest("DetectReplaceMatchTest09", DetectReplaceMatchTest09, 0); + UtRegisterTest("DetectReplaceMatchTest09", DetectReplaceMatchTest09, 1); UtRegisterTest("DetectReplaceMatchTest10", DetectReplaceMatchTest10, 1); UtRegisterTest("DetectReplaceMatchTest11", DetectReplaceMatchTest11, 1); - UtRegisterTest("DetectReplaceMatchTest12", DetectReplaceMatchTest12, 0); + UtRegisterTest("DetectReplaceMatchTest12", DetectReplaceMatchTest12, 1); UtRegisterTest("DetectReplaceMatchTest13", DetectReplaceMatchTest13, 1); - UtRegisterTest("DetectReplaceMatchTest14", DetectReplaceMatchTest14, 0); + UtRegisterTest("DetectReplaceMatchTest14", DetectReplaceMatchTest14, 1); UtRegisterTest("DetectReplaceMatchTest15", DetectReplaceMatchTest15, 1); /* parsing */ UtRegisterTest("DetectReplaceParseTest01", DetectReplaceParseTest01, 1); diff --git a/src/detect-threshold.c b/src/detect-threshold.c index 236b6bf627..e0850a3c9b 100644 --- a/src/detect-threshold.c +++ b/src/detect-threshold.c @@ -333,10 +333,10 @@ static int ThresholdTestParse02(void) de = DetectThresholdParse("type any,track by_dst,count 10,seconds 60"); if (de && (de->type == TYPE_LIMIT) && (de->track == TRACK_DST) && (de->count == 10) && (de->seconds == 60)) { DetectThresholdFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -370,10 +370,10 @@ static int ThresholdTestParse04(void) de = DetectThresholdParse("count 10, track by_dst, seconds 60, type both, count 10"); if (de && (de->type == TYPE_BOTH) && (de->track == TRACK_DST) && (de->count == 10) && (de->seconds == 60)) { DetectThresholdFree(de); - return 1; + return 0; } - return 0; + return 1; } /** @@ -1501,9 +1501,9 @@ void ThresholdRegisterTests(void) { #ifdef UNITTESTS UtRegisterTest("ThresholdTestParse01", ThresholdTestParse01, 1); - UtRegisterTest("ThresholdTestParse02", ThresholdTestParse02, 0); + UtRegisterTest("ThresholdTestParse02", ThresholdTestParse02, 1); UtRegisterTest("ThresholdTestParse03", ThresholdTestParse03, 1); - UtRegisterTest("ThresholdTestParse04", ThresholdTestParse04, 0); + UtRegisterTest("ThresholdTestParse04", ThresholdTestParse04, 1); UtRegisterTest("ThresholdTestParse05", ThresholdTestParse05, 1); UtRegisterTest("DetectThresholdTestSig1", DetectThresholdTestSig1, 1); UtRegisterTest("DetectThresholdTestSig2", DetectThresholdTestSig2, 1); diff --git a/src/util-decode-mime.c b/src/util-decode-mime.c index ded4cd6044..8664a9438c 100644 --- a/src/util-decode-mime.c +++ b/src/util-decode-mime.c @@ -2691,18 +2691,18 @@ static int MimeDecParseLineTest01(void) ret |= MimeDecParseLine((uint8_t *)str, strlen(str), 1, state); if (ret != MIME_DEC_OK) { - return ret; + return 0; } /* Completed */ ret = MimeDecParseComplete(state); if (ret != MIME_DEC_OK) { - return ret; + return 0; } MimeDecEntity *msg = state->msg; if (msg->next != NULL || msg->child != NULL) { SCLogInfo("Error: Invalid sibling or child message"); - return -1; + return 0; } MimeDecFreeEntity(msg); @@ -2715,10 +2715,10 @@ static int MimeDecParseLineTest01(void) if (expected_count != line_count) { SCLogInfo("Error: Line count is invalid: expected - %d actual - %d", expected_count, line_count); - return -1; + return 0; } - return ret; + return 1; } /* Test simple case of EXE URL extraction */ @@ -2757,19 +2757,19 @@ static int MimeDecParseLineTest02(void) ret |= MimeDecParseLine((uint8_t *)str, strlen(str), 1, state); if (ret != MIME_DEC_OK) { - return ret; + return 0; } /* Completed */ ret = MimeDecParseComplete(state); if (ret != MIME_DEC_OK) { - return ret; + return 0; } MimeDecEntity *msg = state->msg; if (msg->url_list == NULL || (msg->url_list != NULL && !(msg->url_list->url_flags & URL_IS_EXE))) { SCLogInfo("Warning: Expected EXE URL not found"); - return -1; + return 0; } MimeDecFreeEntity(msg); @@ -2782,17 +2782,15 @@ static int MimeDecParseLineTest02(void) if (expected_count != line_count) { SCLogInfo("Warning: Line count is invalid: expected - %d actual - %d", expected_count, line_count); - return -1; + return 0; } - return ret; + return 1; } /* Test full message with linebreaks */ static int MimeDecParseFullMsgTest01(void) { - int ret = MIME_DEC_OK; - uint32_t expected_count = 3; uint32_t line_count = 0; @@ -2808,7 +2806,7 @@ static int MimeDecParseFullMsgTest01(void) TestDataChunkCallback); if (entity == NULL) { SCLogInfo("Warning: Message failed to parse"); - return -1; + return 0; } MimeDecFreeEntity(entity); @@ -2816,17 +2814,15 @@ static int MimeDecParseFullMsgTest01(void) if (expected_count != line_count) { SCLogInfo("Warning: Line count is invalid: expected - %d actual - %d", expected_count, line_count); - return -1; + return 0; } - return ret; + return 1; } /* Test full message with linebreaks */ static int MimeDecParseFullMsgTest02(void) { - int ret = MIME_DEC_OK; - uint32_t expected_count = 3; uint32_t line_count = 0; @@ -2844,23 +2840,23 @@ static int MimeDecParseFullMsgTest02(void) if (entity == NULL) { SCLogInfo("Warning: Message failed to parse"); - return -1; + return 0; } MimeDecField *field = MimeDecFindField(entity, "subject"); if (field == NULL) { SCLogInfo("Warning: Message failed to parse"); - return -1; + return 0; } if (field->value_len != sizeof("subject2") - 1) { SCLogInfo("Warning: failed to get subject"); - return -1; + return 0; } if (memcmp(field->value, "subject2", field->value_len) != 0) { SCLogInfo("Warning: failed to get subject"); - return -1; + return 0; } @@ -2869,15 +2865,15 @@ static int MimeDecParseFullMsgTest02(void) if (expected_count != line_count) { SCLogInfo("Warning: Line count is invalid: expected - %d actual - %d", expected_count, line_count); - return -1; + return 0; } - return ret; + return 1; } static int MimeBase64DecodeTest01(void) { - int ret = -1; + int ret = 0; char *msg = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@" "#$%^&*()-=_+,./;'[]<>?:"; @@ -2891,7 +2887,7 @@ static int MimeBase64DecodeTest01(void) ret = DecodeBase64(dst, (const uint8_t *)base64msg, strlen(base64msg), 1); if (memcmp(dst, msg, strlen(msg)) == 0) { - ret = 0; + ret = 1; } SCFree(dst); @@ -2901,7 +2897,7 @@ static int MimeBase64DecodeTest01(void) static int MimeIsExeURLTest01(void) { - int ret = -1; + int ret = 0; char *url1 = "http://www.google.com/"; char *url2 = "http://www.google.com/test.exe"; @@ -2913,7 +2909,7 @@ static int MimeIsExeURLTest01(void) SCLogDebug("Debug: URL2 error"); goto end; } - ret = 0; + ret = 1; end: @@ -2923,67 +2919,67 @@ static int MimeIsExeURLTest01(void) static int MimeIsIpv4HostTest01(void) { if(IsIpv4Host((const uint8_t *)"192.168.1.1", 11) != 1) { - return 1; + return 0; } if(IsIpv4Host((const uint8_t *)"999.oogle.com", 14) != 0) { - return 1; + return 0; } if(IsIpv4Host((const uint8_t *)"0:0:0:0:0:0:0:0", 15) != 0) { - return 1; + return 0; } if (IsIpv4Host((const uint8_t *)"192.168.255.255", 15) != 1) { - return 1; + return 0; } if (IsIpv4Host((const uint8_t *)"192.168.255.255/testurl.html", 28) != 1) { - return 1; + return 0; } if (IsIpv4Host((const uint8_t *)"www.google.com", 14) != 0) { - return 1; + return 0; } - return 0; + return 1; } static int MimeIsIpv6HostTest01(void) { if(IsIpv6Host((const uint8_t *)"0:0:0:0:0:0:0:0", 19) != 1) { - return 1; + return 0; } if(IsIpv6Host((const uint8_t *)"0000:0000:0000:0000:0000:0000:0000:0000", 39) != 1) { - return 1; + return 0; } if(IsIpv6Host((const uint8_t *)"0:0:0:0:0:0:0:0", 19) != 1) { - return 1; + return 0; } if(IsIpv6Host((const uint8_t *)"192:168:1:1:0:0:0:0", 19) != 1) { - return 1; + return 0; } if(IsIpv6Host((const uint8_t *)"999.oogle.com", 14) != 0) { - return 1; + return 0; } if (IsIpv6Host((const uint8_t *)"192.168.255.255", 15) != 0) { - return 1; + return 0; } if (IsIpv6Host((const uint8_t *)"192.168.255.255/testurl.html", 28) != 0) { - return 1; + return 0; } if (IsIpv6Host((const uint8_t *)"www.google.com", 14) != 0) { - return 1; + return 0; } - return 0; + return 1; } #endif /* UNITTESTS */ @@ -2991,13 +2987,13 @@ static int MimeIsIpv6HostTest01(void) void MimeDecRegisterTests(void) { #ifdef UNITTESTS - UtRegisterTest("MimeDecParseLineTest01", MimeDecParseLineTest01, 0); - UtRegisterTest("MimeDecParseLineTest02", MimeDecParseLineTest02, 0); - UtRegisterTest("MimeDecParseFullMsgTest01", MimeDecParseFullMsgTest01, 0); - UtRegisterTest("MimeDecParseFullMsgTest02", MimeDecParseFullMsgTest02, 0); - UtRegisterTest("MimeBase64DecodeTest01", MimeBase64DecodeTest01, 0); - UtRegisterTest("MimeIsExeURLTest01", MimeIsExeURLTest01, 0); - UtRegisterTest("MimeIsIpv4HostTest01", MimeIsIpv4HostTest01, 0); - UtRegisterTest("MimeIsIpv6HostTest01", MimeIsIpv6HostTest01, 0); + UtRegisterTest("MimeDecParseLineTest01", MimeDecParseLineTest01, 1); + UtRegisterTest("MimeDecParseLineTest02", MimeDecParseLineTest02, 1); + UtRegisterTest("MimeDecParseFullMsgTest01", MimeDecParseFullMsgTest01, 1); + UtRegisterTest("MimeDecParseFullMsgTest02", MimeDecParseFullMsgTest02, 1); + UtRegisterTest("MimeBase64DecodeTest01", MimeBase64DecodeTest01, 1); + UtRegisterTest("MimeIsExeURLTest01", MimeIsExeURLTest01, 1); + UtRegisterTest("MimeIsIpv4HostTest01", MimeIsIpv4HostTest01, 1); + UtRegisterTest("MimeIsIpv6HostTest01", MimeIsIpv6HostTest01, 1); #endif /* UNITTESTS */ } diff --git a/src/util-threshold-config.c b/src/util-threshold-config.c index f2f5ad3afe..f6c34bd0e9 100644 --- a/src/util-threshold-config.c +++ b/src/util-threshold-config.c @@ -1590,7 +1590,7 @@ end: SigGroupBuild(de_ctx); SigGroupCleanup(de_ctx); SigCleanSignatures(de_ctx); - return result; + return result == 0; } /** @@ -2882,7 +2882,7 @@ void SCThresholdConfRegisterTests(void) UtRegisterTest("SCThresholdConfTest01", SCThresholdConfTest01, 1); UtRegisterTest("SCThresholdConfTest02", SCThresholdConfTest02, 1); UtRegisterTest("SCThresholdConfTest03", SCThresholdConfTest03, 1); - UtRegisterTest("SCThresholdConfTest04", SCThresholdConfTest04, 0); + UtRegisterTest("SCThresholdConfTest04", SCThresholdConfTest04, 1); UtRegisterTest("SCThresholdConfTest05", SCThresholdConfTest05, 1); UtRegisterTest("SCThresholdConfTest06", SCThresholdConfTest06, 1); UtRegisterTest("SCThresholdConfTest07", SCThresholdConfTest07, 1); diff --git a/src/util-unittest.c b/src/util-unittest.c index c3f0fdb296..b172e9a0ff 100644 --- a/src/util-unittest.c +++ b/src/util-unittest.c @@ -292,8 +292,8 @@ int UtSelftestTrue(void) int UtSelftestFalse(void) { - if (0)return 1; - else return 0; + if (0)return 0; + else return 1; } #endif /* UNITTESTS */ @@ -312,7 +312,7 @@ int UtRunSelftest (char *regex_arg) UtInitialize(); UtRegisterTest("true", UtSelftestTrue, 1); - UtRegisterTest("false", UtSelftestFalse, 0); + UtRegisterTest("false", UtSelftestFalse, 1); int ret = UtRunTests(regex_arg); if (ret == 0)