990920d0a94bed7a40c60c568b51754ac6abfdc3
[profile/ivi/GUPnP-AV.git] / tests / check-feature-list-parser.c
1 /*
2  * Copyright (C) 2012 Intel Corporation
3  *
4  * Authors: Regis Merlino <regis.merlino@intel.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-feature-list-parser.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 static const char * const names[] = {
27         "BOOKMARK",
28         "EPG",
29 };
30
31 static const char * const versions[] = {
32         "1",
33         "2",
34 };
35
36 static const char * const ids[] = {
37         "bookmark1,bookmark2,bookmark3",
38         "epg1,epg2",
39 };
40
41 static const char *text =
42         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
43         "<Features "
44                 "xmlns=\"urn:schemas-upnp-org:av:avs\" "
45                 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
46                 "xsi:schemaLocation=\""
47                 "urn:schemas-upnp-org:av:avs "
48                 "http://www.upnp.org/schemas/av/avs-v1-20060531.xsd\">"
49                 "<Feature name=\"BOOKMARK\" version=\"1\">"
50                         "<objectIDs>bookmark1</objectIDs>"
51                         "<objectIDs>bookmark2,bookmark3</objectIDs>"
52                 "</Feature>"
53                 "<Feature name=\"EPG\" version=\"2\">"
54                         "<objectIDs>epg1,epg2</objectIDs>"
55                 "</Feature>"
56         "</Features>";
57
58 static gboolean
59 check_feature (GUPnPFeature *feature)
60 {
61         static int index = 0;
62
63         if (strcmp (names[index], gupnp_feature_get_name (feature)))
64                         return FALSE;
65
66         if (strcmp (versions[index], gupnp_feature_get_version (feature)))
67                         return FALSE;
68
69         if (strcmp (ids[index], gupnp_feature_get_object_ids (feature)))
70                         return FALSE;
71
72         index++;
73
74         return TRUE;
75 }
76
77 int
78 main (int argc, char **argv)
79 {
80         GUPnPFeatureListParser *parser;
81         GError                 *error;
82         GList                  *features;
83         GList                  *item;
84         gboolean               success = TRUE;
85
86 #if !GLIB_CHECK_VERSION (2, 35, 0)
87         g_type_init ();
88 #endif
89
90         parser = gupnp_feature_list_parser_new ();
91
92         error = NULL;
93         features = gupnp_feature_list_parser_parse_text (parser, text, &error);
94         if (features == NULL) {
95                 g_printerr ("Parse error: %s\n", error->message);
96                 g_error_free (error);
97                 return EXIT_FAILURE;
98         }
99
100         for (item = features; item != NULL; item = g_list_next (item)) {
101                 success = check_feature ((GUPnPFeature *) item->data);
102                 if (!success)
103                         break;
104         }
105
106         g_print ("\n");
107
108         g_list_free_full (features, g_object_unref);
109         g_object_unref (parser);
110
111         return (success) ? EXIT_SUCCESS : EXIT_FAILURE;
112 }