rhythmbox r5667 - in trunk: . plugins/audioscrobbler po tests



Author: jmatthew
Date: Fri Apr  4 12:47:10 2008
New Revision: 5667
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=5667&view=rev

Log:
2008-04-04  Jonathan Matthew  <jonathan d14n org>

	* plugins/audioscrobbler/Makefile.am:
	* plugins/audioscrobbler/rb-audioscrobbler-entry.c:
	* plugins/audioscrobbler/rb-audioscrobbler-entry.h:
	* plugins/audioscrobbler/rb-audioscrobbler.c:
	(rb_audioscrobbler_finalize), (maybe_add_current_song_to_queue),
	(rb_audioscrobbler_build_post_data),
	(rb_audioscrobbler_song_changed_cb),
	(rb_audioscrobbler_load_queue), (rb_audioscrobbler_save_queue),
	(rb_audioscrobbler_print_queue),
	(rb_audioscrobbler_free_queue_entries):
	Split code for dealing with audioscrobbler queue entries out to a
	separate file.  Instead of formatting the timestamp when saving to
	disk, just save the time_t as an integer.  Fixes #508895.

	* tests/Makefile.am:
	* tests/test-audioscrobbler.c: (START_TEST),
	(rb_audioscrobbler_suite), (main):
	Add a few simple tests to make sure queue entries survive being saved.
	Would have caught this and the soup_uri_decode thing.


Added:
   trunk/plugins/audioscrobbler/rb-audioscrobbler-entry.c
   trunk/plugins/audioscrobbler/rb-audioscrobbler-entry.h
   trunk/tests/test-audioscrobbler.c
Modified:
   trunk/ChangeLog
   trunk/plugins/audioscrobbler/Makefile.am
   trunk/plugins/audioscrobbler/rb-audioscrobbler.c
   trunk/po/ChangeLog
   trunk/po/POTFILES.in
   trunk/tests/Makefile.am

Modified: trunk/plugins/audioscrobbler/Makefile.am
==============================================================================
--- trunk/plugins/audioscrobbler/Makefile.am	(original)
+++ trunk/plugins/audioscrobbler/Makefile.am	Fri Apr  4 12:47:10 2008
@@ -5,6 +5,8 @@
 
 libaudioscrobbler_la_SOURCES = \
 	rb-audioscrobbler-plugin.c			\
+	rb-audioscrobbler-entry.h			\
+	rb-audioscrobbler-entry.c			\
 	rb-audioscrobbler.c				\
 	rb-audioscrobbler.h				\
 	rb-lastfm-gst-src.c				\

Added: trunk/plugins/audioscrobbler/rb-audioscrobbler-entry.c
==============================================================================
--- (empty file)
+++ trunk/plugins/audioscrobbler/rb-audioscrobbler-entry.c	Fri Apr  4 12:47:10 2008
@@ -0,0 +1,229 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ *  Copyright (C) 2007 Christophe Fergeau <teuf gnome org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ */
+
+#define __EXTENSIONS__
+
+#include "config.h"
+
+#include <string.h>
+#include <time.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "rb-debug.h"
+#include "rhythmdb.h"
+#include "rb-soup-compat.h"
+#include <libsoup/soup.h>
+
+#include "rb-audioscrobbler-entry.h"
+
+
+#define SCROBBLER_DATE_FORMAT "%Y%%2D%m%%2D%d%%20%H%%3A%M%%3A%S"
+
+
+void
+rb_audioscrobbler_entry_init (AudioscrobblerEntry *entry)
+{
+	entry->artist = g_strdup ("");
+	entry->album = g_strdup ("");
+	entry->title = g_strdup ("");
+	entry->length = 0;
+	entry->play_time = 0;
+	entry->mbid = g_strdup ("");
+}
+
+void
+rb_audioscrobbler_entry_free (AudioscrobblerEntry *entry)
+{
+	g_free (entry->artist);
+	g_free (entry->album);
+	g_free (entry->title);
+	g_free (entry->mbid);
+
+	g_free (entry);
+}
+
+void
+rb_audioscrobbler_encoded_entry_free (AudioscrobblerEncodedEntry *entry)
+{
+	g_free (entry->artist);
+	g_free (entry->album);
+	g_free (entry->title);
+	g_free (entry->mbid);
+	g_free (entry->timestamp);
+
+	g_free (entry);
+}
+
+
+AudioscrobblerEntry *
+rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry)
+{
+	AudioscrobblerEntry *as_entry = g_new0 (AudioscrobblerEntry, 1);
+
+	as_entry->title = rhythmdb_entry_dup_string (rb_entry,
+						     RHYTHMDB_PROP_TITLE);
+	as_entry->artist = rhythmdb_entry_dup_string (rb_entry,
+						      RHYTHMDB_PROP_ARTIST);
+	as_entry->album = rhythmdb_entry_dup_string (rb_entry,
+						     RHYTHMDB_PROP_ALBUM);
+	if (strcmp (as_entry->album, _("Unknown")) == 0) {
+		g_free (as_entry->album);
+		as_entry->album = g_strdup ("");
+	}
+	as_entry->length = rhythmdb_entry_get_ulong (rb_entry,
+						     RHYTHMDB_PROP_DURATION);
+	as_entry->mbid = rhythmdb_entry_dup_string (rb_entry,
+						    RHYTHMDB_PROP_MUSICBRAINZ_TRACKID);
+
+	return as_entry;
+}
+
+AudioscrobblerEncodedEntry *
+rb_audioscrobbler_entry_encode (AudioscrobblerEntry *entry)
+{
+
+	AudioscrobblerEncodedEntry *encoded;
+
+	encoded = g_new0 (AudioscrobblerEncodedEntry, 1);
+	
+	encoded->artist = soup_uri_encode (entry->artist, 
+					   EXTRA_URI_ENCODE_CHARS);
+	encoded->title = soup_uri_encode (entry->title,
+					  EXTRA_URI_ENCODE_CHARS);
+	encoded->album = soup_uri_encode (entry->album, 
+					  EXTRA_URI_ENCODE_CHARS);
+	encoded->mbid = soup_uri_encode (entry->mbid, 
+					 EXTRA_URI_ENCODE_CHARS);
+	encoded->timestamp = g_new0 (gchar, 30);
+	strftime (encoded->timestamp, 30, SCROBBLER_DATE_FORMAT, 
+		  gmtime (&entry->play_time));
+
+	encoded->length = entry->length;
+
+	return encoded;
+}
+
+static char *
+rb_uri_decode (const char *uri)
+{
+#if defined(HAVE_LIBSOUP_2_4)
+    return soup_uri_decode (uri);
+#else 
+    char *result;
+    result = g_strdup (uri);
+    soup_uri_decode (result);
+    return result;
+#endif
+}
+
+AudioscrobblerEntry*
+rb_audioscrobbler_entry_load_from_string (const char *string)
+{
+	AudioscrobblerEntry *entry;
+	int i = 0;
+	char **breaks;
+
+	entry = g_new0 (AudioscrobblerEntry, 1);
+	rb_audioscrobbler_entry_init (entry);
+
+	breaks = g_strsplit (string, "&", 6);
+
+	for (i = 0; breaks[i] != NULL; i++) {
+		char **breaks2 = g_strsplit (breaks[i], "=", 2);
+
+		if (breaks2[0] != NULL && breaks2[1] != NULL) {
+			if (g_str_has_prefix (breaks2[0], "a")) {
+				g_free (entry->artist);
+				entry->artist = rb_uri_decode (breaks2[1]);
+			}
+			if (g_str_has_prefix (breaks2[0], "t")) {
+				g_free (entry->title);
+				entry->title = rb_uri_decode (breaks2[1]);
+			}
+			if (g_str_has_prefix (breaks2[0], "b")) {
+				g_free (entry->album);
+				entry->album = rb_uri_decode (breaks2[1]);
+			}
+			if (g_str_has_prefix (breaks2[0], "m")) {
+				g_free (entry->mbid);
+				entry->mbid = rb_uri_decode (breaks2[1]);
+			}
+			if (g_str_has_prefix (breaks2[0], "l")) {
+				entry->length = atoi (breaks2[1]);
+			}
+			if (g_str_has_prefix (breaks2[0], "i")) {
+				struct tm tm;
+				strptime (breaks2[1], SCROBBLER_DATE_FORMAT, 
+					  &tm);
+				entry->play_time = mktime (&tm);
+			}
+			/* slight format extension: time_t */
+			if (g_str_has_prefix (breaks2[0], "I")) {		
+				entry->play_time = strtol (breaks2[1], NULL, 10);
+			}
+		}
+
+		g_strfreev (breaks2);
+	}
+
+	g_strfreev (breaks);
+
+	if (strcmp (entry->artist, "") == 0 || strcmp (entry->title, "") == 0) {
+		rb_audioscrobbler_entry_free (entry);
+		entry = NULL;
+	}
+
+	return entry;
+}
+
+char *
+rb_audioscrobbler_entry_save_to_string (AudioscrobblerEntry *entry)
+{
+	char *result;
+	AudioscrobblerEncodedEntry *encoded;
+
+	encoded = rb_audioscrobbler_entry_encode (entry);
+	result = g_strdup_printf ("a=%s&t=%s&b=%s&m=%s&l=%d&I=%ld\n",
+				  encoded->artist, 
+				  encoded->title,
+				  encoded->album, 
+				  encoded->mbid,
+				  encoded->length,
+				  entry->play_time);
+	rb_audioscrobbler_encoded_entry_free (encoded);
+	return result;
+}
+
+void
+rb_audioscrobbler_entry_debug (AudioscrobblerEntry *entry, int index)
+{
+	char timestamp[30];
+	rb_debug ("%-3d  artist: %s", index, entry->artist);
+	rb_debug ("      album: %s", entry->album);
+	rb_debug ("      title: %s", entry->title);
+	rb_debug ("     length: %d", entry->length);
+	rb_debug ("   playtime: %ld", entry->play_time);
+	strftime (timestamp, 30, SCROBBLER_DATE_FORMAT, 
+		  gmtime (&entry->play_time));
+	rb_debug ("  timestamp: %s", timestamp);
+}
+

Added: trunk/plugins/audioscrobbler/rb-audioscrobbler-entry.h
==============================================================================
--- (empty file)
+++ trunk/plugins/audioscrobbler/rb-audioscrobbler-entry.h	Fri Apr  4 12:47:10 2008
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007 Christophe Fergeau <teuf gnome org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ */
+
+#ifndef __RB_AUDIOSCROBBLER_ENTRY_H
+#define __RB_AUDIOSCROBBLER_ENTRY_H
+
+G_BEGIN_DECLS
+
+#include "rhythmdb.h"
+
+#define EXTRA_URI_ENCODE_CHARS	"&+"
+
+typedef struct
+{
+	gchar *artist;
+	gchar *album;
+	gchar *title;
+	guint length;
+	gchar *mbid;
+	time_t play_time;
+} AudioscrobblerEntry;
+
+typedef struct
+{
+	gchar *artist;
+	gchar *album;
+	gchar *title;
+	guint length;
+	gchar *mbid;
+	gchar *timestamp;
+} AudioscrobblerEncodedEntry;
+
+
+void	     			rb_audioscrobbler_entry_init (AudioscrobblerEntry *entry);
+void	     			rb_audioscrobbler_entry_free (AudioscrobblerEntry *entry);
+void          			rb_audioscrobbler_encoded_entry_free (AudioscrobblerEncodedEntry *entry);
+AudioscrobblerEncodedEntry *	rb_audioscrobbler_entry_encode (AudioscrobblerEntry *entry);
+
+AudioscrobblerEntry *		rb_audioscrobbler_entry_create (RhythmDBEntry *rb_entry);
+
+AudioscrobblerEntry *		rb_audioscrobbler_entry_load_from_string (const char *string);
+char *				rb_audioscrobbler_entry_save_to_string (AudioscrobblerEntry *entry);
+
+void				rb_audioscrobbler_entry_debug (AudioscrobblerEntry *entry, int index);
+
+G_END_DECLS
+
+#endif /* __RB_AUDIOSCROBBLER_ENTRY_H */
+

Modified: trunk/plugins/audioscrobbler/rb-audioscrobbler.c
==============================================================================
--- trunk/plugins/audioscrobbler/rb-audioscrobbler.c	(original)
+++ trunk/plugins/audioscrobbler/rb-audioscrobbler.c	Fri Apr  4 12:47:10 2008
@@ -54,6 +54,7 @@
 #include "rb-cut-and-paste-code.h"
 #include "rb-plugin.h"
 
+#include "rb-audioscrobbler-entry.h"
 
 #define CLIENT_ID "rbx"
 #define CLIENT_VERSION VERSION
@@ -64,31 +65,6 @@
 
 #define USER_AGENT	"Rhythmbox/" VERSION
 
-#define SCROBBLER_DATE_FORMAT "%Y%%2D%m%%2D%d%%20%H%%3A%M%%3A%S"
-
-#define EXTRA_URI_ENCODE_CHARS	"&+"
-
-typedef struct
-{
-	gchar *artist;
-	gchar *album;
-	gchar *title;
-	guint length;
-	gchar *mbid;
-	time_t play_time;
-} AudioscrobblerEntry;
-
-typedef struct
-{
-	gchar *artist;
-	gchar *album;
-	gchar *title;
-	guint length;
-	gchar *mbid;
-	gchar *timestamp;
-} AudioscrobblerEncodedEntry;
-
-
 struct _RBAudioscrobblerPrivate
 {
 	RBShellPlayer *shell_player;
@@ -166,13 +142,6 @@
 #define RB_AUDIOSCROBBLER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_AUDIOSCROBBLER, RBAudioscrobblerPrivate))
 
 
-static void	     audioscrobbler_entry_init (AudioscrobblerEntry *entry);
-static void	     audioscrobbler_entry_free (AudioscrobblerEntry *entry);
-static void          audioscrobbler_encoded_entry_free (AudioscrobblerEncodedEntry *entry);
-static AudioscrobblerEncodedEntry *audioscrobbler_entry_encode (AudioscrobblerEntry *entry);
-
-
-
 static gboolean	     rb_audioscrobbler_load_queue (RBAudioscrobbler *audioscrobbler);
 static int	     rb_audioscrobbler_save_queue (RBAudioscrobbler *audioscrobbler);
 static void	     rb_audioscrobbler_print_queue (RBAudioscrobbler *audioscrobbler, gboolean submission);
@@ -416,7 +385,7 @@
 	g_free (audioscrobbler->priv->password);
 	g_free (audioscrobbler->priv->submit_url);
 	if (audioscrobbler->priv->currently_playing != NULL) {
-		audioscrobbler_entry_free (audioscrobbler->priv->currently_playing);
+		rb_audioscrobbler_entry_free (audioscrobbler->priv->currently_playing);
 		audioscrobbler->priv->currently_playing = NULL;
 	}
 
@@ -621,7 +590,7 @@
 			/* not sure about this - what if I skip to somewhere towards
 			 * the end, but then go back and listen to the whole song?
 			 */
-			audioscrobbler_entry_free (audioscrobbler->priv->currently_playing);
+			rb_audioscrobbler_entry_free (audioscrobbler->priv->currently_playing);
 			audioscrobbler->priv->currently_playing = NULL;
 
 		}
@@ -1023,7 +992,7 @@
 		gchar *new;
 		/* remove first queue entry */
 		entry = g_queue_pop_head (audioscrobbler->priv->queue);
-		encoded = audioscrobbler_entry_encode (entry);
+		encoded = rb_audioscrobbler_entry_encode (entry);
 		new = g_strdup_printf ("%sa[%d]=%s&t[%d]=%s&b[%d]=%s&m[%d]=%s&l[%d]=%d&i[%d]=%s&",
 				       post_data,
 				       i, encoded->artist,
@@ -1032,7 +1001,7 @@
 				       i, encoded->mbid,
 				       i, encoded->length,
 				       i, encoded->timestamp);
-		audioscrobbler_encoded_entry_free (encoded);
+		rb_audioscrobbler_encoded_entry_free (encoded);
 		g_free (post_data);
 		post_data = new;
 
@@ -1334,7 +1303,7 @@
 	guint time;
 
 	if (audioscrobbler->priv->currently_playing != NULL) {
-		audioscrobbler_entry_free (audioscrobbler->priv->currently_playing);
+		rb_audioscrobbler_entry_free (audioscrobbler->priv->currently_playing);
 		audioscrobbler->priv->currently_playing = NULL;
 	}
 
@@ -1396,136 +1365,9 @@
 	/* ? */
 }
 
-/* AudioscrobblerEntry functions: */
-static void
-audioscrobbler_entry_init (AudioscrobblerEntry *entry)
-{
-	entry->artist = g_strdup ("");
-	entry->album = g_strdup ("");
-	entry->title = g_strdup ("");
-	entry->length = 0;
-	entry->play_time = 0;
-	entry->mbid = g_strdup ("");
-}
-
-static void
-audioscrobbler_entry_free (AudioscrobblerEntry *entry)
-{
-	g_free (entry->artist);
-	g_free (entry->album);
-	g_free (entry->title);
-	g_free (entry->mbid);
-
-	g_free (entry);
-}
-
-static AudioscrobblerEncodedEntry *
-audioscrobbler_entry_encode (AudioscrobblerEntry *entry)
-{
-
-	AudioscrobblerEncodedEntry *encoded;
-
-	encoded = g_new0 (AudioscrobblerEncodedEntry, 1);
-	
-	encoded->artist = soup_uri_encode (entry->artist, 
-					   EXTRA_URI_ENCODE_CHARS);
-	encoded->title = soup_uri_encode (entry->title,
-					  EXTRA_URI_ENCODE_CHARS);
-	encoded->album = soup_uri_encode (entry->album, 
-					  EXTRA_URI_ENCODE_CHARS);
-	encoded->mbid = soup_uri_encode (entry->mbid, 
-					 EXTRA_URI_ENCODE_CHARS);
-	encoded->timestamp = g_new0 (gchar, 30);
-	strftime (encoded->timestamp, 30, SCROBBLER_DATE_FORMAT, 
-		  gmtime (&entry->play_time));
-
-	encoded->length = entry->length;
-
-	return encoded;
-}
-
-static 
-void audioscrobbler_encoded_entry_free (AudioscrobblerEncodedEntry *entry)
-{
-	g_free (entry->artist);
-	g_free (entry->album);
-	g_free (entry->title);
-	g_free (entry->mbid);
-	g_free (entry->timestamp);
-
-	g_free (entry);
-}
 
 
 /* Queue functions: */
-static char *rb_uri_decode (const char *uri)
-{
-#if defined(HAVE_LIBSOUP_2_4)
-    return soup_uri_decode (uri);
-#else 
-    char *decoded;
-    decoded = g_strdup (uri);
-    soup_uri_decode (decoded);
-    return decoded;
-#endif
-}
-
-static AudioscrobblerEntry*
-rb_audioscrobbler_load_entry_from_string (const char *string)
-{
-	AudioscrobblerEntry *entry;
-	int i = 0;
-	char **breaks;
-
-	entry = g_new0 (AudioscrobblerEntry, 1);
-	audioscrobbler_entry_init (entry);
-
-	breaks = g_strsplit (string, "&", 6);
-
-	for (i = 0; breaks[i] != NULL; i++) {
-		char **breaks2 = g_strsplit (breaks[i], "=", 2);
-
-		if (breaks2[0] != NULL && breaks2[1] != NULL) {
-			if (g_str_has_prefix (breaks2[0], "a")) {
-				g_free (entry->artist);
-				entry->artist = rb_uri_decode (breaks2[1]);
-			}
-			if (g_str_has_prefix (breaks2[0], "t")) {
-				g_free (entry->title);
-				entry->title = rb_uri_decode (breaks2[1]);
-			}
-			if (g_str_has_prefix (breaks2[0], "b")) {
-				g_free (entry->album);
-				entry->album = rb_uri_decode (breaks2[1]);
-			}
-			if (g_str_has_prefix (breaks2[0], "m")) {
-				g_free (entry->mbid);
-				entry->mbid = rb_uri_decode (breaks2[1]);
-			}
-			if (g_str_has_prefix (breaks2[0], "l")) {
-				entry->length = atoi (breaks2[1]);
-			}
-			if (g_str_has_prefix (breaks2[0], "i")) {
-				struct tm tm;
-				strptime (breaks2[1], SCROBBLER_DATE_FORMAT, 
-					  &tm);
-				entry->play_time = mktime (&tm);
-			}
-		}
-
-		g_strfreev (breaks2);
-	}
-
-	g_strfreev (breaks);
-
-	if (strcmp (entry->artist, "") == 0 || strcmp (entry->title, "") == 0) {
-		audioscrobbler_entry_free (entry);
-		entry = NULL;
-	}
-
-	return entry;
-}
-
 static gboolean
 rb_audioscrobbler_load_queue (RBAudioscrobbler *audioscrobbler)
 {
@@ -1556,7 +1398,7 @@
 				break;
 			*end = 0;
 
-			entry = rb_audioscrobbler_load_entry_from_string (start);
+			entry = rb_audioscrobbler_entry_load_from_string (start);
 			if (entry) {
 				g_queue_push_tail (audioscrobbler->priv->queue,
 						   entry);
@@ -1576,23 +1418,6 @@
 	return (result == GNOME_VFS_OK);
 }
 
-static char *
-rb_audioscrobbler_save_entry_to_string (AudioscrobblerEntry *entry)
-{
-	char *result;
-	AudioscrobblerEncodedEntry *encoded;
-
-	encoded = audioscrobbler_entry_encode (entry);
-	result = g_strdup_printf ("a=%s&t=%s&b=%s&m=%s&l=%d&i=%s\n",
-				  encoded->artist, 
-				  encoded->title,
-				  encoded->album, 
-				  encoded->mbid,
-				  encoded->length,
-				  encoded->timestamp);
-	audioscrobbler_encoded_entry_free (encoded);
-	return result;
-}
 
 static gboolean
 rb_audioscrobbler_save_queue (RBAudioscrobbler *audioscrobbler)
@@ -1621,7 +1446,7 @@
 			AudioscrobblerEntry *entry;
 			char *str;
 			entry = (AudioscrobblerEntry *) l->data;
-			str = rb_audioscrobbler_save_entry_to_string (entry);
+			str = rb_audioscrobbler_entry_save_to_string (entry);
 			result = gnome_vfs_write (handle, str, strlen (str), 
 						  NULL);
 			g_free (str);
@@ -1662,23 +1487,15 @@
 	}
 
 	for (; l != NULL; l = g_list_next (l)) {
-		char timestamp[30];
 		entry = (AudioscrobblerEntry *) l->data;
-		
-		rb_debug ("%-3d  artist: %s", ++i, entry->artist);
-		rb_debug ("      album: %s", entry->album);
-		rb_debug ("      title: %s", entry->title);
-		rb_debug ("     length: %d", entry->length);
-		strftime (timestamp, 30, SCROBBLER_DATE_FORMAT, 
-			  gmtime (&entry->play_time));
-		rb_debug ("  timestamp: %s", timestamp);
+		rb_audioscrobbler_entry_debug (entry, ++i);
 	}
 }
 
 static void
 rb_audioscrobbler_free_queue_entries (RBAudioscrobbler *audioscrobbler, GQueue **queue)
 {
-	g_queue_foreach (*queue, (GFunc) audioscrobbler_entry_free, NULL);
+	g_queue_foreach (*queue, (GFunc) rb_audioscrobbler_entry_free, NULL);
 	g_queue_free (*queue);
 	*queue = NULL;
 

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Fri Apr  4 12:47:10 2008
@@ -40,6 +40,7 @@
 [type: gettext/ini]plugins/audioscrobbler/audioscrobbler.rb-plugin.in
 plugins/audioscrobbler/audioscrobbler-prefs.glade
 plugins/audioscrobbler/rb-audioscrobbler-plugin.c
+plugins/audioscrobbler/rb-audioscrobbler-entry.c
 plugins/audioscrobbler/rb-audioscrobbler.c
 plugins/audioscrobbler/rb-lastfm-source.c
 [type: gettext/ini]plugins/cd-recorder/cd-recorder.rb-plugin.in

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	(original)
+++ trunk/tests/Makefile.am	Fri Apr  4 12:47:10 2008
@@ -32,7 +32,12 @@
 	$(test_utils)
 
 test_rb_lib_SOURCES = \
-	test-rb-lib.c					\
+	test-rb-lib.c						\
+	$(test_utils)
+
+test_audioscrobbler_SOURCES = \
+	test-audioscrobbler.c					\
+	$(top_srcdir)/plugins/audioscrobbler/rb-audioscrobbler-entry.c \
 	$(test_utils)
 
 bench_rhythmdb_load_SOURCES = bench-rhythmdb-load.c
@@ -42,11 +47,13 @@
 	-DG_LOG_DOMAIN=\"Rhythmbox-tests\"			\
 	-I$(top_srcdir) 					\
 	$(RHYTHMBOX_CFLAGS)					\
+	$(SOUP_CFLAGS)						\
 	-I$(top_srcdir)/lib					\
 	-I$(top_srcdir)/metadata				\
 	-I$(top_srcdir)/widgets					\
-	-I$(top_srcdir)/rhythmdb
-
+	-I$(top_srcdir)/rhythmdb				\
+	-I$(top_srcdir)/plugins/audioscrobbler			\
+	-D_XOPEN_SOURCE -D_BSD_SOURCE
 
 if HAVE_CHECK
 TESTS += \
@@ -54,7 +61,8 @@
 	test-rhythmdb						\
 	test-rhythmdb-query-model				\
 	test-rhythmdb-property-model				\
-	test-file-helpers
+	test-file-helpers					\
+	test-audioscrobbler
 endif
 
 OLD_TESTS = \

Added: trunk/tests/test-audioscrobbler.c
==============================================================================
--- (empty file)
+++ trunk/tests/test-audioscrobbler.c	Fri Apr  4 12:47:10 2008
@@ -0,0 +1,86 @@
+#include "config.h"
+
+#include <string.h>
+#include <glib-object.h>
+
+#include <check.h>
+#include "test-utils.h"
+#include "rb-audioscrobbler-entry.h"
+#include "rb-debug.h"
+#include "rb-util.h"
+
+START_TEST (test_rb_audioscrobbler_entry)
+{
+	AudioscrobblerEntry *entry;
+	AudioscrobblerEntry *reload;
+	char *as_string;
+
+	entry = g_new0(AudioscrobblerEntry, 1);
+	entry->title = g_strdup ("something or other");
+	entry->artist = g_strdup ("someone & someone else");
+	entry->album = g_strdup ("unknown + other things");
+	entry->length = 11;
+	entry->mbid = g_strdup ("");		/* ? */
+	entry->play_time = time (0);
+
+	as_string = rb_audioscrobbler_entry_save_to_string (entry);
+	rb_debug ("string form: %s", as_string);
+	fail_unless (strlen (as_string) != 0, "entry saved as string should not be empty");
+
+	reload = rb_audioscrobbler_entry_load_from_string (as_string);
+	fail_unless (reload != NULL, "entry-as-string can be converted back to an entry");
+
+	rb_audioscrobbler_entry_debug (entry, 0);
+	rb_audioscrobbler_entry_debug (reload, 1);
+	fail_unless (strcmp (entry->title, reload->title) == 0, "title made it back OK");
+	fail_unless (strcmp (entry->artist, reload->artist) == 0, "artist made it back OK");
+	fail_unless (strcmp (entry->album, reload->album) == 0, "album made it back OK");
+	fail_unless (strcmp (entry->mbid, reload->mbid) == 0, "album made it back OK");
+	fail_unless (entry->length == reload->length, "length made it back OK");
+	fail_unless (entry->play_time == reload->play_time, "play time made it back OK");
+
+	rb_audioscrobbler_entry_free (entry);
+	rb_audioscrobbler_entry_free (reload);
+	g_free (as_string);
+}
+END_TEST
+
+static Suite *
+rb_audioscrobbler_suite ()
+{
+	Suite *s = suite_create ("rb-audioscrobbler");
+	TCase *tc_chain = tcase_create ("rb-audioscrobbler-entry");
+
+	suite_add_tcase (s, tc_chain);
+
+	tcase_add_test (tc_chain, test_rb_audioscrobbler_entry);
+
+	return s;
+}
+
+int
+main (int argc, char **argv)
+{
+	int ret;
+	SRunner *sr;
+	Suite *s;
+
+	rb_profile_start ("rb-audioscrobbler test suite");
+	g_thread_init (NULL);
+	rb_threads_init ();
+	g_type_init ();
+	rb_debug_init (TRUE);
+
+	GDK_THREADS_ENTER ();
+
+	/* setup tests */
+	s = rb_audioscrobbler_suite ();
+	sr = srunner_create (s);
+	srunner_run_all (sr, CK_NORMAL);
+	ret = srunner_ntests_failed (sr);
+	srunner_free (sr);
+
+	rb_profile_end ("rb-audioscrobbler test suite");
+	return ret;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]