summaryrefslogtreecommitdiff
path: root/tests/test-search-criteria-parser.c
blob: eabcd34992d44b1822c9364db06038ae9ceffcf1 (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
/*
 * Copyright (C) 2008 OpenedHand Ltd.
 *
 * Authors: Jorn Baayen <jorn@openedhand.com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 */

#include <config.h>

#include <libgupnp-av/gupnp-search-criteria-parser.h>
#include <stdlib.h>

static void
begin_parens_cb (G_GNUC_UNUSED GUPnPSearchCriteriaParser *parser,
                 G_GNUC_UNUSED gpointer                   user_data)
{
        g_print ("(");
}

static void
end_parens_cb (G_GNUC_UNUSED GUPnPSearchCriteriaParser *parser,
               G_GNUC_UNUSED gpointer                   user_data)
{
        g_print (")");
}

static void
conjunction_cb (G_GNUC_UNUSED GUPnPSearchCriteriaParser *parser,
                G_GNUC_UNUSED gpointer                   user_data)
{
        g_print (" and ");
}

static void
disjunction_cb (G_GNUC_UNUSED GUPnPSearchCriteriaParser *parser,
                G_GNUC_UNUSED gpointer                   user_data)
{
        g_print (" or ");
}

static gboolean
expression_cb (G_GNUC_UNUSED GUPnPSearchCriteriaParser *parser,
               const char                              *property,
               GUPnPSearchCriteriaOp                    op,
               const char                              *value,
               G_GNUC_UNUSED GError                   **error,
               G_GNUC_UNUSED gpointer                   user_data)
{
        g_print ("%s %d %s", property, op, value);

        return TRUE;
}

int
main (int argc, char **argv)
{
        GUPnPSearchCriteriaParser *parser;
        GError *error;

        g_assert (argc == 2);

        parser = gupnp_search_criteria_parser_new ();

        g_signal_connect (parser,
                          "begin_parens",
                          G_CALLBACK (begin_parens_cb),
                          NULL);
        g_signal_connect (parser,
                          "end_parens",
                          G_CALLBACK (end_parens_cb),
                          NULL);
        g_signal_connect (parser,
                          "conjunction",
                          G_CALLBACK (conjunction_cb),
                          NULL);
        g_signal_connect (parser,
                          "disjunction",
                          G_CALLBACK (disjunction_cb),
                          NULL);
        g_signal_connect (parser,
                          "expression",
                          G_CALLBACK (expression_cb),
                          NULL);

        error = NULL;
        gupnp_search_criteria_parser_parse_text (parser, argv[1], &error);
        if (error != NULL) {
                g_printerr ("Parse error: %s\n", error->message);
                g_error_free (error);
                return EXIT_FAILURE;
        }

        g_print ("\n");

        g_object_unref (parser);

        return EXIT_SUCCESS;
}