diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-07 11:36:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-07 11:36:06 +0000 |
commit | c2b7de53b4ea53e1c82b529e24ab80d9489743e7 (patch) | |
tree | 1f34d751095bca308d1b22e2d6b2ea5df75a2f0d /src/dns | |
parent | 00cad61e45eb0b5ace71795d370b194317c99eee (diff) | |
download | gnunet-c2b7de53b4ea53e1c82b529e24ab80d9489743e7.tar.gz gnunet-c2b7de53b4ea53e1c82b529e24ab80d9489743e7.zip |
-testcase and bugfix for hexcoder
Diffstat (limited to 'src/dns')
-rw-r--r-- | src/dns/Makefile.am | 24 | ||||
-rw-r--r-- | src/dns/dnsparser.c | 2 | ||||
-rw-r--r-- | src/dns/test_hexcoder.c | 56 |
3 files changed, 76 insertions, 6 deletions
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am index 0ef1623f9..f8645305d 100644 --- a/src/dns/Makefile.am +++ b/src/dns/Makefile.am | |||
@@ -37,13 +37,16 @@ noinst_PROGRAMS = \ | |||
37 | gnunet-dns-monitor gnunet-dns-redirector | 37 | gnunet-dns-monitor gnunet-dns-redirector |
38 | 38 | ||
39 | plugin_LTLIBRARIES = \ | 39 | plugin_LTLIBRARIES = \ |
40 | libgnunet_plugin_block_dns.la | 40 | libgnunet_plugin_block_dns.la |
41 | 41 | ||
42 | if LINUX | 42 | if LINUX |
43 | check_SCRIPTS = \ | 43 | check_SCRIPTS = \ |
44 | test_gnunet_dns.sh | 44 | test_gnunet_dns.sh |
45 | endif | 45 | endif |
46 | 46 | ||
47 | check_PROGRAMS = \ | ||
48 | test_hexcoder | ||
49 | |||
47 | gnunet_helper_dns_SOURCES = \ | 50 | gnunet_helper_dns_SOURCES = \ |
48 | gnunet-helper-dns.c | 51 | gnunet-helper-dns.c |
49 | 52 | ||
@@ -71,7 +74,7 @@ gnunet_dns_redirector_DEPENDENCIES = \ | |||
71 | libgnunetdns.la | 74 | libgnunetdns.la |
72 | 75 | ||
73 | gnunet_service_dns_SOURCES = \ | 76 | gnunet_service_dns_SOURCES = \ |
74 | gnunet-service-dns.c | 77 | gnunet-service-dns.c |
75 | gnunet_service_dns_LDADD = \ | 78 | gnunet_service_dns_LDADD = \ |
76 | $(top_builddir)/src/dns/libgnunetdnsstub.la \ | 79 | $(top_builddir)/src/dns/libgnunetdnsstub.la \ |
77 | $(top_builddir)/src/tun/libgnunettun.la \ | 80 | $(top_builddir)/src/tun/libgnunettun.la \ |
@@ -82,7 +85,7 @@ gnunet_service_dns_DEPENDENCIES = \ | |||
82 | libgnunetdnsstub.la | 85 | libgnunetdnsstub.la |
83 | 86 | ||
84 | libgnunetdnsparser_la_SOURCES = \ | 87 | libgnunetdnsparser_la_SOURCES = \ |
85 | dnsparser.c | 88 | dnsparser.c |
86 | libgnunetdnsparser_la_LIBADD = \ | 89 | libgnunetdnsparser_la_LIBADD = \ |
87 | $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \ | 90 | $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \ |
88 | -lidn | 91 | -lidn |
@@ -91,7 +94,7 @@ libgnunetdnsparser_la_LDFLAGS = \ | |||
91 | -version-info 1:0:1 | 94 | -version-info 1:0:1 |
92 | 95 | ||
93 | libgnunetdnsstub_la_SOURCES = \ | 96 | libgnunetdnsstub_la_SOURCES = \ |
94 | dnsstub.c | 97 | dnsstub.c |
95 | libgnunetdnsstub_la_LIBADD = \ | 98 | libgnunetdnsstub_la_LIBADD = \ |
96 | $(top_builddir)/src/util/libgnunetutil.la $(XLIB) | 99 | $(top_builddir)/src/util/libgnunetutil.la $(XLIB) |
97 | libgnunetdnsstub_la_LDFLAGS = \ | 100 | libgnunetdnsstub_la_LDFLAGS = \ |
@@ -120,4 +123,15 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS) | |||
120 | endif | 123 | endif |
121 | 124 | ||
122 | EXTRA_DIST = \ | 125 | EXTRA_DIST = \ |
123 | $(check_SCRIPTS) | 126 | $(check_SCRIPTS) |
127 | |||
128 | |||
129 | test_hexcoder_SOURCES = \ | ||
130 | test_hexcoder.c | ||
131 | test_hexcoder_LDADD = \ | ||
132 | libgnunetdnsparser.la \ | ||
133 | $(top_builddir)/src/util/libgnunetutil.la | ||
134 | test_hexcoder_DEPENDENCIES = \ | ||
135 | libgnunetdnsparser.la \ | ||
136 | $(top_builddir)/src/util/libgnunetutil.la | ||
137 | |||
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c index 2be34fc15..11f27a244 100644 --- a/src/dns/dnsparser.c +++ b/src/dns/dnsparser.c | |||
@@ -1249,7 +1249,7 @@ GNUNET_DNSPARSER_bin_to_hex (const void *data, | |||
1249 | ret = GNUNET_malloc (data_size * 2 + 1); | 1249 | ret = GNUNET_malloc (data_size * 2 + 1); |
1250 | for (off = 0; off < data_size; off++) | 1250 | for (off = 0; off < data_size; off++) |
1251 | sprintf (&ret[off * 2], | 1251 | sprintf (&ret[off * 2], |
1252 | "%x", | 1252 | "%02x", |
1253 | idata[off]); | 1253 | idata[off]); |
1254 | return ret; | 1254 | return ret; |
1255 | } | 1255 | } |
diff --git a/src/dns/test_hexcoder.c b/src/dns/test_hexcoder.c new file mode 100644 index 000000000..5c1191a3c --- /dev/null +++ b/src/dns/test_hexcoder.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | |||
20 | */ | ||
21 | /** | ||
22 | * @author Christian Grothoff | ||
23 | * @file dns/test_hexcoder.c | ||
24 | * @brief test for #GNUNET_DNSPARSER_hex_to_bin() and | ||
25 | * #GNUNET_DNSPARSER_bin_to_hex() | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_dnsparser_lib.h" | ||
30 | |||
31 | #define TESTSTRING "Hello World!" | ||
32 | |||
33 | |||
34 | int | ||
35 | main (int argc, | ||
36 | char *argv[]) | ||
37 | { | ||
38 | char buf[strlen (TESTSTRING) + 1]; | ||
39 | char *ret; | ||
40 | |||
41 | GNUNET_log_setup ("test-hexcoder", "WARNING", NULL); | ||
42 | ret = GNUNET_DNSPARSER_bin_to_hex (TESTSTRING, | ||
43 | strlen (TESTSTRING) + 1); | ||
44 | GNUNET_assert (NULL != ret); | ||
45 | GNUNET_assert (sizeof (buf) == | ||
46 | GNUNET_DNSPARSER_hex_to_bin (ret, | ||
47 | buf)); | ||
48 | GNUNET_assert (0 == memcmp (TESTSTRING, | ||
49 | buf, | ||
50 | sizeof (buf))); | ||
51 | GNUNET_free (ret); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | |||
56 | /* end of test_hexcoder.c */ | ||