[easytag] Add tests for several picture functions
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Add tests for several picture functions
- Date: Fri, 21 Nov 2014 23:21:17 +0000 (UTC)
commit 38ba361b46a1d00d93252cbecfb3afb9ffd8c839
Author: David King <amigadave amigadave com>
Date: Fri Nov 21 23:18:16 2014 +0000
Add tests for several picture functions
Makefile.am | 17 +++++++
src/picture.c | 30 +++++-------
src/picture.h | 2 +-
src/tag_area.c | 6 ++-
tests/test-picture.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 165 insertions(+), 21 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 880b0bd..d208a8f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -410,6 +410,7 @@ test-report perf-report full-report: $(check_PROGRAMS)
check_PROGRAMS = \
tests/test-dlm \
tests/test-misc \
+ tests/test-picture \
tests/test-scan
tests_test_dlm_CPPFLAGS = \
@@ -445,6 +446,22 @@ tests_test_misc_SOURCES = \
tests_test_misc_LDADD = \
$(EASYTAG_LIBS)
+tests_test_picture_CPPFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_builddir) \
+ $(DEPRECATED_CPPFLAGS)
+
+tests_test_picture_CFLAGS = \
+ $(WARN_CFLAGS) \
+ $(EASYTAG_CFLAGS)
+
+tests_test_picture_SOURCES = \
+ tests/test-picture.c \
+ src/picture.c
+
+tests_test_picture_LDADD = \
+ $(EASYTAG_LIBS)
+
tests_test_scan_CPPFLAGS = \
-I$(top_srcdir)/src \
-I$(top_builddir) \
diff --git a/src/picture.c b/src/picture.c
index 88fe08e..7fd81fb 100644
--- a/src/picture.c
+++ b/src/picture.c
@@ -248,11 +248,11 @@ Picture_Type_String (EtPictureType type)
}
gchar *
-Picture_Info (const Picture *pic)
+Picture_Info (const Picture *pic,
+ ET_Tag_Type tag_type)
{
const gchar *format, *desc, *type;
gchar *r, *size_str;
- GString *s;
format = Picture_Format_String(Picture_Format_From_Data(pic));
@@ -264,35 +264,29 @@ Picture_Info (const Picture *pic)
type = Picture_Type_String(pic->type);
size_str = g_format_size (pic->size);
- s = g_string_new(0);
// Behaviour following the tag type...
- switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
+ switch (tag_type)
{
case MP4_TAG:
{
- g_string_printf (s, "%s (%s - %d×%d %s)\n%s: %s",
- format,
- size_str,
- pic->width, pic->height, _("pixels"),
- _("Type"), type);
+ r = g_strdup_printf ("%s (%s - %d×%d %s)\n%s: %s", format,
+ size_str, pic->width, pic->height,
+ _("pixels"), _("Type"), type);
break;
}
// Other tag types
default:
{
- g_string_printf (s, "%s (%s - %d×%d %s)\n%s: %s\n%s: %s",
- format,
- size_str,
- pic->width, pic->height, _("pixels"),
- _("Type"), type,
- _("Description"), desc);
+ r = g_strdup_printf ("%s (%s - %d×%d %s)\n%s: %s\n%s: %s", format,
+ size_str, pic->width, pic->height,
+ _("pixels"), _("Type"), type,
+ _("Description"), desc);
break;
}
}
- r = Try_To_Validate_Utf8_String(s->str);
- g_string_free(s, TRUE); // TRUE to free also 's->str'!
- g_free(size_str);
+
+ g_free (size_str);
return r;
}
diff --git a/src/picture.h b/src/picture.h
index a3d8904..925b49d 100644
--- a/src/picture.h
+++ b/src/picture.h
@@ -89,7 +89,7 @@ void Picture_Free (Picture *pic);
Picture_Format Picture_Format_From_Data (const Picture *pic);
const gchar *Picture_Mime_Type_String (Picture_Format format);
const gchar * Picture_Type_String (EtPictureType type);
-gchar * Picture_Info (const Picture *pic);
+gchar * Picture_Info (const Picture *pic, ET_Tag_Type tag_type);
Picture *et_picture_load_file_data (GFile *file, GError **error);
gboolean et_picture_save_file_data (const Picture *pic, GFile *file, GError **error);
diff --git a/src/tag_area.c b/src/tag_area.c
index 7c6c98b..4be465e 100644
--- a/src/tag_area.c
+++ b/src/tag_area.c
@@ -1304,7 +1304,8 @@ PictureEntry_Update (EtTagArea *self,
GDK_INTERP_BILINEAR);
g_object_unref(pixbuf);
- pic_info = Picture_Info (pic);
+ pic_info = Picture_Info (pic,
+ ETCore->ETFileDisplayed->ETFileDescription->TagType);
gtk_list_store_insert_with_values (priv->images_model, &iter1,
G_MAXINT,
PICTURE_COLUMN_PIC,
@@ -1776,7 +1777,8 @@ on_picture_properties_button_clicked (GObject *object,
pic->description = buffer;
/* Update value in the PictureEntryView. */
- pic_info = Picture_Info (pic);
+ pic_info = Picture_Info (pic,
+ ETCore->ETFileDisplayed->ETFileDescription->TagType);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
PICTURE_COLUMN_TEXT, pic_info, -1);
g_free (pic_info);
diff --git a/tests/test-picture.c b/tests/test-picture.c
new file mode 100644
index 0000000..c037c1b
--- /dev/null
+++ b/tests/test-picture.c
@@ -0,0 +1,131 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014 David King <amigadave amigadave com>
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "picture.h"
+
+static void
+picture_copy (void)
+{
+ Picture *pic1;
+ Picture *pic2;
+ Picture *pic3;
+ Picture *pic1_copy;
+ Picture *pic2_copy;
+ const Picture *pic3_copy;
+
+ pic1 = Picture_Allocate ();
+
+ pic1->type = ET_PICTURE_TYPE_LEAFLET_PAGE;
+ pic1->width = 640;
+ pic1->height = 480;
+ pic1->description = g_strdup ("foobar.png");
+ pic1->size = 10;
+ pic1->data = g_malloc0 (pic1->size);
+
+ pic2 = Picture_Copy (pic1);
+
+ g_assert_cmpint (pic2->type, ==, ET_PICTURE_TYPE_LEAFLET_PAGE);
+ g_assert_cmpint (pic2->width, ==, 640);
+ g_assert_cmpint (pic2->height, ==, 480);
+ g_assert_cmpstr (pic2->description, ==, "foobar.png");
+ g_assert_cmpint (pic2->size, ==, 10);
+ g_assert (pic2->next == NULL);
+
+ pic3 = Picture_Allocate ();
+
+ pic3->type = ET_PICTURE_TYPE_ILLUSTRATION;
+ pic3->width = 320;
+ pic3->height = 240;
+ pic3->description = g_strdup ("bash.jpg");
+ pic3->size = 20;
+ pic3->data = g_malloc0 (pic3->size);
+
+ pic1->next = pic2;
+ pic2->next = pic3;
+
+ pic2_copy = Picture_Copy_One (pic2);
+
+ g_assert_cmpint (pic2_copy->type, ==, ET_PICTURE_TYPE_LEAFLET_PAGE);
+ g_assert_cmpint (pic2_copy->width, ==, 640);
+ g_assert_cmpint (pic2_copy->height, ==, 480);
+ g_assert_cmpstr (pic2_copy->description, ==, "foobar.png");
+ g_assert_cmpint (pic2_copy->size, ==, 10);
+ g_assert (pic2_copy->next == NULL);
+
+ pic1_copy = Picture_Copy (pic1);
+
+ g_assert (pic1_copy->next != NULL);
+ g_assert (pic1_copy->next->next != NULL);
+ g_assert (pic1_copy->next->next->next == NULL);
+
+ pic3_copy = pic1_copy->next->next;
+
+ g_assert_cmpint (pic3_copy->type, ==, ET_PICTURE_TYPE_ILLUSTRATION);
+ g_assert_cmpint (pic3_copy->width, ==, 320);
+ g_assert_cmpint (pic3_copy->height, ==, 240);
+ g_assert_cmpstr (pic3_copy->description, ==, "bash.jpg");
+ g_assert_cmpint (pic3_copy->size, ==, 20);
+
+ Picture_Free (pic1_copy);
+ Picture_Free (pic2_copy);
+ Picture_Free (pic1);
+}
+
+static void
+picture_type_from_filename (void)
+{
+ gsize i;
+
+ static const struct
+ {
+ const gchar *filename;
+ EtPictureType type;
+ } pictures[] =
+ {
+ { "no clues here", ET_PICTURE_TYPE_FRONT_COVER },
+ { "cover.jpg", ET_PICTURE_TYPE_FRONT_COVER },
+ { "inside cover.png", ET_PICTURE_TYPE_LEAFLET_PAGE },
+ { "acdc", ET_PICTURE_TYPE_MEDIA },
+ { "ACDC", ET_PICTURE_TYPE_MEDIA },
+ { "aCdC", ET_PICTURE_TYPE_MEDIA },
+ { "aC dC", ET_PICTURE_TYPE_FRONT_COVER },
+ { "back in black", ET_PICTURE_TYPE_BACK_COVER },
+ { "illustrations of grandeur", ET_PICTURE_TYPE_ILLUSTRATION },
+ { "inside outside", ET_PICTURE_TYPE_LEAFLET_PAGE },
+ { "front to back", ET_PICTURE_TYPE_FRONT_COVER },
+ { "back to front", ET_PICTURE_TYPE_FRONT_COVER }
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (pictures); i++)
+ {
+ g_assert_cmpint (pictures[i].type, ==,
+ et_picture_type_from_filename (pictures[i].filename));
+ }
+}
+
+int
+main (int argc, char** argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/picture/copy", picture_copy);
+ g_test_add_func ("/picture/type-from-filename",
+ picture_type_from_filename);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]