1 /*
2 * Copyright (C) 2012 Intel Corporation
3 *
4 * Authors: Regis Merlino <regis.merlino@intel.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 *
8 */
9
10 #include <config.h>
11
12 #include <libgupnp-av/gupnp-feature-list-parser.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 static const char * const names[] = {
17 "BOOKMARK",
18 "EPG",
19 };
20
21 static const char * const versions[] = {
22 "1",
23 "2",
24 };
25
26 static const char * const ids[] = {
27 "bookmark1,bookmark2,bookmark3",
28 "epg1,epg2",
29 };
30
31 static const char *text =
32 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
33 "<Features "
34 "xmlns=\"urn:schemas-upnp-org:av:avs\" "
35 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
36 "xsi:schemaLocation=\""
37 "urn:schemas-upnp-org:av:avs "
38 "http://www.upnp.org/schemas/av/avs-v1-20060531.xsd\">"
39 "<Feature name=\"BOOKMARK\" version=\"1\">"
40 "<objectIDs>bookmark1</objectIDs>"
41 "<objectIDs>bookmark2,bookmark3</objectIDs>"
42 "</Feature>"
43 "<Feature name=\"EPG\" version=\"2\">"
44 "<objectIDs>epg1,epg2</objectIDs>"
45 "</Feature>"
46 "</Features>";
47
48 static gboolean
check_feature(GUPnPFeature * feature)49 check_feature (GUPnPFeature *feature)
50 {
51 static int index = 0;
52
53 if (strcmp (names[index], gupnp_feature_get_name (feature)))
54 return FALSE;
55
56 if (strcmp (versions[index], gupnp_feature_get_version (feature)))
57 return FALSE;
58
59 if (strcmp (ids[index], gupnp_feature_get_object_ids (feature)))
60 return FALSE;
61
62 index++;
63
64 return TRUE;
65 }
66
67 int
main(G_GNUC_UNUSED int argc,G_GNUC_UNUSED char ** argv)68 main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
69 {
70 GUPnPFeatureListParser *parser;
71 GError *error;
72 GList *features;
73 GList *item;
74 gboolean success = TRUE;
75
76 parser = gupnp_feature_list_parser_new ();
77
78 error = NULL;
79 features = gupnp_feature_list_parser_parse_text (parser, text, &error);
80 if (features == NULL) {
81 g_printerr ("Parse error: %s\n", error->message);
82 g_error_free (error);
83 return EXIT_FAILURE;
84 }
85
86 for (item = features; item != NULL; item = g_list_next (item)) {
87 success = check_feature ((GUPnPFeature *) item->data);
88 if (!success)
89 break;
90 }
91
92 g_print ("\n");
93
94 g_list_free_full (features, g_object_unref);
95 g_object_unref (parser);
96
97 return (success) ? EXIT_SUCCESS : EXIT_FAILURE;
98 }
99