tracker-0.16.2/tests/libtracker-miner/miners-mock.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found miners-mock.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) 2010, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public License
  6  * as published by the Free Software Foundation; either version 2
  7  * of the License, or (at your option) any later version.
  8  *
  9  * This program 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
 12  * GNU General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public License
 15  * along with this program; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 17  * 02110-1301, USA.
 18  */
 19 
 20 #include <string.h>
 21 
 22 #include <glib-object.h>
 23 #include <gobject/gvaluecollector.h>
 24 
 25 #include "empty-gobject.h"
 26 #include "miners-mock.h"
 27 #include "tracker-miner-mock.h"
 28 
 29 GHashTable *miners = NULL;
 30 
 31 void
 32 miners_mock_init ()
 33 {
 34 	TrackerMinerMock *miner;
 35 
 36 	miners = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 37 
 38 	miner = tracker_miner_mock_new (MOCK_MINER_1);
 39 	tracker_miner_mock_set_paused (miner, FALSE);
 40 	g_hash_table_insert (miners, g_strdup (MOCK_MINER_1), miner);
 41 
 42 	miner = tracker_miner_mock_new (MOCK_MINER_2);
 43 	tracker_miner_mock_set_paused (miner, TRUE);
 44 	g_hash_table_insert (miners, g_strdup (MOCK_MINER_2), miner);
 45 }
 46 
 47 /*
 48  * DBus overrides
 49  */
 50 #if 0
 51 /* Todo: port to gdbus */
 52 
 53 DBusGConnection *
 54 dbus_g_bus_get (DBusBusType type, GError **error)
 55 {
 56 	return (DBusGConnection *) empty_object_new ();
 57 }
 58 
 59 DBusGProxy *
 60 dbus_g_proxy_new_for_name (DBusGConnection *connection,
 61                            const gchar *service,
 62                            const gchar *path,
 63                            const gchar *interface )
 64 {
 65 	TrackerMinerMock *miner;
 66 
 67 	miner = (TrackerMinerMock *)g_hash_table_lookup (miners, service);
 68 	if (!miner) {
 69 		return (DBusGProxy *) empty_object_new ();
 70 	}
 71 	return (DBusGProxy *) miner;
 72 }
 73 
 74 void
 75 dbus_g_proxy_add_signal (DBusGProxy *proxy, const char *signal_name, GType first_type,...)
 76 {
 77 }
 78 
 79 void
 80 dbus_g_proxy_connect_signal (DBusGProxy *proxy,
 81                              const char *signal_name,
 82                              GCallback handler,
 83                              void *data,
 84                              GClosureNotify free_data_func)
 85 {
 86 	TrackerMinerMock *miner = (TrackerMinerMock *)proxy;
 87 
 88 	if (g_strcmp0 (signal_name, "NameOwnerChanged") == 0) {
 89 		return;
 90 	}
 91 
 92 	g_signal_connect (miner, g_utf8_strdown (signal_name, -1), handler, data);
 93 
 94 }
 95 
 96 /*
 97  * Two mock miners available but only 1 running
 98  */
 99 gboolean
100 dbus_g_proxy_call (DBusGProxy *proxy,
101                    const gchar *function_name,
102                    GError  **error,
103                    GType first_arg_type, ...)
104 {
105 	va_list args;
106 	GType   arg_type;
107 	const gchar *running_services[] = { "org.gnome.Tomboy",
108 	                                    "org.gnome.GConf",
109 	                                    MOCK_MINER_1,
110 	                                    "org.gnome.SessionManager",
111 	                                    NULL};
112 
113 	va_start (args, first_arg_type);
114 
115 	if (g_strcmp0 (function_name, "ListNames") == 0) {
116 		/*
117 		 *  G_TYPE_INVALID,
118 		 *  G_TYPE_STRV, &result,
119 		 *  G_TYPE_INVALID
120 		 */
121 		GValue value = { 0, };
122 		gchar *local_error = NULL;
123 
124 		arg_type = va_arg (args, GType);
125 
126 		g_assert (arg_type == G_TYPE_STRV);
127 		g_value_init (&value, arg_type);
128 		g_value_set_boxed (&value, running_services);
129 		G_VALUE_LCOPY (&value,
130 		               args, 0,
131 		               &local_error);
132 		g_free (local_error);
133 		g_value_unset (&value);
134 
135 	} else if (g_strcmp0 (function_name, "NameHasOwner") == 0) {
136 		/*
137 		 * G_TYPE_STRING, miner,
138 		 * G_TYPE_INVALID,
139 		 * G_TYPE_BOOLEAN, &active,
140 		 *  G_TYPE_INVALID)) {
141 		 */
142 		GValue value = { 0, };
143 		gchar *local_error = NULL;
144 		const gchar *miner_name;
145 		TrackerMinerMock *miner;
146 		gboolean     active;
147 
148 		g_value_init (&value, G_TYPE_STRING);
149 		G_VALUE_COLLECT (&value, args, 0, &local_error);
150 		g_free (local_error);
151 		miner_name = g_value_get_string (&value);
152 
153 		miner = (TrackerMinerMock *)g_hash_table_lookup (miners, miner_name);
154 		active = !tracker_miner_mock_get_paused (miner);
155 		g_value_unset (&value);
156 
157 		arg_type = va_arg (args, GType);
158 		g_assert (arg_type == G_TYPE_INVALID);
159 
160 		arg_type = va_arg (args, GType);
161 		g_assert (arg_type == G_TYPE_BOOLEAN);
162 		g_value_init (&value, arg_type);
163 		g_value_set_boolean (&value, active);
164 		G_VALUE_LCOPY (&value,
165 		               args, 0,
166 		               &local_error);
167 		g_free (local_error);
168 		g_value_unset (&value);
169 
170 	} else if (g_strcmp0 (function_name, "GetPauseDetails") == 0) {
171 		/*
172 		 *  G_TYPE_INVALID,
173 		 *  G_TYPE_STRV, &apps,
174 		 *  G_TYPE_STRV, &reasons,
175 		 *  G_TYPE_INVALID
176 		 */
177 		GValue value = { 0, };
178 		gchar *local_error = NULL;
179 		gint   amount;
180 		gchar **apps, **reasons;
181 		TrackerMinerMock *miner = (TrackerMinerMock *)proxy;
182 
183 		arg_type = va_arg (args, GType);
184 		g_assert (arg_type == G_TYPE_STRV);
185 		g_value_init (&value, arg_type);
186 		apps = tracker_miner_mock_get_apps (miner, &amount);
187 		if (apps == NULL || amount == 0) {
188 			apps = g_new0 (gchar *, 1);
189 		}
190 		g_value_set_boxed (&value, apps);
191 		G_VALUE_LCOPY (&value,
192 		               args, 0,
193 		               &local_error);
194 		g_free (local_error);
195 		g_value_unset (&value);
196 
197 		arg_type = va_arg (args, GType);
198 		g_assert (arg_type == G_TYPE_STRV);
199 		g_value_init (&value, arg_type);
200 		reasons = tracker_miner_mock_get_reasons (miner, &amount);
201 		if (reasons == NULL || amount == 0) {
202 			reasons = g_new0 (gchar *, 1);
203 		}
204 		g_value_set_boxed (&value, reasons);
205 		G_VALUE_LCOPY (&value,
206 		               args, 0,
207 		               &local_error);
208 		g_free (local_error);
209 		g_value_unset (&value);
210 
211 	} else if (g_strcmp0 (function_name, "Pause") == 0) {
212 		/*
213 		 *  G_TYPE_STRING, &app,
214 		 *  G_TYPE_STRING, &reason,
215 		 *  G_TYPE_INVALID,
216 		 *  G_TYPE_INT, &cookie,
217 		 *  G_TYPE_INVALID
218 		 */
219 		GValue value_app = { 0, };
220 		gchar *local_error = NULL;
221 		GValue value_reason = {0, };
222 		const gchar *app;
223 		const gchar *reason;
224 		TrackerMinerMock *miner = (TrackerMinerMock *)proxy;
225 
226 		g_value_init (&value_app, G_TYPE_STRING);
227 		G_VALUE_COLLECT (&value_app, args, 0, &local_error);
228 		g_free (local_error);
229 		app = g_value_get_string (&value_app);
230 
231 		arg_type = va_arg (args, GType);
232 		g_value_init (&value_reason, G_TYPE_STRING);
233 		G_VALUE_COLLECT (&value_reason, args, 0, &local_error);
234 		g_free (local_error);
235 		reason = g_value_get_string (&value_reason);
236 
237 		tracker_miner_mock_pause (miner, app, reason);
238 
239 	} else if (g_strcmp0 (function_name, "Resume") == 0) {
240 		/*
241 		 * G_TYPE_INT, &cookie
242 		 * G_TYPE_INVALID
243 		 */
244 		TrackerMinerMock *miner = (TrackerMinerMock *)proxy;
245 		tracker_miner_mock_resume (miner);
246 
247 	} else if (g_strcmp0 (function_name, "IgnoreNextUpdate") == 0) {
248 		/* Well, ok... */
249 	} else if (g_strcmp0 (function_name, "GetProgress") == 0) {
250 		/* Whatever */
251 	} else if (g_strcmp0 (function_name, "GetStatus") == 0) {
252 		/* Whatever */
253 	} else {
254 		g_critical ("dbus_g_proxy_call '%s' unsupported", function_name);
255 	}
256 
257 	va_end (args);
258 	return TRUE;
259 }
260 
261 
262 void
263 dbus_g_proxy_call_no_reply (DBusGProxy        *proxy,
264                             const char        *method,
265                             GType              first_arg_type,
266                             ...)
267 {
268 }
269 
270 
271 void
272 dbus_g_connection_unref (DBusGConnection *conn)
273 {
274 	/* It is an EmptyGObject */
275 	g_object_unref (conn);
276 }
277 
278 #endif