Blame tests/check-feature-list-parser.c

Packit 712bc5
/*
Packit 712bc5
 * Copyright (C) 2012 Intel Corporation
Packit 712bc5
 *
Packit 712bc5
 * Authors: Regis Merlino <regis.merlino@intel.com>
Packit 712bc5
 *
Packit 712bc5
 * This library is free software; you can redistribute it and/or
Packit 712bc5
 * modify it under the terms of the GNU Library General Public
Packit 712bc5
 * License as published by the Free Software Foundation; either
Packit 712bc5
 * version 2 of the License, or (at your option) any later version.
Packit 712bc5
 *
Packit 712bc5
 * This library is distributed in the hope that it will be useful,
Packit 712bc5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 712bc5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 712bc5
 * Library General Public License for more details.
Packit 712bc5
 *
Packit 712bc5
 * You should have received a copy of the GNU Library General Public
Packit 712bc5
 * License along with this library; if not, write to the
Packit 712bc5
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit 712bc5
 * Boston, MA 02110-1301, USA.
Packit 712bc5
 */
Packit 712bc5
Packit 712bc5
#include <libgupnp-av/gupnp-feature-list-parser.h>
Packit 712bc5
#include <stdlib.h>
Packit 712bc5
#include <string.h>
Packit 712bc5
Packit 712bc5
static const char * const names[] = {
Packit 712bc5
        "BOOKMARK",
Packit 712bc5
        "EPG",
Packit 712bc5
};
Packit 712bc5
Packit 712bc5
static const char * const versions[] = {
Packit 712bc5
        "1",
Packit 712bc5
        "2",
Packit 712bc5
};
Packit 712bc5
Packit 712bc5
static const char * const ids[] = {
Packit 712bc5
        "bookmark1,bookmark2,bookmark3",
Packit 712bc5
        "epg1,epg2",
Packit 712bc5
};
Packit 712bc5
Packit 712bc5
static const char *text =
Packit 712bc5
        ""
Packit 712bc5
        "
Packit 712bc5
                "xmlns=\"urn:schemas-upnp-org:av:avs\" "
Packit 712bc5
                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
Packit 712bc5
                "xsi:schemaLocation=\""
Packit 712bc5
                "urn:schemas-upnp-org:av:avs "
Packit 712bc5
                "http://www.upnp.org/schemas/av/avs-v1-20060531.xsd\">"
Packit 712bc5
                "<Feature name=\"BOOKMARK\" version=\"1\">"
Packit 712bc5
                        "<objectIDs>bookmark1</objectIDs>"
Packit 712bc5
                        "<objectIDs>bookmark2,bookmark3</objectIDs>"
Packit 712bc5
                "</Feature>"
Packit 712bc5
                "<Feature name=\"EPG\" version=\"2\">"
Packit 712bc5
                        "<objectIDs>epg1,epg2</objectIDs>"
Packit 712bc5
                "</Feature>"
Packit 712bc5
        "</Features>";
Packit 712bc5
Packit 712bc5
static gboolean
Packit 712bc5
check_feature (GUPnPFeature *feature)
Packit 712bc5
{
Packit 712bc5
        static int index = 0;
Packit 712bc5
Packit 712bc5
        if (strcmp (names[index], gupnp_feature_get_name (feature)))
Packit 712bc5
                        return FALSE;
Packit 712bc5
Packit 712bc5
        if (strcmp (versions[index], gupnp_feature_get_version (feature)))
Packit 712bc5
                        return FALSE;
Packit 712bc5
Packit 712bc5
        if (strcmp (ids[index], gupnp_feature_get_object_ids (feature)))
Packit 712bc5
                        return FALSE;
Packit 712bc5
Packit 712bc5
        index++;
Packit 712bc5
Packit 712bc5
        return TRUE;
Packit 712bc5
}
Packit 712bc5
Packit 712bc5
int
Packit 712bc5
main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
Packit 712bc5
{
Packit 712bc5
        GUPnPFeatureListParser *parser;
Packit 712bc5
        GError                 *error;
Packit 712bc5
        GList                  *features;
Packit 712bc5
        GList                  *item;
Packit 712bc5
        gboolean               success = TRUE;
Packit 712bc5
Packit 712bc5
#if !GLIB_CHECK_VERSION (2, 35, 0)
Packit 712bc5
        g_type_init ();
Packit 712bc5
#endif
Packit 712bc5
Packit 712bc5
        parser = gupnp_feature_list_parser_new ();
Packit 712bc5
Packit 712bc5
        error = NULL;
Packit 712bc5
        features = gupnp_feature_list_parser_parse_text (parser, text, &error);
Packit 712bc5
        if (features == NULL) {
Packit 712bc5
                g_printerr ("Parse error: %s\n", error->message);
Packit 712bc5
                g_error_free (error);
Packit 712bc5
                return EXIT_FAILURE;
Packit 712bc5
        }
Packit 712bc5
Packit 712bc5
        for (item = features; item != NULL; item = g_list_next (item)) {
Packit 712bc5
                success = check_feature ((GUPnPFeature *) item->data);
Packit 712bc5
                if (!success)
Packit 712bc5
                        break;
Packit 712bc5
        }
Packit 712bc5
Packit 712bc5
        g_print ("\n");
Packit 712bc5
Packit 712bc5
        g_list_free_full (features, g_object_unref);
Packit 712bc5
        g_object_unref (parser);
Packit 712bc5
Packit 712bc5
        return (success) ? EXIT_SUCCESS : EXIT_FAILURE;
Packit 712bc5
}