[libdmapsharing] Add unit tests for DAAPRecord
- From: W. Michael Petullo <wmpetullo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdmapsharing] Add unit tests for DAAPRecord
- Date: Tue, 5 Dec 2017 04:07:13 +0000 (UTC)
commit 17cb26af8492b1d2faa4f24f70b461d8e4e6c263
Author: W. Michael Petullo <mike flyn org>
Date: Mon Dec 4 23:06:17 2017 -0500
Add unit tests for DAAPRecord
Signed-off-by: W. Michael Petullo <mike flyn org>
libdmapsharing/daap-record.c | 97 +++++++++++++++++++++++++++++++++++++
libdmapsharing/test-daap-record.c | 12 +++++
2 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/libdmapsharing/daap-record.c b/libdmapsharing/daap-record.c
index f05c888..9da802c 100644
--- a/libdmapsharing/daap-record.c
+++ b/libdmapsharing/daap-record.c
@@ -256,9 +256,106 @@ daap_record_cmp_by_album (gpointer a, gpointer b, DMAPDb * db)
#ifdef HAVE_CHECK
#include <check.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <libdmapsharing/test-daap-record.h>
#include <libdmapsharing/test-dmap-db.h>
+START_TEST(daap_record_read_test)
+{
+ DAAPRecord *record;
+ GInputStream *stream;
+ GError *error = NULL;
+ gssize count;
+ char buf[PATH_MAX];
+ char template[PATH_MAX];
+ char uri[PATH_MAX];
+ int tmp;
+
+ strcpy(template, "/tmp/libdmapsharing-test-XXXXXX");
+
+ tmp = mkstemp(template);
+ if (-1 == tmp) {
+ ck_abort();
+ }
+
+ /* Use randomization of template name for test data. */
+ count = write(tmp, template, strlen(template));
+ if (-1 == count) {
+ ck_abort();
+ }
+
+ sprintf(uri, "file://%s", template);
+
+ record = DAAP_RECORD(test_daap_record_new());
+ g_object_set(record, "location", uri, NULL);
+
+ stream = daap_record_read(record, &error);
+
+ ck_assert(NULL == error);
+
+ count = g_input_stream_read(stream,
+ buf,
+ BUFSIZ,
+ NULL,
+ &error);
+ ck_assert(NULL == error);
+ ck_assert_str_eq(buf, template);
+
+ g_input_stream_close(stream, NULL, NULL);
+ g_object_unref(record);
+ close(tmp);
+ unlink(template);
+}
+END_TEST
+
+START_TEST(daap_record_read_bad_path_test)
+{
+ DAAPRecord *record;
+ GError *error = NULL;
+ const char *uri = "/xxx";
+
+ record = DAAP_RECORD(test_daap_record_new());
+ g_object_set(record, "location", uri, NULL);
+
+ daap_record_read(record, &error);
+
+ ck_assert(NULL != error);
+
+ g_object_unref(record);
+}
+END_TEST
+
+START_TEST(daap_record_itunes_compat_test)
+{
+ DAAPRecord *record;
+ gboolean ok;
+
+ record = DAAP_RECORD(test_daap_record_new());
+ g_object_set(record, "format", "mp3", NULL);
+
+ ok = daap_record_itunes_compat(record);
+ ck_assert(TRUE == ok);
+
+ g_object_unref(record);
+}
+END_TEST
+
+START_TEST(daap_record_itunes_compat_no_test)
+{
+ DAAPRecord *record;
+ gboolean ok;
+
+ record = DAAP_RECORD(test_daap_record_new());
+ g_object_set(record, "format", "ogg", NULL);
+
+ ok = daap_record_itunes_compat(record);
+ ck_assert(FALSE == ok);
+
+ g_object_unref(record);
+}
+END_TEST
+
START_TEST(daap_record_cmp_by_album_test)
{
gint id;
diff --git a/libdmapsharing/test-daap-record.c b/libdmapsharing/test-daap-record.c
index 0ce1b22..028320e 100644
--- a/libdmapsharing/test-daap-record.c
+++ b/libdmapsharing/test-daap-record.c
@@ -244,6 +244,17 @@ test_daap_record_get_property (GObject *object,
}
}
+gboolean test_daap_record_itunes_compat (DAAPRecord *record)
+{
+ const gchar *format = TEST_DAAP_RECORD (record)->priv->format;
+
+ if (! strcmp (format, "mp3")) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
GInputStream *test_daap_record_read (DAAPRecord *record, GError **error)
{
GFile *file;
@@ -313,6 +324,7 @@ test_daap_record_daap_iface_init (gpointer iface, gpointer data)
g_assert (G_TYPE_FROM_INTERFACE (daap_record) == DAAP_TYPE_RECORD);
+ daap_record->itunes_compat = test_daap_record_itunes_compat;
daap_record->read = test_daap_record_read;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]