From: Wouter Wijngaards Date: Mon, 7 May 2007 14:22:30 +0000 (+0000) Subject: unit test upgrade. X-Git-Tag: release-0.3~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efd5b66026c733c6d27eb921bfde4658ab0a1f5b;p=thirdparty%2Funbound.git unit test upgrade. git-svn-id: file:///svn/unbound/trunk@292 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/testcode/unitmsgparse.c b/testcode/unitmsgparse.c index 0af2c1acb..9f2bfb5b4 100644 --- a/testcode/unitmsgparse.c +++ b/testcode/unitmsgparse.c @@ -267,6 +267,7 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out, checkformerr(pkt); unit_assert(ret != LDNS_RCODE_SERVFAIL); } else { + const size_t lim = 512; ret = reply_info_encode(&qi, rep, id, flags, out, timenow, region, 65535); unit_assert(ret != 0); /* udp packets should fit */ @@ -275,6 +276,24 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out, (unsigned)ldns_buffer_limit(pkt), (unsigned)ldns_buffer_limit(out)); test_buffers(pkt, out); + + if(ldns_buffer_limit(out) > lim) { + ret = reply_info_encode(&qi, rep, id, flags, out, + timenow, region, + lim - calc_edns_field_size(&edns)); + unit_assert(ret != 0); /* should fit, but with TC */ + attach_edns_record(out, &edns); + if( LDNS_QDCOUNT(ldns_buffer_begin(out)) != + LDNS_QDCOUNT(ldns_buffer_begin(pkt)) || + LDNS_ANCOUNT(ldns_buffer_begin(out)) != + LDNS_ANCOUNT(ldns_buffer_begin(pkt)) || + LDNS_NSCOUNT(ldns_buffer_begin(out)) != + LDNS_NSCOUNT(ldns_buffer_begin(pkt))) + unit_assert( + LDNS_TC_WIRE(ldns_buffer_begin(out))); + /* must set TC bit if shortened */ + unit_assert(ldns_buffer_limit(out) <= lim); + } } query_info_clear(&qi); diff --git a/util/data/msgreply.c b/util/data/msgreply.c index cad215dac..7c09f89ab 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -1066,8 +1066,7 @@ int reply_info_encode(struct query_info* qinfo, struct reply_info* rep, return 1; } -/** estimate size of EDNS field in packet */ -static uint16_t +uint16_t calc_edns_field_size(struct edns_data* edns) { if(!edns || !edns->edns_present) diff --git a/util/data/msgreply.h b/util/data/msgreply.h index 0abb62573..d8e6c94de 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -298,6 +298,13 @@ int reply_info_encode(struct query_info* qinfo, struct reply_info* rep, struct msgreply_entry* query_info_entrysetup(struct query_info* q, struct reply_info* r, hashvalue_t h); +/** + * Estimate size of EDNS record in packet. EDNS record will be no larger. + * @param edns: edns data or NULL. + * @return octets to reserve for EDNS. + */ +uint16_t calc_edns_field_size(struct edns_data* edns); + /** * Attach EDNS record to buffer. Buffer has complete packet. There must * be enough room left for the EDNS record.