tracker-0.16.2/tests/libtracker-common/tracker-media-art-test.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found tracker-media-art-test.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * Copyright (C) 2011, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include <glib-object.h>
 21 
 22 #include <libtracker-common/tracker-common.h>
 23 
 24 struct {
 25         const gchar *input;
 26         const gchar *expected_output;
 27 } strip_test_cases [] = {
 28         { "nothing to strip here", "nothing to strip here" },
 29         { "Upper Case gOEs dOwN", "upper case goes down"},
 30         { "o", "o"},
 31         { "A", "a"},
 32         { "cool album (CD1)", "cool album"},
 33         { "cool album [CD1]", "cool album"},
 34         { "cool album {CD1}", "cool album"},
 35         { "cool album <CD1>", "cool album"},
 36         { " ", ""},
 37         { "     a     ", "a"},
 38         { "messy #title & stuff?", "messy title stuff"},
 39         { "Unbalanced [brackets", "unbalanced brackets" },
 40         { "Unbalanced (brackets", "unbalanced brackets" },
 41         { "Unbalanced <brackets", "unbalanced brackets" },
 42         { "Unbalanced brackets)", "unbalanced brackets" },
 43         { "Unbalanced brackets]", "unbalanced brackets" },
 44         { "Unbalanced brackets>", "unbalanced brackets" },
 45         { "Live at *WEMBLEY* dude!", "live at wembley dude" },
 46         { NULL, NULL}
 47 };
 48 
 49 static void
 50 test_albumart_stripping (void)
 51 {
 52         gint i;
 53         gchar *result;
 54 
 55         for (i = 0; strip_test_cases[i].input != NULL; i++) {
 56                 result = tracker_media_art_strip_invalid_entities (strip_test_cases[i].input);
 57                 g_assert_cmpstr (result, ==, strip_test_cases[i].expected_output);
 58                 g_free (result);
 59         }
 60 
 61         g_print ("(%d test cases) ", i);
 62 }
 63 
 64 static void
 65 test_albumart_stripping_null (void)
 66 {
 67         // FIXME: Decide what is the expected behaviour here...
 68         //   a. Return NULL
 69         //   b. Return ""
 70         //g_assert (!tracker_albumart_strip_invalid_entities (NULL));
 71 }
 72 
 73 struct {
 74         const gchar *artist;
 75         const gchar *album;
 76         const gchar *filename;
 77 } albumart_test_cases [] = {
 78         {"Beatles", "Sgt. Pepper", 
 79          "album-2a9ea35253dbec60e76166ec8420fbda-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
 80 
 81         { "", "sgt. pepper",
 82           "album-d41d8cd98f00b204e9800998ecf8427e-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
 83 
 84         { " ", "sgt. pepper",
 85           "album-d41d8cd98f00b204e9800998ecf8427e-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
 86 
 87         { NULL, "sgt. pepper",
 88           "album-cfba4326a32b44b8760b3a2fc827a634-7215ee9c7d9dc229d2921a40e899ec5f.jpeg"}, 
 89 
 90         { "Beatles", NULL,
 91           "album-2a9ea35253dbec60e76166ec8420fbda-7215ee9c7d9dc229d2921a40e899ec5f.jpeg"},
 92 
 93         { NULL, NULL, NULL }
 94 };
 95 
 96 static void
 97 test_albumart_location (void)
 98 {
 99         gchar *path = NULL, *local_uri = NULL;
100         gchar *expected;
101         gint i;
102      
103         for (i = 0; albumart_test_cases[i].filename != NULL; i++) {
104                 tracker_media_art_get_path (albumart_test_cases[i].artist,
105                                             albumart_test_cases[i].album,
106                                             "album",
107                                             "file:///home/test/a.mp3",
108                                             &path,
109                                             &local_uri);
110                 expected = g_build_path (G_DIR_SEPARATOR_S, 
111                                          g_get_user_cache_dir (),
112                                          "media-art",
113                                          albumart_test_cases[i].filename, 
114                                          NULL);
115                 g_assert_cmpstr (path, ==, expected);
116                 
117                 g_free (expected);
118                 g_free (path);
119                 g_free (local_uri);
120         }
121         g_print ("(%d test cases) ", i);
122 
123 
124 }
125 
126 static void
127 test_albumart_location_null (void)
128 {
129         gchar *path = NULL, *local_uri = NULL;
130 
131         /* NULL parameters */
132         tracker_media_art_get_path (NULL, NULL, "album", "file:///a/b/c.mp3", &path, &local_uri);
133         g_assert (!path && !local_uri);
134 }
135 
136 static void
137 test_albumart_location_path (void)
138 {
139         gchar *path = NULL, *local_uri = NULL;
140         gchar *expected;
141 
142         /* Use path instead of URI */
143         tracker_media_art_get_path (albumart_test_cases[0].artist,
144                                     albumart_test_cases[0].album,
145                                     "album",
146                                     "/home/test/a.mp3",
147                                     &path,
148                                     &local_uri);
149         expected = g_build_path (G_DIR_SEPARATOR_S, 
150                                  g_get_user_cache_dir (),
151                                  "media-art",
152                                  albumart_test_cases[0].filename, 
153                                  NULL);
154         g_assert_cmpstr (path, ==, expected);
155                 
156         g_free (expected);
157         g_free (path);
158         g_free (local_uri);
159 }
160 
161 gint
162 main (gint argc, gchar **argv)
163 {
164         g_test_init (&argc, &argv, NULL);
165 
166         g_test_add_func ("/libtracker-common/albumart/stripping",
167                          test_albumart_stripping);
168         g_test_add_func ("/libtracker-common/albumart/stripping_null",
169                          test_albumart_stripping_null);
170         g_test_add_func ("/libtracker-common/albumart/location",
171                          test_albumart_location);
172         g_test_add_func ("/libtracker-common/albumart/location_null",
173                          test_albumart_location_null);
174         g_test_add_func ("/libtracker_common/albumart/location_path",
175                          test_albumart_location_path);
176 
177         return g_test_run ();
178 }