summaryrefslogtreecommitdiff
path: root/lib/gibber/tests/test-resolver.c
blob: bb6ab8d734156b2150d8675a7178f224066f6d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * test-resolver.c - Source for TestResolver
 * Copyright (C) 2008 Collabora Ltd.
 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */


#include <stdio.h>
#include <stdlib.h>

#include "test-resolver.h"

G_DEFINE_TYPE(TestResolver, test_resolver, GIBBER_TYPE_RESOLVER)

/* private structure */
typedef struct _TestResolverPrivate TestResolverPrivate;

struct _TestResolverPrivate
{
  gboolean dispose_has_run;
};

#define TEST_RESOLVER_GET_PRIVATE(o)  \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_RESOLVER, TestResolverPrivate))

static void
test_resolver_init (TestResolver *obj)
{
}

static void test_resolver_dispose (GObject *object);
static void test_resolver_finalize (GObject *object);

static gboolean test_resolv_srv (GibberResolver *resolver, guint id,
  const gchar *service_name, const char *service,
  GibberResolverServiceType type);

static void
test_resolver_class_init (TestResolverClass *test_resolver_class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (test_resolver_class);
  GibberResolverClass *resolver_class = GIBBER_RESOLVER_CLASS
    (test_resolver_class);

  g_type_class_add_private (test_resolver_class, sizeof (TestResolverPrivate));

  object_class->dispose = test_resolver_dispose;
  object_class->finalize = test_resolver_finalize;

  resolver_class->resolv_srv = test_resolv_srv;
}

void
test_resolver_dispose (GObject *object)
{
  TestResolver *self = TEST_RESOLVER (object);
  TestResolverPrivate *priv = TEST_RESOLVER_GET_PRIVATE (self);

  if (priv->dispose_has_run)
    return;

  priv->dispose_has_run = TRUE;

  /* release any references held by the object here */

  if (G_OBJECT_CLASS (test_resolver_parent_class)->dispose)
    G_OBJECT_CLASS (test_resolver_parent_class)->dispose (object);
}

void
test_resolver_finalize (GObject *object)
{
  G_OBJECT_CLASS (test_resolver_parent_class)->finalize (object);
}


static gboolean test_resolv_srv (GibberResolver *resolver, guint id,
  const gchar *service_name, const char *service,
  GibberResolverServiceType type)
{
  GList *entries = NULL;
  int i;

  for (i = 0 ; i < 20 ; i++)
    {
      gchar *str;

      str = g_strdup_printf ("test%2d.example.com", i);

      entries = g_list_prepend (entries,
        gibber_resolver_srv_record_new (str, 1234,
          10 - (i / 5) , 4 - i % 5));

      g_free (str);
    }

  gibber_resolver_srv_result (resolver, id, entries, NULL);
  return FALSE;
}