1 /* EasyTAG - tag editor for audio files
2  * Copyright (C) 2015-2016 David King <amigadave@amigadave.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "file_tag.h"
20 
21 #include "misc.h"
22 #include "picture.h"
23 
24 GtkWidget *MainWindow;
25 GSettings *MainSettings;
26 
27 static void
file_tag_new(void)28 file_tag_new (void)
29 {
30     File_Tag *file_tag;
31 
32     file_tag = et_file_tag_new ();
33 
34     g_assert (file_tag);
35 
36     et_file_tag_free (file_tag);
37 }
38 
39 static void
file_tag_copy(void)40 file_tag_copy (void)
41 {
42     File_Tag *tag1;
43     File_Tag *tag2;
44 
45     tag1 = et_file_tag_new ();
46 
47     g_assert (tag1);
48 
49     et_file_tag_set_title (tag1, "foo");
50     et_file_tag_set_artist (tag1, "bar");
51     et_file_tag_set_album_artist (tag1, "baz");
52 
53     g_assert_cmpstr (tag1->title, ==, "foo");
54     g_assert_cmpstr (tag1->artist, ==, "bar");
55     g_assert_cmpstr (tag1->album_artist, ==, "baz");
56 
57     tag2 = et_file_tag_new ();
58 
59     g_assert (tag2);
60 
61     et_file_tag_copy_into (tag2, tag1);
62 
63     g_assert_cmpstr (tag2->title, ==, "foo");
64     g_assert_cmpstr (tag2->artist, ==, "bar");
65     g_assert_cmpstr (tag2->album_artist, ==, "baz");
66 
67     et_file_tag_free (tag2);
68     et_file_tag_free (tag1);
69 }
70 
71 static void
file_tag_copy_other(void)72 file_tag_copy_other (void)
73 {
74     File_Tag *tag1;
75     File_Tag *tag2;
76     GList *l;
77 
78     tag1 = et_file_tag_new ();
79 
80     g_assert (tag1);
81 
82     tag1->other = g_list_prepend (tag1->other, g_strdup ("foo"));
83 
84     tag2 = et_file_tag_new ();
85 
86     g_assert (tag2);
87 
88     tag2->other = g_list_prepend (tag2->other, g_strdup ("bar"));
89 
90     et_file_tag_copy_other_into (tag1, tag2);
91 
92     l = tag1->other;
93     g_assert_cmpstr (l->data, ==, "foo");
94 
95     l = g_list_next (l);
96     g_assert_cmpstr (l->data, ==, "bar");
97 
98     et_file_tag_free (tag2);
99     et_file_tag_free (tag1);
100 }
101 
102 static void
file_tag_difference(void)103 file_tag_difference (void)
104 {
105     File_Tag *tag1;
106     File_Tag *tag2;
107     GBytes *bytes;
108 
109     tag1 = et_file_tag_new ();
110 
111     g_assert (tag1);
112 
113     et_file_tag_set_title (tag1, "foo:");
114 
115     /* Contains a full-width colon, which should compare differently to a
116      * colon. */
117     g_assert_cmpstr (tag1->title, ==, "foo:");
118 
119     tag2 = et_file_tag_new ();
120 
121     g_assert (tag2);
122 
123     et_file_tag_set_title (tag2, "foo:");
124 
125     g_test_bug ("744897");
126     g_assert (et_file_tag_detect_difference (tag1, tag2));
127 
128     et_file_tag_free (tag2);
129     et_file_tag_free (tag1);
130 
131     tag1 = et_file_tag_new ();
132 
133     et_file_tag_set_artist (tag1, "bar");
134 
135     tag2 = et_file_tag_new ();
136 
137     et_file_tag_set_artist (tag2, "baz");
138 
139     g_assert (et_file_tag_detect_difference (tag1, tag2));
140 
141     et_file_tag_free (tag2);
142     et_file_tag_free (tag1);
143 
144     tag1 = et_file_tag_new ();
145     bytes = g_bytes_new_static ("foo", 3);
146 
147     et_file_tag_set_picture (tag1,
148                              et_picture_new (ET_PICTURE_TYPE_FRONT_COVER, "", 0, 0,
149                                              bytes));
150 
151     g_bytes_unref (bytes);
152 
153     tag2 = et_file_tag_new ();
154 
155     g_assert (et_file_tag_detect_difference (tag1, tag2));
156 
157     et_file_tag_free (tag2);
158     et_file_tag_free (tag1);
159 }
160 
161 int
main(int argc,char ** argv)162 main (int argc, char** argv)
163 {
164     g_test_init (&argc, &argv, NULL);
165     g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=");
166 
167     g_test_add_func ("/file_tag/new", file_tag_new);
168     g_test_add_func ("/file_tag/copy", file_tag_copy);
169     g_test_add_func ("/file_tag/copy-other", file_tag_copy_other);
170     g_test_add_func ("/file_tag/difference", file_tag_difference);
171 
172     return g_test_run ();
173 }
174