Commit 540644f6 authored by Ghislain MARY's avatar Ghislain MARY

Use bctoolbox_tester instead of using CUnit directly.

parent 88104f53
......@@ -31,11 +31,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "CUnit/Basic.h"
#include "bzrtp/bzrtp.h"
#include "cryptoUtils.h"
#include "testUtils.h"
#include <bctoolbox/tester.h>
/**
*
......@@ -87,7 +87,7 @@ void test_zrtpKDF(void) {
(void (*)(uint8_t *, uint8_t, uint8_t *, uint32_t, uint8_t, uint8_t *))bctbx_hmacSha256,
output);
CU_ASSERT_TRUE(memcmp(output, patternKDFOutput[i], patternKDFHmacLength[i]) == 0);
BC_ASSERT_TRUE(memcmp(output, patternKDFOutput[i], patternKDFHmacLength[i]) == 0);
}
}
......@@ -112,7 +112,7 @@ uint32_t patternCRCoutput[CRC_TEST_NUMBER] = {0x5065ab04, 0x9c9edccd, 0xda5c92ea
void test_CRC32(void) {
int i;
for (i=0; i<CRC_TEST_NUMBER; i++) {
CU_ASSERT_TRUE(bzrtp_CRC32(patterCRCinput[i], patternCRCLength[i]) == patternCRCoutput[i]);
BC_ASSERT_TRUE(bzrtp_CRC32(patterCRCinput[i], patternCRCLength[i]) == patternCRCoutput[i]);
}
}
......@@ -184,7 +184,7 @@ static int testAlgoType(uint8_t algoType, uint8_t *packetTypes, uint8_t packetTy
setHelloMessageAlgo(helloMessage, algoType, packetTypes, packetTypesCount);
}
CU_ASSERT_FALSE(crypoAlgoAgreement(zrtpContext, zrtpContext->channelContext[0], helloPacket->messageData));
BC_ASSERT_FALSE(crypoAlgoAgreement(zrtpContext, zrtpContext->channelContext[0], helloPacket->messageData));
retval = compareAllAlgoTypesWithExpectedChangedOnly(zrtpContext->channelContext[0], algoType, expectedType);
bzrtp_freeZrtpPacket(helloPacket);
......@@ -296,39 +296,39 @@ void test_algoAgreement(void) {
struct st_algo_type *cipher_type;
/* check defaults */
CU_ASSERT_TRUE(testAlgoTypeWithPacket(ZRTP_UNSET_ALGO, NULL, 0, ZRTP_KEYAGREEMENT_DH3k));
BC_ASSERT_TRUE(testAlgoTypeWithPacket(ZRTP_UNSET_ALGO, NULL, 0, ZRTP_KEYAGREEMENT_DH3k));
/* key agreement type */
agreement_type_with_packet = &agreement_types_with_packet[0];
while (agreement_type_with_packet->typesCount > 0) {
CU_ASSERT_TRUE(testAlgoTypeWithPacket(ZRTP_KEYAGREEMENT_TYPE, agreement_type_with_packet->types, agreement_type_with_packet->typesCount, agreement_type_with_packet->expectedType));
BC_ASSERT_TRUE(testAlgoTypeWithPacket(ZRTP_KEYAGREEMENT_TYPE, agreement_type_with_packet->types, agreement_type_with_packet->typesCount, agreement_type_with_packet->expectedType));
agreement_type_with_packet++;
}
agreement_type_with_context = &agreement_types_with_context[0];
while (agreement_type_with_context->typesCount > 0) {
CU_ASSERT_TRUE(testAlgoTypeWithContext(ZRTP_KEYAGREEMENT_TYPE, agreement_type_with_context->types, agreement_type_with_context->typesCount, agreement_type_with_context->expectedType));
BC_ASSERT_TRUE(testAlgoTypeWithContext(ZRTP_KEYAGREEMENT_TYPE, agreement_type_with_context->types, agreement_type_with_context->typesCount, agreement_type_with_context->expectedType));
agreement_type_with_context++;
}
agreement_type = &agreement_types[0];
while (agreement_type->packetTypesCount > 0) {
CU_ASSERT_TRUE(testAlgoType(ZRTP_KEYAGREEMENT_TYPE, agreement_type->packetTypes, agreement_type->packetTypesCount, agreement_type->contextTypes, agreement_type->contextTypesCount, agreement_type->expectedType));
BC_ASSERT_TRUE(testAlgoType(ZRTP_KEYAGREEMENT_TYPE, agreement_type->packetTypes, agreement_type->packetTypesCount, agreement_type->contextTypes, agreement_type->contextTypesCount, agreement_type->expectedType));
agreement_type++;
}
/* cipher type */
cipher_type_with_packet = &cipher_types_with_packet[0];
while (cipher_type_with_packet->typesCount > 0) {
CU_ASSERT_TRUE(testAlgoTypeWithPacket(ZRTP_CIPHERBLOCK_TYPE, cipher_type_with_packet->types, cipher_type_with_packet->typesCount, cipher_type_with_packet->expectedType));
BC_ASSERT_TRUE(testAlgoTypeWithPacket(ZRTP_CIPHERBLOCK_TYPE, cipher_type_with_packet->types, cipher_type_with_packet->typesCount, cipher_type_with_packet->expectedType));
cipher_type_with_packet++;
}
cipher_type_with_context = &cipher_types_with_context[0];
while (cipher_type_with_context->typesCount > 0) {
CU_ASSERT_TRUE(testAlgoTypeWithContext(ZRTP_CIPHERBLOCK_TYPE, cipher_type_with_context->types, cipher_type_with_context->typesCount, cipher_type_with_context->expectedType));
BC_ASSERT_TRUE(testAlgoTypeWithContext(ZRTP_CIPHERBLOCK_TYPE, cipher_type_with_context->types, cipher_type_with_context->typesCount, cipher_type_with_context->expectedType));
cipher_type_with_context++;
}
cipher_type = &cipher_types[0];
while (cipher_type->packetTypesCount > 0) {
CU_ASSERT_TRUE(testAlgoType(ZRTP_CIPHERBLOCK_TYPE, cipher_type->packetTypes, cipher_type->packetTypesCount, cipher_type->contextTypes, cipher_type->contextTypesCount, cipher_type->expectedType));
BC_ASSERT_TRUE(testAlgoType(ZRTP_CIPHERBLOCK_TYPE, cipher_type->packetTypes, cipher_type->packetTypesCount, cipher_type->contextTypes, cipher_type->contextTypesCount, cipher_type->expectedType));
cipher_type++;
}
}
......@@ -413,14 +413,14 @@ void test_algoSetterGetter(void) {
/* key agreement type */
agreement_type = &agreement_types[0];
while (agreement_type->contextTypesCount > 0) {
CU_ASSERT_TRUE(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, agreement_type->contextTypes, agreement_type->contextTypesCount, agreement_type->expectedTypes, agreement_type->expectedTypesCount));
BC_ASSERT_TRUE(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, agreement_type->contextTypes, agreement_type->contextTypesCount, agreement_type->expectedTypes, agreement_type->expectedTypesCount));
agreement_type++;
}
/* cipher type */
cipher_type = &cipher_types[0];
while (cipher_type->contextTypesCount > 0) {
CU_ASSERT_TRUE(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, cipher_type->contextTypes, cipher_type->contextTypesCount, cipher_type->expectedTypes, cipher_type->expectedTypesCount));
BC_ASSERT_TRUE(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, cipher_type->contextTypes, cipher_type->contextTypesCount, cipher_type->expectedTypes, cipher_type->expectedTypesCount));
cipher_type++;
}
}
......@@ -477,7 +477,7 @@ void test_addMandatoryCryptoTypesIfNeeded(void) {
crypto_type = &crypto_types[0];
while (crypto_type->algoTypesCount > 0) {
CU_ASSERT_TRUE(testAddMandatoryCryptoTypesIfNeeded(crypto_type->algoType, crypto_type->algoTypes, crypto_type->algoTypesCount, crypto_type->expectedTypes, crypto_type->expectedTypesCount));
BC_ASSERT_TRUE(testAddMandatoryCryptoTypesIfNeeded(crypto_type->algoType, crypto_type->algoTypes, crypto_type->algoTypesCount, crypto_type->expectedTypes, crypto_type->expectedTypesCount));
crypto_type++;
}
}
This diff is collapsed.
......@@ -21,79 +21,91 @@
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "bzrtpCryptoTest.h"
#include "bzrtpParserTest.h"
#include "typedef.h"
#include "testUtils.h"
#include <bctoolbox/logging.h>
#include <bctoolbox/tester.h>
#ifdef HAVE_LIBXML2
#include <libxml/parser.h>
#endif
int main(int argc, char *argv[] ) {
int i, fails_count=0;
CU_pSuite cryptoUtilsTestSuite, parserTestSuite;
CU_pSuite *suites[] = {
&cryptoUtilsTestSuite,
&parserTestSuite,
NULL
};
if (argc>1) {
if (argv[1][0] == '-') {
if (strcmp(argv[1], "-verbose") == 0) {
verbose = 1;
} else {
printf ("Usage:\n %s [-verbose] to enable extensive logging\n", argv[0]);
return 1;
}
} else {
printf ("Usage:\n %s [-verbose] to enable extensive logging\n", argv[0]);
return 1;
}
}
test_t crypto_utils_tests[] = {
{ "zrtpKDF", test_zrtpKDF },
{ "CRC32", test_CRC32 },
{ "algo agreement", test_algoAgreement },
{ "context algo setter and getter", test_algoSetterGetter },
{ "adding mandatory crypto algorithms if needed", test_addMandatoryCryptoTypesIfNeeded }
};
test_suite_t crypto_utils_test_suite = {
"Crypto Utils",
NULL,
NULL,
NULL,
NULL,
sizeof(crypto_utils_tests) / sizeof(crypto_utils_tests[0]),
crypto_utils_tests
};
test_t packet_parser_tests[] = {
{ "Parse", test_parser },
{ "Parse hvi check fail", test_parser_hvi },
{ "Parse Exchange", test_parserComplete },
{ "State machine", test_stateMachine },
{ "ZRTP-hash", test_zrtphash }
};
test_suite_t packet_parser_test_suite = {
"Packet Parser",
NULL,
NULL,
NULL,
NULL,
sizeof(packet_parser_tests) / sizeof(packet_parser_tests[0]),
packet_parser_tests
};
void bzrtp_tester_init(void) {
#ifdef HAVE_LIBXML2
xmlInitParser();
#endif
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry()) {
return CU_get_error();
}
bc_tester_init(NULL, BCTBX_LOG_MESSAGE, BCTBX_LOG_ERROR, NULL);
/* Add the cryptoUtils suite to the registry */
cryptoUtilsTestSuite = CU_add_suite("Bzrtp Crypto Utils", NULL, NULL);
CU_add_test(cryptoUtilsTestSuite, "zrtpKDF", test_zrtpKDF);
CU_add_test(cryptoUtilsTestSuite, "CRC32", test_CRC32);
CU_add_test(cryptoUtilsTestSuite, "algo agreement", test_algoAgreement);
CU_add_test(cryptoUtilsTestSuite, "context algo setter and getter", test_algoSetterGetter);
CU_add_test(cryptoUtilsTestSuite, "adding mandatory crypto algorithms if needed", test_addMandatoryCryptoTypesIfNeeded);
/* Add the parser suite to the registry */
parserTestSuite = CU_add_suite("Bzrtp ZRTP Packet Parser", NULL, NULL);
CU_add_test(parserTestSuite, "Parse", test_parser);
CU_add_test(parserTestSuite, "Parse hvi check fail", test_parser_hvi);
CU_add_test(parserTestSuite, "Parse Exchange", test_parserComplete);
CU_add_test(parserTestSuite, "State machine", test_stateMachine);
CU_add_test(parserTestSuite, "ZRTP-hash", test_zrtphash);
/* Run all suites */
for(i=0; suites[i]; i++){
CU_basic_run_suite(*suites[i]);
fails_count += CU_get_number_of_tests_failed();
}
/* cleanup the CUnit registry */
CU_cleanup_registry();
bc_tester_add_suite(&crypto_utils_test_suite);
bc_tester_add_suite(&packet_parser_test_suite);
}
void bzrtp_tester_uninit(void) {
bc_tester_uninit();
#ifdef HAVE_LIBXML2
/* cleanup libxml2 */
xmlCleanupParser();
#endif
}
int main(int argc, char *argv[]) {
int i;
int ret;
bzrtp_tester_init();
for (i = 1; i < argc; ++i) {
int ret = bc_tester_parse_args(argc, argv, i);
if (ret > 0) {
i += ret - 1;
continue;
} else if (ret < 0) {
bc_tester_helper(argv[0], "");
}
return ret;
}
return (fails_count == 0 ? 0 : 1);
ret = bc_tester_start(argv[0]);
bzrtp_tester_uninit();
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment