tracker-0.16.2/tests/libtracker-common/tracker-dbus-test.c

Location Tool Test ID Function Issue
tracker-dbus-test.c:124:3 clang-analyzer Value stored to 'request' is never read
  1 /*
  2  * Copyright (C) 2008, 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 <stdlib.h>
 21 
 22 #include <glib.h>
 23 #include <gio/gio.h>
 24 
 25 #include <libtracker-common/tracker-dbus.h>
 26 
 27 #include <tracker-test-helpers.h>
 28 
 29 static void
 30 slist_to_strv (gboolean utf8)
 31 {
 32 	GSList *input = NULL;
 33 	gint    i;
 34 	gchar **input_as_strv;
 35 	gint    strings = 5;
 36 
 37 	for (i = 0; i < strings; i++) {
 38 		if (utf8) {
 39 			input = g_slist_prepend (input, g_strdup_printf ("%d", i));
 40 		} else {
 41 			input = g_slist_prepend (input, g_strdup (tracker_test_helpers_get_nonutf8 ()));
 42 		}
 43 	}
 44 	g_assert_cmpint (g_slist_length (input), ==, strings);
 45 
 46 	if (utf8) {
 47 		input_as_strv = tracker_dbus_slist_to_strv (input);
 48 
 49 		g_assert_cmpint (g_strv_length (input_as_strv), ==, (utf8 ? strings : 0));
 50 		g_strfreev (input_as_strv);
 51 	} else {
 52 		if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
 53 			input_as_strv = tracker_dbus_slist_to_strv (input);
 54 			g_strfreev (input_as_strv);
 55 		}
 56 		/* Error message:
 57 		 *   Could not add string:'/invalid/file/\xe4\xf6\xe590808.' to GStrv, invalid UTF-8
 58 		 */
 59 		g_test_trap_assert_stderr ("*Could not add string:*");
 60 	}
 61 
 62 	g_slist_foreach (input, (GFunc) g_free, NULL);
 63 	g_slist_free (input);
 64 }
 65 
 66 static void
 67 test_slist_to_strv (void)
 68 {
 69 	slist_to_strv (TRUE);
 70 }
 71 
 72 #if 0
 73 
 74 static void
 75 test_slist_to_strv_nonutf8 (void)
 76 {
 77 	slist_to_strv (FALSE);
 78 }
 79 
 80 #endif
 81 
 82 #if 0
 83 
 84 static void
 85 test_async_queue_to_strv_nonutf8 (void)
 86 {
 87 	async_queue_to_strv (FALSE);
 88 }
 89 
 90 #endif
 91 
 92 static void
 93 test_dbus_request_failed (void)
 94 {
 95 	TrackerDBusRequest *request;
 96 	GError *error = NULL;
 97 
 98 	/* For some (unknown) reason, this calls don't appear in the
 99 	 * coverage evaluation. */
100 
101 	request = tracker_dbus_request_begin ("tracker-dbus-test.c",
102 	                                      "%s()",
103 	                                      __PRETTY_FUNCTION__);
104 
105 	/* We have already the error and want only the log line */
106 	error = g_error_new (1000, -1, "The indexer founded an error");
107 	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
108 		tracker_dbus_request_end (request, error);
109 	}
110 
111 	g_test_trap_assert_stderr ("*The indexer founded an error*");
112 	g_error_free (error);
113 }
114 
115 static void
116 test_dbus_request ()
117 {
118 	TrackerDBusRequest *request;
119 
120 	tracker_dbus_enable_client_lookup (FALSE);
121 
122 	/* Checking the logging output */
123 	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
124 		request = tracker_dbus_request_begin ("tracker-dbus-test.c",
Value stored to 'request' is never read
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

125 "Test request (%s))", 126 "--TestNewOK--"); 127 exit (0); 128 } 129 130 g_test_trap_assert_passed (); 131 g_test_trap_assert_stdout ("*TestNewOK*"); 132 133 request = tracker_dbus_request_begin ("tracker-dbus-test.c", 134 "Test request (%s))", 135 "--TestNewOK--"); 136 137 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) { 138 tracker_dbus_request_comment (request, 139 "Well (%s)", 140 "--TestCommentOK--"); 141 exit (0); 142 } 143 144 g_test_trap_assert_passed (); 145 g_test_trap_assert_stderr ("*TestCommentOK*"); 146 147 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) { 148 tracker_dbus_request_end (request, NULL); 149 exit (0); 150 } 151 152 g_test_trap_assert_passed (); 153 g_test_trap_assert_stdout ("*Success*"); 154 } 155 #if 0 156 static void 157 test_dbus_request_client_lookup () 158 { 159 TrackerDBusRequest *request; 160 161 tracker_dbus_enable_client_lookup (TRUE); 162 163 164 /* Checking the logging output */ 165 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) { 166 request = tracker_dbus_request_begin ("tracker-dbus-test.c", 167 "Test request (%s))", 168 "--TestNewOK--"); 169 exit (0); 170 } 171 172 g_test_trap_assert_passed (); 173 g_test_trap_assert_stdout ("*TestNewOK*"); 174 g_test_trap_assert_stdout ("*lt-tracker-dbus*"); 175 176 request = tracker_dbus_request_begin ("tracker-dbus-test.c", 177 "Test request (%s))", 178 "--TestNewOK--"); 179 180 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) { 181 tracker_dbus_request_comment (request, 182 "Well (%s)", 183 "--TestCommentOK--"); 184 exit (0); 185 } 186 187 g_test_trap_assert_passed (); 188 g_test_trap_assert_stderr ("*TestCommentOK*"); 189 190 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) { 191 tracker_dbus_request_info (request, 192 "Test info %s", 193 "--TestInfoOK--"); 194 exit (0); 195 } 196 197 g_test_trap_assert_passed (); 198 g_test_trap_assert_stdout ("*TestInfoOK*"); 199 200 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) { 201 tracker_dbus_request_debug (request, 202 "Test debug %s", 203 "--TestDebugOK--"); 204 exit (0); 205 } 206 207 g_test_trap_assert_passed (); 208 g_test_trap_assert_stdout ("*TestDebugOK*"); 209 210 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) { 211 tracker_dbus_request_end (request, NULL); 212 exit (0); 213 } 214 215 g_test_trap_assert_passed (); 216 g_test_trap_assert_stdout ("*Success*"); 217 218 /* Force client shutdown */ 219 tracker_dbus_enable_client_lookup (FALSE); 220 } 221 222 static void 223 test_dbus_request_client_lookup_monothread () 224 { 225 /* Run everything in the same fork to check the clients_shutdown code */ 226 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) { 227 TrackerDBusRequest *request; 228 229 tracker_dbus_enable_client_lookup (TRUE); 230 request = tracker_dbus_request_begin ("tracker-dbus-test.c", 231 "Test request (%s))", 232 "--TestNewOK--"); 233 tracker_dbus_request_comment (request, 234 "Well (%s)", 235 "--TestCommentOK--"); 236 /* 237 tracker_dbus_request_end (request, NULL, 238 "--TestFailedOK--"); 239 tracker_quark = tracker_dbus_error_quark (); 240 error = g_error_new (tracker_quark, -1, "test_using_g_error"); 241 tracker_dbus_request_end (tracker_quark, error); 242 */ 243 244 tracker_dbus_request_end (request, NULL); 245 /* Force client shutdown */ 246 tracker_dbus_enable_client_lookup (FALSE); 247 exit (0); 248 } 249 250 g_test_trap_assert_passed (); 251 } 252 253 static void 254 test_dbus_request_failed_coverage () 255 { 256 /* Repeat the failed test case in one thread to get coverage */ 257 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) { 258 GQuark tracker_quark; 259 GError *error = NULL; 260 TrackerDBusRequest *request; 261 262 tracker_dbus_enable_client_lookup (TRUE); 263 264 /* Using GError */ 265 request = tracker_dbus_request_begin ("tracker-dbus-test.c", 266 "Test request (%s))", 267 "--TestNewOK--"); 268 tracker_quark = tracker_dbus_error_quark (); 269 error = g_error_new (tracker_quark, -1, "test_using_g_error"); 270 tracker_dbus_request_end (request, error); 271 272 request = tracker_dbus_request_begin ("tracker-dbus-test.c", 273 "Test request (%s))", 274 "--TestNewOK--"); 275 tracker_dbus_request_end (request, NULL); 276 277 /* Force client shutdown */ 278 tracker_dbus_enable_client_lookup (FALSE); 279 exit (0); 280 } 281 282 g_test_trap_assert_passed (); 283 } 284 #endif 285 286 int 287 main (int argc, char **argv) { 288 289 gint result; 290 291 g_test_init (&argc, &argv, NULL); 292 293 /* 294 Disabled non-UTF-8 tests to not break test report generation 295 296 g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_nonutf8", 297 test_slist_to_strv_nonutf8); 298 g_test_add_func ("/libtracker-common/tracker-dbus/async_queue_to_strv_nonutf8", 299 test_async_queue_to_strv_nonutf8); 300 */ 301 302 g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_ok", 303 test_slist_to_strv); 304 g_test_add_func ("/libtracker-common/tracker-dbus/request", 305 test_dbus_request); 306 /* port to gdbus first 307 g_test_add_func ("/libtracker-common/tracker-dbus/request-client-lookup", 308 test_dbus_request_client_lookup); 309 310 g_test_add_func ("/libtracker-common/tracker-dbus/request-client-lookup", 311 test_dbus_request_client_lookup_monothread); 312 */ 313 g_test_add_func ("/libtracker-common/tracker-dbus/request_failed", 314 test_dbus_request_failed); 315 /* g_test_add_func ("/libtracker-common/tracker-dbus/request_failed_coverage", 316 test_dbus_request_failed_coverage); 317 */ 318 result = g_test_run (); 319 320 tracker_test_helpers_free_nonutf8 (); 321 322 return result; 323 }