summaryrefslogtreecommitdiff
path: root/tests/newdns-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/newdns-test.c')
-rw-r--r--tests/newdns-test.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/newdns-test.c b/tests/newdns-test.c
new file mode 100644
index 0000000..db02abe
--- /dev/null
+++ b/tests/newdns-test.c
@@ -0,0 +1,117 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
+
+/* Lac - Library for asynchronous communication
+ * Copyright (C) 2002 Søren Sandmann (sandmann@daimi.au.dk)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <lac.h>
+#include <string.h>
+
+static int n_outstanding;
+static GMainLoop *main_loop;
+
+static void
+name_callback (const gchar *name, gpointer data, const GError *err)
+{
+ gchar *addr_str = data;
+
+ if (err)
+ {
+ g_print ("reverse %s: %s\n", addr_str, err->message);
+ }
+ else
+ {
+ g_print ("reverse %s: %s\n", addr_str, name);
+ }
+ g_free (addr_str);
+}
+
+static void
+callback (const GPtrArray *addresses, gpointer data, const GError *err)
+{
+ gchar *name = data;
+
+ if (err)
+ {
+ g_print ("%s: %s\n", name, err->message);
+ }
+ else
+ {
+ int i;
+
+ if (addresses->len == 0)
+ g_print ("this should not happen\n");
+ for (i = 0; i < addresses->len; ++i)
+ {
+ gchar *addr = lac_address_to_str (addresses->pdata[i]);
+ g_print ("%s: %s\n", name, addr);
+
+ lac_dns_get_name (addresses->pdata[i], name_callback, addr);
+ }
+
+ }
+
+ if (!strstr (name, "again"))
+ {
+ gchar *tmp;
+
+ n_outstanding += 2;
+ lac_dns_get_addresses (name, callback, g_strdup_printf ("%s again", name));
+
+ tmp = g_ascii_strup (name, -1);
+ lac_dns_get_addresses (tmp, callback, g_strdup_printf ("%s (UPPER) again", name));
+ g_free (tmp);
+ }
+
+ if (--n_outstanding == 0)
+ g_main_quit (main_loop);
+ g_free (name);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int i;
+
+ main_loop = g_main_loop_new (NULL, TRUE);
+ g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR |
+ G_LOG_LEVEL_CRITICAL);
+
+ lac_set_verbose (TRUE);
+
+ if (argc > 1)
+ {
+ for (i = 1; i < argc; ++i)
+ {
+ ++n_outstanding;
+ lac_dns_get_addresses (argv[i], callback, g_strdup (argv[i]));
+ }
+ }
+ else
+ {
+ g_print ("usage %s <names>\n", argv[0]);
+ return 1;
+ }
+
+ g_assert (main_loop);
+#if 0
+ g_timeout_add (200, g_main_loop_quit, main_loop);
+#endif
+ g_main_loop_run (main_loop);
+
+ return 0;
+}