Updated GUPnP-AV to version 11.7 (a48bbd0)
[profile/ivi/GUPnP-AV.git] / tests / test-search-criteria-parser.c
1 /*
2  * Copyright (C) 2008 OpenedHand Ltd.
3  *
4  * Authors: Jorn Baayen <jorn@openedhand.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include <libgupnp-av/gupnp-search-criteria-parser.h>
23 #include <stdlib.h>
24
25 static void
26 begin_parens_cb (GUPnPSearchCriteriaParser *parser,
27                  gpointer                   user_data)
28 {
29         g_print ("(");
30 }
31
32 static void
33 end_parens_cb (GUPnPSearchCriteriaParser *parser,
34                gpointer                   user_data)
35 {
36         g_print (")");
37 }
38
39 static void
40 conjunction_cb (GUPnPSearchCriteriaParser *parser,
41                 gpointer                   user_data)
42 {
43         g_print (" and ");
44 }
45
46 static void
47 disjunction_cb (GUPnPSearchCriteriaParser *parser,
48                 gpointer                   user_data)
49 {
50         g_print (" or ");
51 }
52
53 static gboolean
54 expression_cb (GUPnPSearchCriteriaParser *parser,
55                const char                *property,
56                GUPnPSearchCriteriaOp      op,
57                const char                *value,
58                GError                   **error,
59                gpointer                   user_data)
60 {
61         g_print ("%s %d %s", property, op, value);
62
63         return TRUE;
64 }
65
66 int
67 main (int argc, char **argv)
68 {
69         GUPnPSearchCriteriaParser *parser;
70         GError *error;
71
72         g_assert (argc == 2);
73
74 #if !GLIB_CHECK_VERSION (2, 35, 0)
75         g_type_init ();
76 #endif
77
78         parser = gupnp_search_criteria_parser_new ();
79
80         g_signal_connect (parser,
81                           "begin_parens",
82                           G_CALLBACK (begin_parens_cb),
83                           NULL);
84         g_signal_connect (parser,
85                           "end_parens",
86                           G_CALLBACK (end_parens_cb),
87                           NULL);
88         g_signal_connect (parser,
89                           "conjunction",
90                           G_CALLBACK (conjunction_cb),
91                           NULL);
92         g_signal_connect (parser,
93                           "disjunction",
94                           G_CALLBACK (disjunction_cb),
95                           NULL);
96         g_signal_connect (parser,
97                           "expression",
98                           G_CALLBACK (expression_cb),
99                           NULL);
100
101         error = NULL;
102         gupnp_search_criteria_parser_parse_text (parser, argv[1], &error);
103         if (error != NULL) {
104                 g_printerr ("Parse error: %s\n", error->message);
105                 g_error_free (error);
106                 return EXIT_FAILURE;
107         }
108
109         g_print ("\n");
110
111         g_object_unref (parser);
112
113         return EXIT_SUCCESS;
114 }