From d2d0c07fb1233da1156a4a84d114863b319a1ec0 Mon Sep 17 00:00:00 2001 From: Jan Kadlec <jan.kadlec@nic.cz> Date: Tue, 2 Aug 2011 10:55:27 +0200 Subject: [PATCH] Fixed warnings in tests. --- src/dnslib/tests/dnslib/nsec3_tests.c | 31 +-- src/dnslib/tests/dnslib/packet_tests.c | 4 +- src/dnslib/tests/dnslib/response2_tests.c | 156 ++++++------ src/dnslib/tests/dnslib/zone_tests.c | 46 ++-- .../realdata/dnslib/packet_tests_realdata.c | 2 +- .../realdata/dnslib/response_tests_realdata.c | 226 +++++++++--------- .../realdata/dnslib_tests_loader_realdata.c | 2 +- 7 files changed, 233 insertions(+), 234 deletions(-) diff --git a/src/dnslib/tests/dnslib/nsec3_tests.c b/src/dnslib/tests/dnslib/nsec3_tests.c index 79d91c3eb..f76c1d124 100644 --- a/src/dnslib/tests/dnslib/nsec3_tests.c +++ b/src/dnslib/tests/dnslib/nsec3_tests.c @@ -39,7 +39,7 @@ static int test_nsec3_params_from_wire() dnslib_rdata_item_set_raw_data(rdata, 1, (uint16_t *)"\x1\x0\x0"); dnslib_rdata_item_set_raw_data(rdata, 2, (uint16_t *)"\x2\x0\x0\x64"); dnslib_rdata_item_set_raw_data(rdata, 3, - (uint16_t *)"\xF\x0\xE20110331084524"); + (uint16_t *)"\xF\x0\xE\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF"); dnslib_rrset_t *rrset = dnslib_rrset_new(dnslib_dname_new_from_str("cz.", @@ -51,6 +51,7 @@ static int test_nsec3_params_from_wire() assert(dnslib_rrset_add_rdata(rrset, rdata) == DNSLIB_EOK); dnslib_nsec3_params_t nsec3_tests_params; + UNUSED(nsec3_tests_params); int errors = 0; int lived = 0; @@ -78,7 +79,8 @@ static int test_nsec3_params_from_wire() }, "nsec3 params from wire NULL tests"); errors += lived != 1; - if (dnslib_nsec3_params_from_wire(&nsec3_test_params, rrset) != DNSLIB_EOK) { + if (dnslib_nsec3_params_from_wire(&nsec3_test_params, +rrset) != DNSLIB_EOK) { diag("Could not convert nsec3 params to wire!"); return 0; } @@ -104,8 +106,8 @@ static int test_nsec3_params_from_wire() } if (compare_wires_simple((uint8_t *)nsec3_test_params.salt, - (uint8_t *)"\xF\xF\xF\xF\xF\xF\xF\xF", - 8) != 0) { + (uint8_t *)"\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF\xF", + 15) != 0) { diag("Salt wire error"); errors++; } @@ -118,6 +120,7 @@ static int test_nsec3_sha1() { int errors = 0; int lived = 0; + lives_ok({ if (dnslib_nsec3_sha1(NULL, NULL, 1, NULL, NULL) != DNSLIB_EBADARG) { @@ -154,15 +157,6 @@ static int test_nsec3_sha1() DNSLIB_EBADARG) { errors++; } - size = NULL; - digest = 0xaaaaaa; - lived = 1; - lived = 0; - if (dnslib_nsec3_sha1(&nsec3_test_params, - data, 20, &digest, &size) != - DNSLIB_EBADARG) { - errors++; - } lived = 1; }, "NSEC3: nsec3 sha1 NULL tests"); if (errors) { @@ -174,7 +168,8 @@ static int test_nsec3_sha1() uint8_t *digest = NULL; size_t digest_size = 0; - if (dnslib_nsec3_sha1(&nsec3_test_params, "\2ns\3nic\2cz", + if (dnslib_nsec3_sha1(&nsec3_test_params, + (uint8_t *)"\2ns\3nic\2cz", strlen("\2ns\3nic\2cz"), &digest, &digest_size) != DNSLIB_EOK) { diag("Could not hash name!"); @@ -190,10 +185,10 @@ static int test_nsec3_sha1() nsec3_test_params.salt_length, nsec3_test_params.salt); assert(hashed_name); - dnslib_dname_t *dname_from_ldns = - dnslib_dname_new_from_wire(ldns_rdf_data(hashed_name), - ldns_rdf_size(hashed_name), - NULL); +// dnslib_dname_t *dname_from_ldns = +// dnslib_dname_new_from_wire(ldns_rdf_data(hashed_name), +// ldns_rdf_size(hashed_name), +// NULL); char *name_b32 = NULL; size_t size_b32 = base32hex_encode_alloc((char *)digest, digest_size, diff --git a/src/dnslib/tests/dnslib/packet_tests.c b/src/dnslib/tests/dnslib/packet_tests.c index 4b4496975..6b7643b50 100644 --- a/src/dnslib/tests/dnslib/packet_tests.c +++ b/src/dnslib/tests/dnslib/packet_tests.c @@ -119,7 +119,7 @@ static int test_packet_parse_next_rr_answer() errors++; } tmp = 1; - dnslib_rrset_t *rrset = 0xaaaa; + dnslib_rrset_t *rrset = (dnslib_rrset_t *)0xaaaa; tmp = 0; if (dnslib_packet_parse_next_rr_answer(packet, &rrset) != @@ -364,7 +364,7 @@ static int test_packet_to_wire() errors++; } lived = 1; - uint8_t *wire = 0xabcdef; + uint8_t *wire = (uint8_t *)0xabcdef; lived = 0; if (dnslib_packet_to_wire(packet, &wire, &size) != DNSLIB_EBADARG) { diff --git a/src/dnslib/tests/dnslib/response2_tests.c b/src/dnslib/tests/dnslib/response2_tests.c index ee3f41342..1a2e8b3a4 100644 --- a/src/dnslib/tests/dnslib/response2_tests.c +++ b/src/dnslib/tests/dnslib/response2_tests.c @@ -110,96 +110,96 @@ int compare_wires_simple(uint8_t *wire1, uint8_t *wire2, uint count) } -static int test_response_clear() -{ - int errors = 0; - int lived = 0; - lives_ok({ - dnslib_response2_clear(NULL, 1); - lived = 1; - }, "response2: clear NULL tests"); - errors += lived != 1; - - /* - * Create new response, convert to wire, then add something, clear - * the response, convert to wire again and compare wires. - */ - - dnslib_packet_t *response = - dnslib_packet_new(DNSLIB_PACKET_PREALLOC_RESPONSE); - dnslib_packet_set_max_size(response, DNSLIB_WIRE_HEADER_SIZE * 100); - assert(dnslib_response2_init(response) == DNSLIB_EOK); - - uint8_t *original_wire = NULL; - size_t original_size = 0; - assert(dnslib_packet_to_wire(response, &original_wire, - &original_size) == - DNSLIB_EOK); - /* Do something in question section. */ -// test_dname_t test_dname; -// test_dname.str = "ns8.nic.cz."; -// dnslib_dname_t *dname = dname_from_test_dname_str(&test_dname); -// assert(dname); - - response->question.qtype = DNSLIB_RRTYPE_HINFO; - response->question.qclass = DNSLIB_CLASS_CH; - - uint8_t *question_changed_wire = NULL; - size_t question_changed_size = 0; - assert(dnslib_packet_to_wire(response, - &question_changed_wire, - &question_changed_size) == - DNSLIB_EOK); - - dnslib_response2_set_aa(response); - dnslib_response2_set_tc(response); - dnslib_response2_set_rcode(response, dnslib_quick_rand()); - - dnslib_response2_clear(response, 0); - uint8_t *new_wire = NULL; - size_t new_size = 0; - assert(dnslib_packet_to_wire(response, &new_wire, &new_size) == - DNSLIB_EOK); - if (question_changed_size != new_size) { - diag("Wrong wire size after calling response_clear! " - "got %d should be %d", new_size, question_changed_size); - errors++; - } else { - if (compare_wires_simple(question_changed_wire, - new_wire, new_size)) { - diag("Wrong wire after calling response_clear! "); - errors++; - } - } - free(new_wire); - - new_wire = NULL; - new_size = 0; +//static int test_response_clear() +//{ +// int errors = 0; +// int lived = 0; +// lives_ok({ +// dnslib_response2_clear(NULL, 1); +// lived = 1; +// }, "response2: clear NULL tests"); +// errors += lived != 1; + +// /* +// * Create new response, convert to wire, then add something, clear +// * the response, convert to wire again and compare wires. +// */ + +// dnslib_packet_t *response = +// dnslib_packet_new(DNSLIB_PACKET_PREALLOC_RESPONSE); +// dnslib_packet_set_max_size(response, DNSLIB_WIRE_HEADER_SIZE * 100); +// assert(dnslib_response2_init(response) == DNSLIB_EOK); + +// uint8_t *original_wire = NULL; +// size_t original_size = 0; +// assert(dnslib_packet_to_wire(response, &original_wire, +// &original_size) == +// DNSLIB_EOK); +// /* Do something in question section. */ +//// test_dname_t test_dname; +//// test_dname.str = "ns8.nic.cz."; +//// dnslib_dname_t *dname = dname_from_test_dname_str(&test_dname); +//// assert(dname); + +// response->question.qtype = DNSLIB_RRTYPE_HINFO; +// response->question.qclass = DNSLIB_CLASS_CH; + +// uint8_t *question_changed_wire = NULL; +// size_t question_changed_size = 0; +// assert(dnslib_packet_to_wire(response, +// &question_changed_wire, +// &question_changed_size) == +// DNSLIB_EOK); - /*!< \todo figure out this segfault! */ +// dnslib_response2_set_aa(response); +// dnslib_response2_set_tc(response); +// dnslib_response2_set_rcode(response, dnslib_quick_rand()); -// dnslib_response2_clear(response, 1); +// dnslib_response2_clear(response, 0); +// uint8_t *new_wire = NULL; +// size_t new_size = 0; // assert(dnslib_packet_to_wire(response, &new_wire, &new_size) == // DNSLIB_EOK); - -// if (original_size != new_size) { -// diag("Wrong wire size after calling response_clear!"); +// if (question_changed_size != new_size) { +// diag("Wrong wire size after calling response_clear! " +// "got %d should be %d", new_size, question_changed_size); // errors++; // } else { -// if (compare_wires_simple(original_wire, +// if (compare_wires_simple(question_changed_wire, // new_wire, new_size)) { -// diag("Wrong wire after calling response_clear!"); +// diag("Wrong wire after calling response_clear! "); // errors++; // } // } - // free(new_wire); -// free(original_wire); -// free(question_changed_wire); -// dnslib_packet_free(&response); - return (errors == 0); -} +// new_wire = NULL; +// new_size = 0; + +// /*!< \todo figure out this segfault! */ + +//// dnslib_response2_clear(response, 1); +//// assert(dnslib_packet_to_wire(response, &new_wire, &new_size) == +//// DNSLIB_EOK); + +//// if (original_size != new_size) { +//// diag("Wrong wire size after calling response_clear!"); +//// errors++; +//// } else { +//// if (compare_wires_simple(original_wire, +//// new_wire, new_size)) { +//// diag("Wrong wire after calling response_clear!"); +//// errors++; +//// } +//// } + +//// free(new_wire); +//// free(original_wire); +//// free(question_changed_wire); +//// dnslib_packet_free(&response); + +// return (errors == 0); +//} static int test_response_add_opt() { diff --git a/src/dnslib/tests/dnslib/zone_tests.c b/src/dnslib/tests/dnslib/zone_tests.c index 29d65c914..c25157b0b 100644 --- a/src/dnslib/tests/dnslib/zone_tests.c +++ b/src/dnslib/tests/dnslib/zone_tests.c @@ -339,12 +339,12 @@ static int test_zone_find_node(dnslib_zone_t *zone, int nsec3) return (errors == 0); } -static void test_zone_destroy_node_from_tree(dnslib_node_t *node, - void *data) -{ - UNUSED(data); - dnslib_node_free(&node, 0); -} +//static void test_zone_destroy_node_from_tree(dnslib_node_t *node, +// void *data) +//{ +// UNUSED(data); +// dnslib_node_free(&node, 0); +//} /* explained below */ static size_t node_index = 0; @@ -509,28 +509,32 @@ static int test_zone_shallow_copy() "arguments did not return DNSLIB_EBADARG!"); errors++; } - + lived = 1; + lived = 0; dnslib_zone_t *zone = dnslib_zone_new(apex_node, 0, 1); if (dnslib_zone_shallow_copy(zone, NULL) != DNSLIB_EBADARG) { diag("Calling zone_shallow_copy with NULL destination " "zone argument did not return DNSLIB_EBADARG!"); errors++; } - + lived = 1; + lived = 0; if (dnslib_zone_shallow_copy(NULL, &zone) != DNSLIB_EBADARG) { diag("Calling zone_shallow_copy with NULL source " "zone argument did not return DNSLIB_EBADARG!"); errors++; } - + lived = 1; + lived = 0; if (dnslib_zone_shallow_copy(zone, &zone) != DNSLIB_EBADARG) { diag("Calling zone_shallow_copy with identical source " "and destination zone did not return DNSLIB_EBADARG!"); errors++; } - + lived = 1; dnslib_zone_free(&zone); }, "zone: shallow copy NULL tests"); + errors += lived != 1; /* example.com. */ dnslib_zone_t *from = @@ -731,17 +735,17 @@ static int test_zone_shallow_copy() } -static int test_zone_free(dnslib_zone_t **zone) -{ - dnslib_zone_tree_apply_postorder(*zone, - test_zone_destroy_node_from_tree, - NULL); - dnslib_zone_nsec3_apply_postorder(*zone, - test_zone_destroy_node_from_tree, - NULL); - dnslib_zone_free(zone); - return (*zone == NULL); -} +//static int test_zone_free(dnslib_zone_t **zone) +//{ +// dnslib_zone_tree_apply_postorder(*zone, +// test_zone_destroy_node_from_tree, +// NULL); +// dnslib_zone_nsec3_apply_postorder(*zone, +// test_zone_destroy_node_from_tree, +// NULL); +// dnslib_zone_free(zone); +// return (*zone == NULL); +//} static const int DNSLIB_ZONE_TEST_COUNT = 10; diff --git a/src/dnslib/tests/realdata/dnslib/packet_tests_realdata.c b/src/dnslib/tests/realdata/dnslib/packet_tests_realdata.c index 7e00bcd74..1045990ae 100644 --- a/src/dnslib/tests/realdata/dnslib/packet_tests_realdata.c +++ b/src/dnslib/tests/realdata/dnslib/packet_tests_realdata.c @@ -9,7 +9,7 @@ /* *test_t structures */ #include "dnslib/tests/realdata/dnslib_tests_loader_realdata.h" #ifdef TEST_WITH_LDNS -#include "ldns/packet.h" +#include "ldns/ldns.h" #endif static int packet_tests_count(int argc, char *argv[]); diff --git a/src/dnslib/tests/realdata/dnslib/response_tests_realdata.c b/src/dnslib/tests/realdata/dnslib/response_tests_realdata.c index 594284845..fcd6038ab 100644 --- a/src/dnslib/tests/realdata/dnslib/response_tests_realdata.c +++ b/src/dnslib/tests/realdata/dnslib/response_tests_realdata.c @@ -190,132 +190,132 @@ static dnslib_dname_t *dname_from_test_dname(const test_dname_t *test_dname) NULL); } -static int check_response(dnslib_response_t *resp, test_response_t *test_resp, - int check_header, int check_question, - int check_answer, int check_additional, - int check_authority) -{ - int errors = 0; /* TODO maybe use it everywhere, or not use it at all */ - - if (check_question) { - /* again, in case of dnames, pointer would probably suffice */ - if (dnslib_dname_compare(resp->question.qname, - dname_from_test_dname(test_resp->qname)) != 0) { - char *tmp_dname; - tmp_dname = dnslib_dname_to_str(resp->question.qname); - diag("Qname in response is wrong:\ - should be: %s is: %s\n", - tmp_dname, test_resp->qname->str); - free(tmp_dname); - return 0; - } - - if (resp->question.qtype != test_resp->qtype) { - diag("Qtype value is wrong: is %u should be %u\n", - resp->question.qtype, test_resp->qtype); - return 0; - } - if (resp->question.qclass != test_resp->qclass) { - diag("Qclass value is wrong: is %u should be %u\n", - resp->question.qclass, test_resp->qclass); - return 0; - } - } - - if (check_header) { - /* Disabled, since these check make no sense - * if we have parsed the query, flags are now set to - * the ones response should have */ - - /* - if (resp->header.flags1 != test_resp->flags1) { - diag("Flags1 value is wrong: is %u should be %u\n", - resp->header.flags1, test_resp->flags1); - //return 0; - } - if (resp->header.flags2 != test_resp->flags2) { - diag("Flags2 value is wrong: is %u should be %u\n", - resp->header.flags2, test_resp->flags2); - return 0; - } - */ - - if (resp->header.qdcount != test_resp->qdcount) { - diag("Qdcount value is wrong: is %u should be %u\n", - resp->header.qdcount, test_resp->qdcount); - return 0; - } - if (resp->header.ancount != test_resp->ancount) { - diag("Ancount value is wrong: is %u should be %u\n", - resp->header.ancount, test_resp->ancount); - return 0; - } - if (resp->header.nscount != test_resp->nscount) { - diag("Nscount value is wrong: is %u should be %u\n", - resp->header.nscount, test_resp->nscount); - return 0; - } - if (resp->header.arcount != test_resp->arcount) { - diag("Arcount value is different: is %u should be %u\n", - resp->header.arcount, test_resp->arcount); +//static int check_response(dnslib_response_t *resp, test_response_t *test_resp, +// int check_header, int check_question, +// int check_answer, int check_additional, +// int check_authority) +//{ +// int errors = 0; /* TODO maybe use it everywhere, or not use it at all */ + +// if (check_question) { +// /* again, in case of dnames, pointer would probably suffice */ +// if (dnslib_dname_compare(resp->question.qname, +// dname_from_test_dname(test_resp->qname)) != 0) { +// char *tmp_dname; +// tmp_dname = dnslib_dname_to_str(resp->question.qname); +// diag("Qname in response is wrong: " +// "should be: %s is: %s\n", +// tmp_dname, test_resp->qname->str); +// free(tmp_dname); // return 0; - } - } - - if (check_question) { - /* Currently just one question RRSET allowed */ - if (dnslib_dname_compare(resp->question.qname, - dname_from_test_dname(test_resp->qname)) != 0) { - diag("Qname is wrongly set"); - errors++; - } - - if (resp->question.qtype != test_resp->qtype) { - diag("Qtype is wrongly set"); - errors++; - } +// } - if (resp->question.qclass != test_resp->qclass) { - diag("Qclass is wrongly set"); - errors++; - } +// if (resp->question.qtype != test_resp->qtype) { +// diag("Qtype value is wrong: is %u should be %u\n", +// resp->question.qtype, test_resp->qtype); +// return 0; +// } +// if (resp->question.qclass != test_resp->qclass) { +// diag("Qclass value is wrong: is %u should be %u\n", +// resp->question.qclass, test_resp->qclass); +// return 0; +// } +// } - } +// if (check_header) { +// /* Disabled, since these check make no sense +// * if we have parsed the query, flags are now set to +// * the ones response should have */ - /* Following code is not used anywhere currently. */ +// /* +// if (resp->header.flags1 != test_resp->flags1) { +// diag("Flags1 value is wrong: is %u should be %u\n", +// resp->header.flags1, test_resp->flags1); +// //return 0; +// } +// if (resp->header.flags2 != test_resp->flags2) { +// diag("Flags2 value is wrong: is %u should be %u\n", +// resp->header.flags2, test_resp->flags2); +// return 0; +// } +// */ -// if (check_authority) { -// for (int i = 0; (i < resp->header.arcount) && !errors; i++) { -// if (resp->authority[i] != (test_resp->authority[i])) { -// diag("Authority rrset #%d is wrongly set.\n", -// i); -// errors++; -// } +// if (resp->header.qdcount != test_resp->qdcount) { +// diag("Qdcount value is wrong: is %u should be %u\n", +// resp->header.qdcount, test_resp->qdcount); +// return 0; +// } +// if (resp->header.ancount != test_resp->ancount) { +// diag("Ancount value is wrong: is %u should be %u\n", +// resp->header.ancount, test_resp->ancount); +// return 0; +// } +// if (resp->header.nscount != test_resp->nscount) { +// diag("Nscount value is wrong: is %u should be %u\n", +// resp->header.nscount, test_resp->nscount); +// return 0; +// } +// if (resp->header.arcount != test_resp->arcount) { +// diag("Arcount value is different: is %u should be %u\n", +// resp->header.arcount, test_resp->arcount); +//// return 0; // } // } -// if (check_answer) { -// for (int i = 0; (i < resp->header.arcount) && !errors; i++) { -// if (resp->authority[i] != (test_resp->authority[i])) { -// diag("Authority rrset #%d is wrongly set.\n", -// i); -// errors++; -// } +// if (check_question) { +// /* Currently just one question RRSET allowed */ +// if (dnslib_dname_compare(resp->question.qname, +// dname_from_test_dname(test_resp->qname)) != 0) { +// diag("Qname is wrongly set"); +// errors++; // } -// } -// if (check_additional) { -// for (int i = 0; (i < resp->header.arcount) && !errors; i++) { -// if (resp->authority[i] != (test_resp->authority[i])) { -// diag("Authority rrset #%d is wrongly set.\n", -// i); -// errors++; -// } +// if (resp->question.qtype != test_resp->qtype) { +// diag("Qtype is wrongly set"); +// errors++; // } + +// if (resp->question.qclass != test_resp->qclass) { +// diag("Qclass is wrongly set"); +// errors++; +// } + // } - return (errors == 0); -} +// /* Following code is not used anywhere currently. */ + +//// if (check_authority) { +//// for (int i = 0; (i < resp->header.arcount) && !errors; i++) { +//// if (resp->authority[i] != (test_resp->authority[i])) { +//// diag("Authority rrset #%d is wrongly set.\n", +//// i); +//// errors++; +//// } +//// } +//// } + +//// if (check_answer) { +//// for (int i = 0; (i < resp->header.arcount) && !errors; i++) { +//// if (resp->authority[i] != (test_resp->authority[i])) { +//// diag("Authority rrset #%d is wrongly set.\n", +//// i); +//// errors++; +//// } +//// } +//// } + +//// if (check_additional) { +//// for (int i = 0; (i < resp->header.arcount) && !errors; i++) { +//// if (resp->authority[i] != (test_resp->authority[i])) { +//// diag("Authority rrset #%d is wrongly set.\n", +//// i); +//// errors++; +//// } +//// } +//// } + +// return (errors == 0); +//} //static int test_response_parse_query(list response_list, // test_raw_packet_t **raw_queries, diff --git a/src/dnslib/tests/realdata/dnslib_tests_loader_realdata.c b/src/dnslib/tests/realdata/dnslib_tests_loader_realdata.c index 9717056ff..c0759fabc 100644 --- a/src/dnslib/tests/realdata/dnslib_tests_loader_realdata.c +++ b/src/dnslib/tests/realdata/dnslib_tests_loader_realdata.c @@ -1132,7 +1132,7 @@ static int init_data(test_data_t *data) static void print_stats(test_data_t *data) { - uint resp_count = 0, dname_count = 0, edns_count = 0, node_count = 0, + uint resp_count = 0, dname_count = 0, node_count = 0, rdata_count = 0, rrset_count = 0, item_count = 0, query_count = 0, raw_query_count = 0, response_count = 0, packet_count = 0, raw_packet_count = 0, raw_response_count = 0; -- GitLab