[libdmapsharing] Unit tests for daap-connection.c
- From: W. Michael Petullo <wmpetullo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdmapsharing] Unit tests for daap-connection.c
- Date: Tue, 7 Nov 2017 22:00:13 +0000 (UTC)
commit f9fa1301caed181e093eabd7e0dc0c53506d04fa
Author: W. Michael Petullo <mike flyn org>
Date: Tue Nov 7 16:59:55 2017 -0500
Unit tests for daap-connection.c
Signed-off-by: W. Michael Petullo <mike flyn org>
libdmapsharing/Makefile.am | 21 ++-
libdmapsharing/daap-connection.c | 219 +++++++++++++++++++-
.../test-daap-record-factory.c | 0
.../test-daap-record-factory.h | 0
{tests => libdmapsharing}/test-daap-record.c | 30 +++-
{tests => libdmapsharing}/test-daap-record.h | 0
.../test-dpap-record-factory.c | 0
.../test-dpap-record-factory.h | 0
{tests => libdmapsharing}/test-dpap-record.c | 0
{tests => libdmapsharing}/test-dpap-record.h | 0
tests/Makefile.am | 16 +--
11 files changed, 252 insertions(+), 34 deletions(-)
---
diff --git a/libdmapsharing/Makefile.am b/libdmapsharing/Makefile.am
index 0186b30..5258da6 100644
--- a/libdmapsharing/Makefile.am
+++ b/libdmapsharing/Makefile.am
@@ -24,6 +24,14 @@ libdmapsharing_3_0_la_SOURCES = \
dpap-record.c \
dpap-share.c
+if HAVE_CHECK
+libdmapsharing_3_0_la_SOURCES += \
+ test-daap-record.c \
+ test-daap-record-factory.c \
+ test-dpap-record.c \
+ test-dpap-record-factory.c
+endif
+
if USE_HOWL
libdmapsharing_3_0_la_SOURCES += \
dmap-mdns-browser-howl.c
@@ -99,14 +107,18 @@ libdmapsharinginclude_HEADERS = \
dpap-share.h
noinst_HEADERS = \
- dmap-marshal.h \
dmap-config.h \
- dmap-mdns-avahi.h \
- dmap-private-utils.h \
dmap-gst-mp3-input-stream.h \
dmap-gst-qt-input-stream.h \
dmap-gst-wav-input-stream.h \
- gst-util.h
+ dmap-marshal.h \
+ dmap-mdns-avahi.h \
+ dmap-private-utils.h \
+ gst-util.h \
+ test-daap-record-factory.h \
+ test-daap-record.h \
+ test-dpap-record-factory.h \
+ test-dpap-record.h
BUILT_SOURCES = dmap-marshal.c dmap-marshal.h dmap-enums.c dmap-enums.h unit-test.stamp
@@ -180,6 +192,7 @@ if HAVE_PEDANSEE
echo -n $${i}_parent_class\;; \
echo -n $${i}_get_instance_private\;; \
echo -n $${i}_class_intern_init\;; \
+ echo -n $${i}_get_type\;; \
done >> pedansee.conf
for i in $$(grep G_DEFINE_TYPE *.c | sed 's/.*(\([^,]*\),.*/\1/g'); do \
echo -n $${i}_private_offset\;; \
diff --git a/libdmapsharing/daap-connection.c b/libdmapsharing/daap-connection.c
index 302c053..2f90472 100644
--- a/libdmapsharing/daap-connection.c
+++ b/libdmapsharing/daap-connection.c
@@ -87,6 +87,17 @@ _handle_mlcl (DMAPConnection * connection, DMAPRecordFactory * factory,
case DMAP_CC_ASGN:
genre = g_value_get_string (&(meta_item->content));
break;
+ case DMAP_CC_ASSA:
+ sort_artist =
+ g_value_get_string (&(meta_item->content));
+ break;
+ case DMAP_CC_ASSU:
+ sort_album =
+ g_value_get_string (&(meta_item->content));
+ break;
+ case DMAP_CC_AEHV:
+ has_video = g_value_get_schar (&(meta_item->content));
+ break;
case DMAP_CC_ASTM:
length = g_value_get_int (&(meta_item->content));
break;
@@ -100,23 +111,12 @@ _handle_mlcl (DMAPConnection * connection, DMAPRecordFactory * factory,
case DMAP_CC_ASYR:
year = g_value_get_int (&(meta_item->content));
break;
- case DMAP_CC_AEHV:
- has_video = g_value_get_schar (&(meta_item->content));
- break;
case DMAP_CC_ASSZ:
size = g_value_get_int (&(meta_item->content));
break;
case DMAP_CC_ASBR:
bitrate = g_value_get_int (&(meta_item->content));
break;
- case DMAP_CC_ASSA:
- sort_artist =
- g_value_get_string (&(meta_item->content));
- break;
- case DMAP_CC_ASSU:
- sort_album =
- g_value_get_string (&(meta_item->content));
- break;
default:
break;
}
@@ -126,6 +126,7 @@ _handle_mlcl (DMAPConnection * connection, DMAPRecordFactory * factory,
if (record == NULL) {
goto _return;
}
+
g_object_set (record,
"year", year,
"has-video", has_video,
@@ -188,6 +189,8 @@ G_DEFINE_TYPE (DAAPConnection, daap_connection, DMAP_TYPE_CONNECTION);
#ifdef HAVE_CHECK
#include <check.h>
+#include <libdmapsharing/test-daap-record.h>
+#include <libdmapsharing/test-daap-record-factory.h>
START_TEST(_get_protocol_version_cc_test)
{
@@ -213,6 +216,200 @@ START_TEST(_get_query_metadata_test)
}
END_TEST
+START_TEST(daap_connection_new_test)
+{
+ char *str;
+ int port;
+ DMAPDb *db;
+ DMAPRecordFactory *factory;
+
+ DAAPConnection *connection = daap_connection_new("foo",
+ "foo.example.com",
+ 3689,
+ 0xdeadbeef,
+ 0xfeedface);
+
+ g_object_get(connection, "name", &str, NULL);
+ ck_assert_str_eq("foo", str);
+
+ g_object_get(connection, "host", &str, NULL);
+ ck_assert_str_eq("foo.example.com", str);
+
+ g_object_get(connection, "port", &port, NULL);
+ ck_assert_int_eq(3689, port);
+
+ g_object_get(connection, "db", &db, NULL);
+ ck_assert(0xdeadbeef == db);
+
+ g_object_get(connection, "factory", &factory, NULL);
+ ck_assert(0xfeedface == factory);
+
+ g_object_unref(connection);
+}
+END_TEST
+
+static void
+_append_str_test(GNode *parent, int code, const char *value)
+{
+ DMAPStructureItem *item;
+ GNode *child;
+
+ item = g_new0(DMAPStructureItem, 1);
+ item->content_code = code;
+ item->size = strlen(value);
+ g_value_init(&(item->content), G_TYPE_STRING);
+ g_value_take_string (&(item->content), value);
+ child = g_node_new(item);
+ g_node_append(parent, child);
+}
+
+static void
+_append_boolean_test(GNode *parent, int code, const gboolean value)
+{
+ DMAPStructureItem *item;
+ GNode *child;
+
+ item = g_new0(DMAPStructureItem, 1);
+ item->content_code = code;
+ item->size = 1;
+ g_value_init(&(item->content), G_TYPE_CHAR);
+ g_value_set_schar(&(item->content), value);
+ child = g_node_new(item);
+ g_node_append(parent, child);
+}
+
+static void
+_append_int_test(GNode *parent, int code, const int value)
+{
+ DMAPStructureItem *item;
+ GNode *child;
+
+ item = g_new0(DMAPStructureItem, 1);
+ item->content_code = code;
+ item->size = 4;
+ g_value_init(&(item->content), G_TYPE_INT);
+ g_value_set_int(&(item->content), value);
+ child = g_node_new(item);
+ g_node_append(parent, child);
+}
+
+START_TEST(_handle_mlcl_test)
+{
+ DMAPStructureItem *item;
+ TestDAAPRecordFactory *factory;
+ GNode *parent;
+ DMAPRecord *record;
+ char *expected_title = "title", *title = NULL;
+ char *expected_album = "album", *album = NULL;
+ char *expected_artist = "artist", *artist = NULL;
+ char *expected_format = "format", *format = NULL;
+ char *expected_genre = "genre", *genre = NULL;
+ char *expected_sort_artist = "sort-artist", *sort_artist = NULL;
+ char *expected_sort_album = "sort-album", *sort_album = NULL;
+ gboolean expected_has_video = TRUE, has_video = FALSE;
+ gint expected_length = 10000, length = 0;
+ gint expected_track = 20, track = 0;
+ gint expected_disc = 30, disc = 0;
+ gint expected_year = 40, year = 0;
+ gint expected_size = 50, size = 0;
+ gint expected_bitrate = 60, bitrate = 0;
+ gint expected_item_id = 70, item_id = 0;
+
+ item = g_new0(DMAPStructureItem, 1);
+ item->content_code = 0;
+ parent = g_node_new(item);
+
+ _append_int_test(parent, DMAP_CC_MIID, expected_item_id);
+ _append_str_test(parent, DMAP_CC_MINM, expected_title);
+ _append_str_test(parent, DMAP_CC_ASAL, expected_album);
+ _append_str_test(parent, DMAP_CC_ASAR, expected_artist);
+ _append_str_test(parent, DMAP_CC_ASFM, expected_format);
+ _append_str_test(parent, DMAP_CC_ASGN, expected_genre);
+ _append_str_test(parent, DMAP_CC_ASSA, expected_sort_artist);
+ _append_str_test(parent, DMAP_CC_ASSU, expected_sort_album);
+ _append_boolean_test(parent, DMAP_CC_AEHV, expected_has_video);
+ _append_int_test(parent, DMAP_CC_ASTM, expected_length);
+ _append_int_test(parent, DMAP_CC_ASTN, expected_track);
+ _append_int_test(parent, DMAP_CC_ASDN, expected_disc);
+ _append_int_test(parent, DMAP_CC_ASYR, expected_year);
+ _append_int_test(parent, DMAP_CC_ASSZ, expected_size);
+ _append_int_test(parent, DMAP_CC_ASBR, expected_bitrate);
+
+ factory = test_daap_record_factory_new();
+ record = _handle_mlcl(NULL, factory, parent, &item_id);
+
+ ck_assert_int_eq(expected_item_id, item_id);
+
+ g_object_get(record, "title", &title, NULL);
+ ck_assert_str_eq(expected_title, title);
+
+ g_object_get(record, "songalbum", &album, NULL);
+ ck_assert_str_eq(expected_album, album);
+
+ g_object_get(record, "songartist", &artist, NULL);
+ ck_assert_str_eq(expected_artist, artist);
+
+ g_object_get(record, "format", &format, NULL);
+ ck_assert_str_eq(expected_format, format);
+
+ g_object_get(record, "songgenre", &genre, NULL);
+ ck_assert_str_eq(expected_genre, genre);
+
+ g_object_get(record, "sort-artist", &sort_artist, NULL);
+ ck_assert_str_eq(expected_sort_artist, sort_artist);
+
+ g_object_get(record, "sort-album", &sort_album, NULL);
+ ck_assert_str_eq(expected_sort_album, sort_album);
+
+ g_object_get(record, "has-video", &has_video, NULL);
+ ck_assert_int_eq(expected_has_video, has_video);
+
+ g_object_get(record, "duration", &length, NULL);
+ ck_assert_int_eq(expected_length, length * 1000);
+
+ g_object_get(record, "track", &track, NULL);
+ ck_assert_int_eq(expected_track, track);
+
+ g_object_get(record, "disc", &disc, NULL);
+ ck_assert_int_eq(expected_disc, disc);
+
+ g_object_get(record, "year", &year, NULL);
+ ck_assert_int_eq(expected_year, year);
+
+ g_object_get(record, "filesize", &size, NULL);
+ ck_assert_int_eq(expected_size, size);
+
+ g_object_get(record, "bitrate", &bitrate, NULL);
+ ck_assert_int_eq(expected_bitrate, bitrate);
+}
+END_TEST
+
+/* Do not crash on bad field code (~0). */
+START_TEST(_handle_mlcl_bad_code_test)
+{
+ DMAPStructureItem *item;
+ TestDAAPRecordFactory *factory;
+ GNode *parent;
+ DMAPRecord *record;
+ int item_id;
+ char *set_value = "value", *value = NULL;
+ char *expected_title = "title", *title = NULL;
+
+ item = g_new0(DMAPStructureItem, 1);
+ item->content_code = 0;
+ parent = g_node_new(item);
+
+ _append_str_test(parent, ~0, set_value);
+ _append_str_test(parent, DMAP_CC_MINM, expected_title);
+
+ factory = test_daap_record_factory_new();
+ record = _handle_mlcl(NULL, factory, parent, &item_id);
+
+ g_object_get(record, "title", &title, NULL);
+ ck_assert_str_eq(expected_title, title);
+}
+END_TEST
+
#include "daap-connection-suite.c"
#endif
diff --git a/tests/test-daap-record-factory.c b/libdmapsharing/test-daap-record-factory.c
similarity index 100%
rename from tests/test-daap-record-factory.c
rename to libdmapsharing/test-daap-record-factory.c
diff --git a/tests/test-daap-record-factory.h b/libdmapsharing/test-daap-record-factory.h
similarity index 100%
rename from tests/test-daap-record-factory.h
rename to libdmapsharing/test-daap-record-factory.h
diff --git a/tests/test-daap-record.c b/libdmapsharing/test-daap-record.c
similarity index 90%
rename from tests/test-daap-record.c
rename to libdmapsharing/test-daap-record.c
index e6a4c2e..2d14872 100644
--- a/tests/test-daap-record.c
+++ b/libdmapsharing/test-daap-record.c
@@ -30,8 +30,10 @@ struct TestDAAPRecordPrivate {
char *format;
char *real_format;
char *album;
+ char *sort_album;
char *artist;
- gulong bitrate;
+ char *sort_artist;
+ gint32 bitrate;
gint32 firstseen;
gint32 mtime;
gint32 disc;
@@ -49,7 +51,9 @@ enum {
PROP_RATING,
PROP_FILESIZE,
PROP_ALBUM,
+ PROP_SORT_ALBUM,
PROP_ARTIST,
+ PROP_SORT_ARTIST,
PROP_GENRE,
PROP_FORMAT,
PROP_DURATION,
@@ -84,10 +88,18 @@ test_daap_record_set_property (GObject *object,
g_free (record->priv->album);
record->priv->album = g_value_dup_string (value);
break;
+ case PROP_SORT_ALBUM:
+ g_free (record->priv->sort_album);
+ record->priv->sort_album = g_value_dup_string (value);
+ break;
case PROP_ARTIST:
g_free (record->priv->artist);
record->priv->artist = g_value_dup_string (value);
break;
+ case PROP_SORT_ARTIST:
+ g_free (record->priv->sort_artist);
+ record->priv->sort_artist = g_value_dup_string (value);
+ break;
case PROP_GENRE:
g_free (record->priv->genre);
record->priv->genre = g_value_dup_string (value);
@@ -104,7 +116,7 @@ test_daap_record_set_property (GObject *object,
record->priv->rating = g_value_get_int (value);
break;
case PROP_FILESIZE:
- record->priv->filesize = g_value_get_int (value);
+ record->priv->filesize = g_value_get_uint64 (value);
break;
case PROP_DURATION:
record->priv->duration = g_value_get_int (value);
@@ -125,7 +137,7 @@ test_daap_record_set_property (GObject *object,
record->priv->disc = g_value_get_int (value);
break;
case PROP_BITRATE:
- record->priv->bitrate = g_value_get_long (value);
+ record->priv->bitrate = g_value_get_int (value);
break;
case PROP_HAS_VIDEO:
record->priv->has_video = g_value_get_boolean (value);
@@ -154,9 +166,15 @@ test_daap_record_get_property (GObject *object,
case PROP_ALBUM:
g_value_set_string (value, record->priv->album);
break;
+ case PROP_SORT_ALBUM:
+ g_value_set_string (value, record->priv->sort_album);
+ break;
case PROP_ARTIST:
g_value_set_string (value, record->priv->artist);
break;
+ case PROP_SORT_ARTIST:
+ g_value_set_string (value, record->priv->sort_artist);
+ break;
case PROP_GENRE:
g_value_set_string (value, record->priv->genre);
break;
@@ -167,7 +185,7 @@ test_daap_record_get_property (GObject *object,
g_value_set_int (value, record->priv->rating);
break;
case PROP_FILESIZE:
- g_value_set_int (value, record->priv->filesize);
+ g_value_set_uint64 (value, record->priv->filesize);
break;
case PROP_DURATION:
g_value_set_int (value, record->priv->duration);
@@ -188,7 +206,7 @@ test_daap_record_get_property (GObject *object,
g_value_set_int (value, record->priv->disc);
break;
case PROP_BITRATE:
- g_value_set_long (value, record->priv->bitrate);
+ g_value_set_int (value, record->priv->bitrate);
break;
case PROP_HAS_VIDEO:
g_value_set_boolean (value, record->priv->has_video);
@@ -234,7 +252,9 @@ test_daap_record_class_init (TestDAAPRecordClass *klass)
g_object_class_override_property (gobject_class, PROP_LOCATION, "location");
g_object_class_override_property (gobject_class, PROP_TITLE, "title");
g_object_class_override_property (gobject_class, PROP_ALBUM, "songalbum");
+ g_object_class_override_property (gobject_class, PROP_SORT_ALBUM, "sort-album");
g_object_class_override_property (gobject_class, PROP_ARTIST, "songartist");
+ g_object_class_override_property (gobject_class, PROP_SORT_ARTIST, "sort-artist");
g_object_class_override_property (gobject_class, PROP_GENRE, "songgenre");
g_object_class_override_property (gobject_class, PROP_FORMAT, "format");
g_object_class_override_property (gobject_class, PROP_RATING, "rating");
diff --git a/tests/test-daap-record.h b/libdmapsharing/test-daap-record.h
similarity index 100%
rename from tests/test-daap-record.h
rename to libdmapsharing/test-daap-record.h
diff --git a/tests/test-dpap-record-factory.c b/libdmapsharing/test-dpap-record-factory.c
similarity index 100%
rename from tests/test-dpap-record-factory.c
rename to libdmapsharing/test-dpap-record-factory.c
diff --git a/tests/test-dpap-record-factory.h b/libdmapsharing/test-dpap-record-factory.h
similarity index 100%
rename from tests/test-dpap-record-factory.h
rename to libdmapsharing/test-dpap-record-factory.h
diff --git a/tests/test-dpap-record.c b/libdmapsharing/test-dpap-record.c
similarity index 100%
rename from tests/test-dpap-record.c
rename to libdmapsharing/test-dpap-record.c
diff --git a/tests/test-dpap-record.h b/libdmapsharing/test-dpap-record.h
similarity index 100%
rename from tests/test-dpap-record.h
rename to libdmapsharing/test-dpap-record.h
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3853408..bfc5f6d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,10 +16,6 @@ endif
test_dmap_client_SOURCES = \
test-dmap-db.c \
- test-daap-record.c \
- test-dpap-record.c \
- test-daap-record-factory.c \
- test-dpap-record-factory.c \
test-dmap-client.c
test_dmap_client_LDADD = \
@@ -36,11 +32,7 @@ test_dmap_server_SOURCES = \
test-dmap-db.c \
test-dmap-container-record.c \
test-dmap-container-db.c \
- test-dmap-server.c \
- test-daap-record.c \
- test-daap-record-factory.c \
- test-dpap-record.c \
- test-dpap-record-factory.c
+ test-dmap-server.c
test_dmap_server_LDADD = \
$(GLIB_LIBS) \
@@ -153,11 +145,7 @@ INCLUDES = \
noinst_HEADERS = \
test-dmap-container-record.h \
test-dmap-container-db.h \
- test-dmap-db.h \
- test-daap-record.h \
- test-daap-record-factory.h \
- test-dpap-record.h \
- test-dpap-record-factory.h
+ test-dmap-db.h
EXTRA_DIST = \
$(dacplisten_VALASOURCES) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]