mirror of https://github.com/getdnsapi/getdns.git
Add conversion functions test package
This commit is contained in:
parent
5ae854b8bf
commit
aadd4dc8bb
|
@ -0,0 +1,15 @@
|
|||
builddir = @BUILDDIR@
|
||||
testname = @TPKG_NAME@
|
||||
LIBTOOL = $(builddir)/libtool
|
||||
|
||||
CFLAGS=-I$(builddir)/src
|
||||
LDLIBS=$(builddir)/src/libgetdns.la
|
||||
|
||||
.SUFFIXES: .c .o .a .lo .h
|
||||
|
||||
.c.lo:
|
||||
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(testname): $(testname).lo
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDLIBS) $(LDFLAGS) -o $@ $<
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <getdns/getdns.h>
|
||||
#include <getdns/getdns_extra.h>
|
||||
|
||||
#define FAIL(...) do { \
|
||||
fprintf(stderr, "ERROR in %s:%d, ", __FILE__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
||||
#define FAIL_r(function_name) FAIL( "%s returned %d: %s", function_name \
|
||||
, (int)r, getdns_get_errorstr_by_id(r));
|
||||
|
||||
void print_dict(getdns_dict *rr_dict)
|
||||
{
|
||||
char *str = getdns_pretty_print_dict(rr_dict);
|
||||
printf("%s\n", str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
void print_wire(uint8_t *wire, size_t wire_len)
|
||||
{
|
||||
size_t pos, i;
|
||||
|
||||
for (pos = 0; pos < wire_len; pos += 16) {
|
||||
printf("%.4zx", pos);
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (i % 8 == 0)
|
||||
printf(" ");
|
||||
if (pos + i < wire_len)
|
||||
printf(" %.2x", (int)wire[pos + i]);
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf(" ");
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (i % 8 == 0)
|
||||
printf(" ");
|
||||
if (pos + i < wire_len && isprint(wire[pos + i]))
|
||||
printf("%c", wire[pos + i]);
|
||||
else
|
||||
printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
getdns_return_t r;
|
||||
getdns_dict *rr_dict;
|
||||
getdns_bindata *dns_name;
|
||||
getdns_bindata address = { 4, "\xb9\x31\x8d\x25" };
|
||||
getdns_bindata nothing = { 8, "\x07nothing" };
|
||||
char *str;
|
||||
uint8_t wire_buf[4096], *wire = wire_buf, *end_of_wire;
|
||||
size_t wire_len = sizeof(wire_buf);
|
||||
|
||||
if ((r = getdns_str2rr_dict(
|
||||
"some.domain.tld. 60 CH TXT \"first string\" second \"and third\"",
|
||||
&rr_dict, NULL, 3600)))
|
||||
FAIL_r("getdns_str2rr_dict");
|
||||
|
||||
print_dict(rr_dict);
|
||||
|
||||
if ((r = getdns_rr_dict2wire(rr_dict, wire, &wire_len)))
|
||||
FAIL_r("getdns_rr_dict2wire");
|
||||
|
||||
print_wire(wire, wire_len);
|
||||
|
||||
if ((r = getdns_dict_remove_name(rr_dict, "/rdata/rdata_raw")))
|
||||
FAIL_r("getdns_dict_remove_name");
|
||||
|
||||
print_dict(rr_dict);
|
||||
|
||||
if ((r = getdns_rr_dict2wire(rr_dict, wire, &wire_len)))
|
||||
FAIL_r("getdns_rr_dict2wire");
|
||||
|
||||
print_wire(wire, wire_len);
|
||||
|
||||
getdns_dict_destroy(rr_dict);
|
||||
|
||||
wire += wire_len;
|
||||
wire_len = sizeof(wire_buf) - (wire - wire_buf);
|
||||
|
||||
if (!(rr_dict = getdns_dict_create()))
|
||||
FAIL("getdns_dict_create returned NULL");
|
||||
|
||||
if ((r = getdns_convert_fqdn_to_dns_name("www.getdnsapi.net", &dns_name)))
|
||||
FAIL_r("getdns_convert_fqdn_to_dns_name");
|
||||
|
||||
r = getdns_dict_set_bindata(rr_dict, "name", dns_name);
|
||||
free(dns_name->data);
|
||||
free(dns_name);
|
||||
if (r)
|
||||
FAIL_r("getdns_dict_set_bindata");
|
||||
|
||||
if ((r = getdns_dict_set_int(rr_dict, "type", GETDNS_RRTYPE_A)))
|
||||
FAIL_r("getdns_dict_set_int");
|
||||
|
||||
if ((r = getdns_dict_set_bindata(rr_dict, "/rdata/ipv4_address", &address)))
|
||||
FAIL_r("getdns_dict_set_int");
|
||||
|
||||
if ((r = getdns_rr_dict2str(rr_dict, &str)))
|
||||
FAIL_r("getdns_rr_dict2str");
|
||||
|
||||
printf("\n%s\n", str);
|
||||
|
||||
if ((r = getdns_rr_dict2wire(rr_dict, wire, &wire_len)))
|
||||
FAIL_r("getdns_rr_dict2wire");
|
||||
|
||||
getdns_dict_destroy(rr_dict);
|
||||
print_wire(wire, wire_len);
|
||||
|
||||
wire += wire_len;
|
||||
wire_len = sizeof(wire_buf) - (wire - wire_buf);
|
||||
|
||||
/* Parse over wire data, convert to string via dict, and print */
|
||||
end_of_wire = wire;
|
||||
wire = wire_buf;
|
||||
wire_len = end_of_wire - wire;
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
BaseName: 260-conversion-functions
|
||||
Version: 1.0
|
||||
Description: Test json pointers
|
||||
CreationDate: vr dec 11 13:09:47 CET 2015
|
||||
Maintainer: Willem Toorop
|
||||
Category:
|
||||
Component:
|
||||
CmdDepends:
|
||||
Depends: 200-stub-only-compile.tpkg
|
||||
Help: 260-conversion-functions.help
|
||||
Pre: 260-conversion-functions.pre
|
||||
Post:
|
||||
Test: 260-conversion-functions.test
|
||||
AuxFiles:
|
||||
Passed:
|
||||
Failure:
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"class": GETDNS_RRCLASS_CH,
|
||||
"name": <bindata of "some.domain.tld.">,
|
||||
"rdata":
|
||||
{
|
||||
"rdata_raw": <bindata of 0x0c666972737420737472696e67067365...>,
|
||||
"txt_strings":
|
||||
[
|
||||
<bindata of "first string">,
|
||||
<bindata of "second">,
|
||||
<bindata of "and third">
|
||||
]
|
||||
},
|
||||
"ttl": 60,
|
||||
"type": GETDNS_RRTYPE_TXT
|
||||
}
|
||||
0000 04 73 6f 6d 65 06 64 6f 6d 61 69 6e 03 74 6c 64 .some.do main.tld
|
||||
0010 00 00 10 00 03 00 00 00 3c 00 1e 0c 66 69 72 73 ........ <...firs
|
||||
0020 74 20 73 74 72 69 6e 67 06 73 65 63 6f 6e 64 09 t string .second.
|
||||
0030 61 6e 64 20 74 68 69 72 64 and thir d.......
|
||||
{
|
||||
"class": GETDNS_RRCLASS_CH,
|
||||
"name": <bindata of "some.domain.tld.">,
|
||||
"rdata":
|
||||
{
|
||||
"txt_strings":
|
||||
[
|
||||
<bindata of "first string">,
|
||||
<bindata of "second">,
|
||||
<bindata of "and third">
|
||||
]
|
||||
},
|
||||
"ttl": 60,
|
||||
"type": GETDNS_RRTYPE_TXT
|
||||
}
|
||||
0000 04 73 6f 6d 65 06 64 6f 6d 61 69 6e 03 74 6c 64 .some.do main.tld
|
||||
0010 00 00 10 00 03 00 00 00 3c 00 1e 0c 66 69 72 73 ........ <...firs
|
||||
0020 74 20 73 74 72 69 6e 67 06 73 65 63 6f 6e 64 09 t string .second.
|
||||
0030 61 6e 64 20 74 68 69 72 64 and thir d.......
|
||||
|
||||
www.getdnsapi.net. 0 IN A 185.49.141.37
|
||||
|
||||
0000 03 77 77 77 09 67 65 74 64 6e 73 61 70 69 03 6e .www.get dnsapi.n
|
||||
0010 65 74 00 00 01 00 01 00 00 00 00 00 04 b9 31 8d et...... ......1.
|
||||
0020 25 %....... ........
|
|
@ -0,0 +1,2 @@
|
|||
Compile a program that setups a dict with json pointers and pretty prints the dict.
|
||||
Then compare the output to the known to be good output.
|
|
@ -0,0 +1,14 @@
|
|||
# #-- 260-conversion-functions.test --#
|
||||
# source the master var file when it's there
|
||||
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
|
||||
# use .tpkg.var.test for in test variable passing
|
||||
[ -f .tpkg.var.test ] && source .tpkg.var.test
|
||||
|
||||
(
|
||||
grep '^CC=' "${BUILDDIR}/build-stub-only/src/Makefile"
|
||||
grep '^LDFLAGS=' "${BUILDDIR}/build-stub-only/src/Makefile"
|
||||
|
||||
BUILDDIR4SED=`echo "${BUILDDIR}/build-stub-only" | sed 's/\//\\\\\//g'`
|
||||
sed -e "s/@BUILDDIR@/${BUILDDIR4SED}/g" \
|
||||
-e "s/@TPKG_NAME@/${TPKG_NAME}/g" "${TPKG_NAME}.Makefile"
|
||||
) > Makefile
|
|
@ -0,0 +1,7 @@
|
|||
# #-- 260-conversion-functions.test --#
|
||||
# source the master var file when it's there
|
||||
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
|
||||
# use .tpkg.var.test for in test variable passing
|
||||
[ -f .tpkg.var.test ] && source .tpkg.var.test
|
||||
|
||||
make && "./${TPKG_NAME}" | tee out && diff out "${TPKG_NAME}.good"
|
Loading…
Reference in New Issue