summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2006-05-30 14:09:44 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2006-05-30 14:09:44 +0000
commit355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17 (patch)
tree64cc40dc42c33925c6183222667354276479c362 /tests
parent58503e6e5b6ef315f37fe859baaf0f5216fc8f5c (diff)
downloadlibgpod-355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17.tar.gz
libgpod-355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17.tar.xz
libgpod-355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17.zip
***** merged photo-support branch back to MAIN. branch is tagged
photo-support-merged_00 ipod.py will need minor patching (flag2, flag3). git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1292 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/test-init-ipod.c102
-rw-r--r--tests/test-photos.c144
3 files changed, 255 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 651f41a..4aa7bc5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,16 +1,18 @@
if HAVE_GDKPIXBUF
-TESTTHUMBS=test-thumbnails test-write-thumbnails
+TESTTHUMBS=test-thumbnails test-write-thumbnails test-photos
else
TESTTHUMBS=
endif
+TESTMISC=test-init-ipod
+
if HAVE_TAGLIB
TESTTAGLIB=test-rebuild-db
else
TESTTAGLIB=
endif
-noinst_PROGRAMS=test-itdb test-ls $(TESTTHUMBS) $(TESTTAGLIB)
+noinst_PROGRAMS=test-itdb test-ls $(TESTTHUMBS) $(TESTTAGLIB) $(TESTMISC)
INCLUDES=$(LIBGPOD_CFLAGS) -I$(top_srcdir)/src -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
LIBS=$(LIBGPOD_LIBS) $(top_builddir)/src/libgpod.la
@@ -31,6 +33,11 @@ if HAVE_GDKPIXBUF
test_thumbnails_SOURCES = test-covers.c
test_thumbnails_CFLAGS = $(AM_CFLAGS)
+test_photos_SOURCES = test-photos.c
+test_photos_CFLAGS = $(AM_CFLAGS)
+
+test_init_ipod_SOURCES = test-init-ipod.c
+
test_write_thumbnails_SOURCES = test-write-covers.c
test_write_thumbnails_CFLAGS = $(AM_CFLAGS)
endif
diff --git a/tests/test-init-ipod.c b/tests/test-init-ipod.c
new file mode 100644
index 0000000..809afcd
--- /dev/null
+++ b/tests/test-init-ipod.c
@@ -0,0 +1,102 @@
+/* Copyright (c) 2006, Jorg Schuler
+ * <jcsjcs at users dot sourceforge dot net>
+ *
+ * The code contained in this file is free software; you can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either version
+ * 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this code; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * iTunes and iPod are trademarks of Apple
+ *
+ * This product is not supported/written/published by Apple!
+ *
+ * $Id$
+ *
+ */
+
+#include "itdb.h"
+
+#include <locale.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <glib/gi18n-lib.h>
+
+
+static void usage (const char *argv0)
+{
+ g_print ("Usage: %s mountpoint [modelnumber]\n", argv0);
+ g_print ("This test program will create the standard directories on your iPod\n");
+ g_print ("including empty iTunesDB and ArtworkDB.\n\n");
+ g_print ("Valid model numbers are listed in itdb_device.c, e.g. 'MA350' for a\n");
+ g_print ("1 GB iPod nano\n\n");
+ g_print ("Often the model number can be found in <mountpoint>/iTunes/Device/SysInfo,\n");
+ g_print ("which is written automatically by most iPods when you reset it.\n\n");
+ g_print ("If you omit the model number, this program will try to detect the model\n");
+ g_print ("number and print it.\n");
+}
+
+
+int
+main (int argc, char **argv)
+{
+ if ((argc < 2) || (argc > 3))
+ {
+ usage (argv[0]);
+ return 1;
+ }
+ setlocale (LC_ALL, "");
+ g_type_init ();
+
+ if (argc == 3)
+ {
+ GError *error = NULL;
+
+ if (!itdb_init_ipod (argv[1], argv[2], "iPod", &error))
+ {
+ if (error)
+ {
+ g_print (_("Error initialising iPod: %s\n"),
+ error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ {
+ g_print (_("Error initialising iPod, unknown error\n"));
+ }
+ }
+ }
+ if (argc == 2)
+ {
+ gchar *model_num;
+ Itdb_Device *device = itdb_device_new ();
+ itdb_device_set_mountpoint (device, argv[1]);
+
+ model_num = itdb_device_get_sysinfo (device, "ModelNumStr");
+
+ if (model_num)
+ {
+ g_print ("Your iPod model number seems to be '%s'.\n",
+ model_num);
+ }
+ else
+ {
+ g_print ("Your iPod model number could not be detected.\n");
+ g_print ("Maybe you have an iPod Shuffle? In that case specify 'M9724' (512 MB)\n");
+ g_print ("or 'M9725' (1 GB) to setup your iPod.\n");
+ g_print ("If you have a mobile phone, specify 'Mmobile1'.\n");
+ g_print ("Otherwise look up the model number on the ipod package or in\n");
+ g_print ("itdb_device.c (prepend 'M').\n");
+ }
+ itdb_device_free (device);
+ }
+ return 0;
+}
diff --git a/tests/test-photos.c b/tests/test-photos.c
new file mode 100644
index 0000000..ae03c21
--- /dev/null
+++ b/tests/test-photos.c
@@ -0,0 +1,144 @@
+/* Copyright (c) 2006, Michael McLellan <mikey@mclellan.org.nz>
+ *
+ * The code contained in this file is free software; you can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either version
+ * 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this code; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * iTunes and iPod are trademarks of Apple
+ *
+ * This product is not supported/written/published by Apple!
+ *
+ * $Id$
+ *
+ */
+
+#include "itdb.h"
+
+#include <locale.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <glib/gi18n-lib.h>
+
+static void
+save_itdb_thumb (Itdb_PhotoDB *itdb, Itdb_Thumb *thumb, const char *filename)
+{
+ GdkPixbuf *pixbuf;
+
+ pixbuf = itdb_thumb_get_gdk_pixbuf (itdb->device, thumb);
+
+ if (pixbuf != NULL) {
+ gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL);
+ gdk_pixbuf_unref (pixbuf);
+ }
+}
+
+static void
+dump_thumbs (Itdb_PhotoDB *db, Itdb_Artwork *artwork, char *album_name )
+{
+ GList *it;
+ gint i = 0;
+
+ for (it = artwork->thumbnails; it != NULL; it = it->next, i++) {
+ Itdb_Thumb *thumb;
+ gchar *filename;
+
+ thumb = (Itdb_Thumb *)it->data;
+ g_return_if_fail (thumb);
+
+ filename = g_strdup_printf ("%s-%d-%d.png",
+ album_name, artwork->id, i );
+ save_itdb_thumb (db, thumb, filename);
+ g_free (filename);
+ }
+}
+
+static void
+dump_artwork (Itdb_PhotoDB *db, gint photo_id, char *album_name)
+{
+ GList *it;
+
+ for (it = db->photos; it != NULL; it = it->next) {
+ Itdb_Artwork *artwork;
+
+ artwork = (Itdb_Artwork *)it->data;
+ g_return_if_fail (artwork);
+ if( artwork->id == photo_id ) {
+ dump_thumbs( db, artwork, album_name );
+ break;
+ }
+ }
+}
+
+static void
+dump_albums (Itdb_PhotoDB *db)
+{
+ GList *it;
+
+ for (it = db->photoalbums; it != NULL; it = it->next) {
+ Itdb_PhotoAlbum *album;
+ GList *it2;
+
+ album = (Itdb_PhotoAlbum *)it->data;
+ g_return_if_fail (album);
+
+ for (it2 = album->members; it2 != NULL; it2 = it2->next) {
+ gint *photo_id;
+
+ photo_id = it2->data;
+ g_return_if_fail (photo_id);
+ dump_artwork (db, *photo_id, album->name);
+ }
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ GError *error = NULL;
+ Itdb_PhotoDB *db;
+ gint i;
+
+ if (argc < 4) {
+ g_print ("Usage: %s mountpoint albumname filename(s)\n", argv[0]);
+ g_print ("albumname should be set to 'master' to add photos to the master photo album\n");
+ return 1;
+ }
+ setlocale (LC_ALL, "");
+ g_type_init ();
+ db = itdb_photodb_parse (argv[1], &error);
+
+ if (db == NULL) {
+ if (error)
+ {
+ g_print (_("Error reading iPod photo database (%s).\nWill attempt to create a new database.\n"), error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ {
+ g_print (_("Error reading iPod photo database, will attempt to create a new database\n"));
+ }
+ db = itdb_photodb_new ();
+ itdb_device_set_mountpoint (db->device, argv[1]);
+ }
+
+ if( 0 )
+ dump_albums (db);
+
+ for (i=3; i<argc; ++i) {
+ itdb_photodb_add_photo (db, argv[2], argv[i]);
+ }
+ itdb_photodb_write (db, NULL);
+ itdb_photodb_free (db);
+ return 0;
+}
+