File: test-dispatcher-reset.c

package info (click to toggle)
libepc 0.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 3,420 kB
  • sloc: ansic: 8,574; sh: 4,257; makefile: 253
file content (90 lines) | stat: -rw-r--r-- 2,833 bytes parent folder | download
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
/* Easy Publish and Consume Library
 * Copyright (C) 2007, 2008  Openismus GmbH
 *
 * 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
 *
 * Authors:
 *      Mathias Hasselmann
 */

/* Test that epc_dispatcher_reset removes services */

#include "framework.h"
#include "libepc/dispatcher.h"

static gchar *test_type = NULL;
static gchar *test_name = NULL;

static void
service_browser_cb (AvahiServiceBrowser     *browser G_GNUC_UNUSED,
                    AvahiIfIndex             interface,
                    AvahiProtocol            protocol G_GNUC_UNUSED,
                    AvahiBrowserEvent        event,
                    const char              *name,
                    const char              *type,
                    const char              *domain G_GNUC_UNUSED,
                    AvahiLookupResultFlags   flags G_GNUC_UNUSED,
                    void                    *data)
{
  EpcDispatcher *dispatcher = data;

  if (name && g_str_equal (name, test_name) &&
      type && g_str_equal (type, test_type))
    {
      if (AVAHI_BROWSER_NEW == event)
        {
          epc_test_pass_once_per_iface (1, interface);
          epc_dispatcher_reset (dispatcher);
        }

      if (AVAHI_BROWSER_REMOVE == event)
        epc_test_pass_once_per_iface (2, interface);
    }
}

int
main (void)
{
  EpcDispatcher *dispatcher = NULL;
  gint result = EPC_TEST_MASK_ALL;
  GError *error = NULL;

  test_name = g_strdup_printf ("%s: %08x", __FILE__, g_random_int ());
  test_type = g_strdup_printf ("_test-%08x._tcp", g_random_int ());

  dispatcher = epc_dispatcher_new (test_name);

  if (epc_test_init (2) &&
      epc_test_init_service_browser (test_type, service_browser_cb, dispatcher) &&
      epc_dispatcher_run (dispatcher, &error))
    {
      epc_dispatcher_add_service (dispatcher, EPC_ADDRESS_UNSPEC,
                                  test_type, NULL, NULL, 2007, NULL);
      result = epc_test_run ();
    }

  if (error)
    g_print ("%s: %s\n", G_STRLOC, error->message);

  g_clear_error (&error);

  if (dispatcher)
    g_object_unref (dispatcher);

  g_free (test_type);
  g_free (test_name);

  return result;
}