|
Packit |
712bc5 |
/*
|
|
Packit |
712bc5 |
* Copyright (C) 2012 Intel Corporation.
|
|
Packit |
712bc5 |
* Copyright (C) 2013 Jens Georg <mail@jensge.org>
|
|
Packit |
712bc5 |
*
|
|
Packit |
712bc5 |
* Author: Jens Georg <jensg@openismus.com>
|
|
Packit |
712bc5 |
* Jens Georg <mail@jensge.org>
|
|
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 <string.h>
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#include <libgupnp-av/gupnp-media-collection.h>
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Flat DIDL_S playlist */
|
|
Packit |
712bc5 |
#define TEST_PARSE_COLLECTION_1 \
|
|
Packit |
712bc5 |
"" \
|
|
Packit |
712bc5 |
"
|
|
Packit |
712bc5 |
" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" \
|
|
Packit |
712bc5 |
" xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"" \
|
|
Packit |
712bc5 |
" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"" \
|
|
Packit |
712bc5 |
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" \
|
|
Packit |
712bc5 |
" xsi:schemaLocation=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" \
|
|
Packit |
712bc5 |
" http://www.upnp.org/schemas/av/didl-lite-v2-20060531.xsd" \
|
|
Packit |
712bc5 |
" urn:schemas-upnp-org:metadata-1-0/upnp/" \
|
|
Packit |
712bc5 |
" http://www.upnp.org/schemas/av/upnp-v2-20060531.xsd\">" \
|
|
Packit |
712bc5 |
" <item id=\"\" parentID=\"0\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>Song1</dc:title>" \
|
|
Packit |
712bc5 |
" <upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
" <res protocolInfo=\"*:*:*:*\" />" \
|
|
Packit |
712bc5 |
" <upnp:artist></upnp:artist>" \
|
|
Packit |
712bc5 |
" </item>" \
|
|
Packit |
712bc5 |
" <item id=\"\" parentID=\"0\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>Song2</dc:title>" \
|
|
Packit |
712bc5 |
" <upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
" <res protocolInfo=\"*:*:*:*\" />" \
|
|
Packit |
712bc5 |
" </item>" \
|
|
Packit |
712bc5 |
" <item id=\"\" parentID=\"0\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>Song3</dc:title>" \
|
|
Packit |
712bc5 |
" <upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
" <res protocolInfo=\"*:*:*:*\" />" \
|
|
Packit |
712bc5 |
" </item>" \
|
|
Packit |
712bc5 |
"</DIDL-Lite>"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Nested DIDL_S playlist */
|
|
Packit |
712bc5 |
#define TEST_PARSE_COLLECTION_2 \
|
|
Packit |
712bc5 |
"" \
|
|
Packit |
712bc5 |
"
|
|
Packit |
712bc5 |
" xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"" \
|
|
Packit |
712bc5 |
" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" \
|
|
Packit |
712bc5 |
" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"" \
|
|
Packit |
712bc5 |
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" \
|
|
Packit |
712bc5 |
" xsi:schemaLocation=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" \
|
|
Packit |
712bc5 |
" http://www.upnp.org/schemas/av/didl-lite-v2-20060531.xsd" \
|
|
Packit |
712bc5 |
" urn:schemas-upnp-org:metadata-1-0/upnp/" \
|
|
Packit |
712bc5 |
" http://www.upnp.org/schemas/av/upnp-v2-20060531.xsd\">" \
|
|
Packit |
712bc5 |
" <container id=\"1\" parentID=\"0\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>NonFlatCollection</dc:title>" \
|
|
Packit |
712bc5 |
" <dc:creator>NonFlatCollection Author</dc:creator>" \
|
|
Packit |
712bc5 |
" <item id=\"\" parentID=\"1\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>Song1</dc:title>" \
|
|
Packit |
712bc5 |
" <upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
" <res protocolInfo=\"*:*:*:*\" />" \
|
|
Packit |
712bc5 |
" <upnp:artist></upnp:artist>" \
|
|
Packit |
712bc5 |
" </item>" \
|
|
Packit |
712bc5 |
" <item id=\"\" parentID=\"1\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>Song2</dc:title>" \
|
|
Packit |
712bc5 |
" <upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
" <res protocolInfo=\"*:*:*:*\" />" \
|
|
Packit |
712bc5 |
" </item>" \
|
|
Packit |
712bc5 |
" <item id=\"\" parentID=\"1\" restricted=\"0\">" \
|
|
Packit |
712bc5 |
" <dc:title>Song3</dc:title>" \
|
|
Packit |
712bc5 |
" <upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
" <res protocolInfo=\"*:*:*:*\" />" \
|
|
Packit |
712bc5 |
" </item>" \
|
|
Packit |
712bc5 |
" </container>" \
|
|
Packit |
712bc5 |
"</DIDL-Lite>"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#define TEST_CREATE_FLAT \
|
|
Packit |
712bc5 |
"
|
|
Packit |
712bc5 |
"xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" " \
|
|
Packit |
712bc5 |
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\" " \
|
|
Packit |
712bc5 |
"xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\">" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song1</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song1.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song2</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song2.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song3</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song3.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"</DIDL-Lite>"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#define TEST_CREATE_FULL \
|
|
Packit |
712bc5 |
"
|
|
Packit |
712bc5 |
"xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" " \
|
|
Packit |
712bc5 |
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\" " \
|
|
Packit |
712bc5 |
"xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\">" \
|
|
Packit |
712bc5 |
"<container>" \
|
|
Packit |
712bc5 |
"<dc:title>TestCollection1</dc:title>" \
|
|
Packit |
712bc5 |
"<dc:creator>TestCollection1Author</dc:creator>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song1</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song1.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song2</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song2.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song3</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song3.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"</container>" \
|
|
Packit |
712bc5 |
"</DIDL-Lite>"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#define TEST_CREATE_FULL_REPARENT \
|
|
Packit |
712bc5 |
"
|
|
Packit |
712bc5 |
"xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" " \
|
|
Packit |
712bc5 |
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\" " \
|
|
Packit |
712bc5 |
"xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\">" \
|
|
Packit |
712bc5 |
"<container>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song1</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song1.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song2</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song2.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<item restricted=\"1\">" \
|
|
Packit |
712bc5 |
"<dc:title>Song3</dc:title>" \
|
|
Packit |
712bc5 |
"<upnp:class>object.item.audioItem</upnp:class>" \
|
|
Packit |
712bc5 |
"<res>http://example.com/song3.mp3</res>" \
|
|
Packit |
712bc5 |
"</item>" \
|
|
Packit |
712bc5 |
"<dc:title>TestCollection1</dc:title>" \
|
|
Packit |
712bc5 |
"<dc:creator>TestCollection1Author</dc:creator>" \
|
|
Packit |
712bc5 |
"</container>" \
|
|
Packit |
712bc5 |
"</DIDL-Lite>"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#define TEST_PARSE_NO_XML "This is just some random text"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_construction (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Check that a collection created via auxillary function is mutable */
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new ();
|
|
Packit |
712bc5 |
g_assert (gupnp_media_collection_get_mutable (collection));
|
|
Packit |
712bc5 |
g_object_unref (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Check that a collection created via auxillary parse function is
|
|
Packit |
712bc5 |
* not mutable */
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new_from_string
|
|
Packit |
712bc5 |
(TEST_PARSE_COLLECTION_1);
|
|
Packit |
712bc5 |
g_assert (!gupnp_media_collection_get_mutable (collection));
|
|
Packit |
712bc5 |
g_object_unref (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Check that creating a collection via g_object_new and title/author
|
|
Packit |
712bc5 |
* properties set is mutable */
|
|
Packit |
712bc5 |
collection = g_object_new (GUPNP_TYPE_MEDIA_COLLECTION,
|
|
Packit |
712bc5 |
"title", "test01collection",
|
|
Packit |
712bc5 |
"author", "test01author",
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert (gupnp_media_collection_get_mutable (collection));
|
|
Packit |
712bc5 |
g_object_unref (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Check that creating a collection via g_object_new and data is not
|
|
Packit |
712bc5 |
* mutable */
|
|
Packit |
712bc5 |
collection = g_object_new (GUPNP_TYPE_MEDIA_COLLECTION,
|
|
Packit |
712bc5 |
"data", TEST_PARSE_COLLECTION_1,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert (!gupnp_media_collection_get_mutable (collection));
|
|
Packit |
712bc5 |
g_object_unref (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Check that creating a collection with all properties set will result
|
|
Packit |
712bc5 |
* in a collection that ignored "title" and "author" properties.
|
|
Packit |
712bc5 |
*/
|
|
Packit |
712bc5 |
collection = g_object_new (GUPNP_TYPE_MEDIA_COLLECTION,
|
|
Packit |
712bc5 |
"title", "test01collection",
|
|
Packit |
712bc5 |
"author", "test01author",
|
|
Packit |
712bc5 |
"data", TEST_PARSE_COLLECTION_1,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert (!gupnp_media_collection_get_mutable (collection));
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_author (collection), ==,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_title (collection), ==,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_string (collection), ==,
|
|
Packit |
712bc5 |
TEST_PARSE_COLLECTION_1);
|
|
Packit |
712bc5 |
g_object_unref (collection);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_parse_flat (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GList *items, *it;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new_from_string
|
|
Packit |
712bc5 |
(TEST_PARSE_COLLECTION_1);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_author (collection), ==,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_title (collection), ==,
|
|
Packit |
712bc5 |
NULL);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_string (collection), ==,
|
|
Packit |
712bc5 |
TEST_PARSE_COLLECTION_1);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
it = items = gupnp_media_collection_get_items (collection);
|
|
Packit |
712bc5 |
g_assert_cmpint (g_list_length (items), ==, 3);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
g_list_free_full (items, (GDestroyNotify) g_object_unref);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_parse_full (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GList *items, *it;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new_from_string
|
|
Packit |
712bc5 |
(TEST_PARSE_COLLECTION_2);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_author (collection), ==,
|
|
Packit |
712bc5 |
"NonFlatCollection Author");
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_title (collection), ==,
|
|
Packit |
712bc5 |
"NonFlatCollection");
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_string (collection), ==,
|
|
Packit |
712bc5 |
TEST_PARSE_COLLECTION_2);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
it = items = gupnp_media_collection_get_items (collection);
|
|
Packit |
712bc5 |
g_assert_cmpint (g_list_length (items), ==, 3);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
g_list_free_full (items, (GDestroyNotify) g_object_unref);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
#define ERROR_MESSAGE "Failed to parse DIDL-Lite: No 'DIDL-Lite' node in the DIDL-Lite XML:"
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static gboolean
|
|
Packit |
712bc5 |
ignore_xml_parse_error (G_GNUC_UNUSED const gchar *log_domain,
|
|
Packit |
712bc5 |
G_GNUC_UNUSED GLogLevelFlags log_level,
|
|
Packit |
712bc5 |
const gchar *message,
|
|
Packit |
712bc5 |
G_GNUC_UNUSED gpointer user_data)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
if (strncmp (message,
|
|
Packit |
712bc5 |
ERROR_MESSAGE,
|
|
Packit |
712bc5 |
g_utf8_strlen (ERROR_MESSAGE, -1) - 1) == 0) {
|
|
Packit |
712bc5 |
return FALSE;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return TRUE;
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_parse_invalid (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GList *items;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_test_log_set_fatal_handler (ignore_xml_parse_error, NULL);
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new_from_string (TEST_PARSE_NO_XML);
|
|
Packit |
712bc5 |
items = gupnp_media_collection_get_items (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_assert (items == NULL);
|
|
Packit |
712bc5 |
g_object_unref (collection);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_create_flat (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteItem *item;
|
|
Packit |
712bc5 |
GList *items, *it;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteResource *res;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new ();
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song1.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song2.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song3.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
it = items = gupnp_media_collection_get_items (collection);
|
|
Packit |
712bc5 |
g_assert_cmpint (g_list_length (items), ==, 3);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
g_list_free_full (items, (GDestroyNotify) g_object_unref);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_string (collection), ==,
|
|
Packit |
712bc5 |
TEST_CREATE_FLAT);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_create_full (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteItem *item;
|
|
Packit |
712bc5 |
GList *items, *it;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteResource *res;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new ();
|
|
Packit |
712bc5 |
gupnp_media_collection_set_title (collection, "TestCollection1");
|
|
Packit |
712bc5 |
gupnp_media_collection_set_author (collection, "TestCollection1Author");
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song1.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song2.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song3.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
it = items = gupnp_media_collection_get_items (collection);
|
|
Packit |
712bc5 |
g_assert_cmpint (g_list_length (items), ==, 3);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
g_list_free_full (items, (GDestroyNotify) g_object_unref);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_string (collection), ==,
|
|
Packit |
712bc5 |
TEST_CREATE_FULL);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
static void
|
|
Packit |
712bc5 |
test_didl_collection_create_reparent (void)
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
GUPnPMediaCollection *collection;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteItem *item;
|
|
Packit |
712bc5 |
GList *items, *it;
|
|
Packit |
712bc5 |
GUPnPDIDLLiteResource *res;
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
collection = gupnp_media_collection_new ();
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song1.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song2.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
item = gupnp_media_collection_add_item (collection);
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_title (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
gupnp_didl_lite_object_set_upnp_class (GUPNP_DIDL_LITE_OBJECT (item),
|
|
Packit |
712bc5 |
"object.item.audioItem");
|
|
Packit |
712bc5 |
res = gupnp_didl_lite_object_add_resource (GUPNP_DIDL_LITE_OBJECT (item));
|
|
Packit |
712bc5 |
gupnp_didl_lite_resource_set_uri (res, "http://example.com/song3.mp3");
|
|
Packit |
712bc5 |
g_object_unref (res);
|
|
Packit |
712bc5 |
g_object_unref (item);
|
|
Packit |
712bc5 |
it = items = gupnp_media_collection_get_items (collection);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
/* Force reparenting of the items in the XML */
|
|
Packit |
712bc5 |
gupnp_media_collection_set_title (collection, "TestCollection1");
|
|
Packit |
712bc5 |
gupnp_media_collection_set_author (collection, "TestCollection1Author");
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_assert_cmpint (g_list_length (items), ==, 3);
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song1");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song2");
|
|
Packit |
712bc5 |
it = it->next;
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_didl_lite_object_get_title (GUPNP_DIDL_LITE_OBJECT (it->data)), ==,
|
|
Packit |
712bc5 |
"Song3");
|
|
Packit |
712bc5 |
g_list_free_full (items, (GDestroyNotify) g_object_unref);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_assert_cmpstr (gupnp_media_collection_get_string (collection), ==,
|
|
Packit |
712bc5 |
TEST_CREATE_FULL_REPARENT);
|
|
Packit |
712bc5 |
}
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
int main (int argc, char *argv[])
|
|
Packit |
712bc5 |
{
|
|
Packit |
712bc5 |
#if !GLIB_CHECK_VERSION (2, 35, 0)
|
|
Packit |
712bc5 |
g_type_init ();
|
|
Packit |
712bc5 |
#endif
|
|
Packit |
712bc5 |
g_test_init (&argc, &argv, NULL);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/construction",
|
|
Packit |
712bc5 |
test_didl_collection_construction);
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/parse_flat",
|
|
Packit |
712bc5 |
test_didl_collection_parse_flat);
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/parse_full",
|
|
Packit |
712bc5 |
test_didl_collection_parse_full);
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/parse_invalid",
|
|
Packit |
712bc5 |
test_didl_collection_parse_invalid);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/create_flat",
|
|
Packit |
712bc5 |
test_didl_collection_create_flat);
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/create_full",
|
|
Packit |
712bc5 |
test_didl_collection_create_full);
|
|
Packit |
712bc5 |
g_test_add_func ("/didl/collection/create_reparent",
|
|
Packit |
712bc5 |
test_didl_collection_create_reparent);
|
|
Packit |
712bc5 |
|
|
Packit |
712bc5 |
return g_test_run ();
|
|
Packit |
712bc5 |
}
|