tracker-0.16.2/tests/libtracker-miner/tracker-monitor-test.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found tracker-monitor-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) 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 #include <unistd.h>
  22 
  23 #include <glib.h>
  24 #include <glib/gstdio.h>
  25 
  26 /* Special case, the monitor header is not normally exported */
  27 #include <libtracker-miner/tracker-monitor.h>
  28 
  29 /* -------------- COMMON FOR ALL FILE EVENT TESTS ----------------- */
  30 
  31 #define TEST_TIMEOUT 5 /* seconds */
  32 
  33 typedef enum {
  34 	MONITOR_SIGNAL_NONE                   = 0,
  35 	MONITOR_SIGNAL_ITEM_CREATED           = 1 << 0,
  36 	MONITOR_SIGNAL_ITEM_UPDATED           = 1 << 1,
  37 	MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED = 1 << 2,
  38 	MONITOR_SIGNAL_ITEM_DELETED           = 1 << 3,
  39 	MONITOR_SIGNAL_ITEM_MOVED_FROM        = 1 << 4,
  40 	MONITOR_SIGNAL_ITEM_MOVED_TO          = 1 << 5
  41 } MonitorSignal;
  42 
  43 /* Fixture object type */
  44 typedef struct {
  45 	TrackerMonitor *monitor;
  46 	GFile *monitored_directory_file;
  47 	gchar *monitored_directory;
  48 	gchar *not_monitored_directory;
  49 	GHashTable *events;
  50 	GMainLoop *main_loop;
  51 } TrackerMonitorTestFixture;
  52 
  53 static void
  54 add_event (GHashTable    *events,
  55            GFile         *file,
  56            MonitorSignal  new_event)
  57 {
  58 	gpointer previous_file;
  59 	gpointer previous_mask;
  60 
  61 	/* Lookup file in HT */
  62 	if (g_hash_table_lookup_extended (events,
  63 	                                  file,
  64 	                                  &previous_file,
  65 	                                  &previous_mask)) {
  66 		guint mask;
  67 
  68 		mask = GPOINTER_TO_UINT (previous_mask);
  69 		mask |= new_event;
  70 		g_hash_table_replace (events,
  71 		                      g_object_ref (previous_file),
  72 		                      GUINT_TO_POINTER (mask));
  73 	}
  74 }
  75 
  76 static void
  77 test_monitor_events_created_cb (TrackerMonitor *monitor,
  78                                 GFile          *file,
  79                                 gboolean        is_directory,
  80                                 gpointer        user_data)
  81 {
  82 	gchar *path;
  83 
  84 	g_assert (file != NULL);
  85 	path = g_file_get_path (file);
  86 	g_assert (path != NULL);
  87 
  88 	g_debug ("***** '%s' (%s) (CREATED)",
  89 	         path,
  90 	         is_directory ? "DIR" : "FILE");
  91 
  92 	g_free (path);
  93 
  94 	add_event ((GHashTable *) user_data,
  95 	           file,
  96 	           MONITOR_SIGNAL_ITEM_CREATED);
  97 }
  98 
  99 static void
 100 test_monitor_events_updated_cb (TrackerMonitor *monitor,
 101                                 GFile          *file,
 102                                 gboolean        is_directory,
 103                                 gpointer        user_data)
 104 {
 105 	gchar *path;
 106 
 107 	g_assert (file != NULL);
 108 	path = g_file_get_path (file);
 109 	g_assert (path != NULL);
 110 
 111 	g_debug ("***** '%s' (%s) (UPDATED)",
 112 	         path,
 113 	         is_directory ? "DIR" : "FILE");
 114 
 115 	g_free (path);
 116 
 117 	add_event ((GHashTable *) user_data,
 118 	           file,
 119 	           MONITOR_SIGNAL_ITEM_UPDATED);
 120 }
 121 
 122 static void
 123 test_monitor_events_attribute_updated_cb (TrackerMonitor *monitor,
 124                                           GFile          *file,
 125                                           gboolean        is_directory,
 126                                           gpointer        user_data)
 127 {
 128 	gchar *path;
 129 
 130 	g_assert (file != NULL);
 131 	path = g_file_get_path (file);
 132 	g_assert (path != NULL);
 133 
 134 	g_debug ("***** '%s' (%s) (ATRIBUTE UPDATED)",
 135 	         path,
 136 	         is_directory ? "DIR" : "FILE");
 137 
 138 	g_free (path);
 139 
 140 	add_event ((GHashTable *) user_data,
 141 	           file,
 142 	           MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED);
 143 }
 144 
 145 static void
 146 test_monitor_events_deleted_cb (TrackerMonitor *monitor,
 147                                 GFile          *file,
 148                                 gboolean        is_directory,
 149                                 gpointer        user_data)
 150 {
 151 	gchar *path;
 152 
 153 	g_assert (file != NULL);
 154 	path = g_file_get_path (file);
 155 	g_assert (path != NULL);
 156 
 157 	g_debug ("***** '%s' (%s) (DELETED)",
 158 	         path,
 159 	         is_directory ? "DIR" : "FILE");
 160 
 161 	g_free (path);
 162 
 163 	add_event ((GHashTable *) user_data,
 164 	           file,
 165 	           MONITOR_SIGNAL_ITEM_DELETED);
 166 }
 167 
 168 static void
 169 test_monitor_events_moved_cb (TrackerMonitor *monitor,
 170                               GFile          *file,
 171                               GFile          *other_file,
 172                               gboolean        is_directory,
 173                               gboolean        is_source_monitored,
 174                               gpointer        user_data)
 175 {
 176 	gchar *path;
 177 	gchar *other_path;
 178 
 179 	g_assert (file != NULL);
 180 	path = g_file_get_path (other_file);
 181 	other_path = g_file_get_path (other_file);
 182 
 183 	g_debug ("***** '%s'->'%s' (%s) (MOVED) (source %smonitored)",
 184 	         path,
 185 	         other_path,
 186 	         is_directory ? "DIR" : "FILE",
 187 	         is_source_monitored ? "" : "not ");
 188 
 189 	g_free (other_path);
 190 	g_free (path);
 191 
 192 	/* Add event to the files */
 193 	add_event ((GHashTable *) user_data,
 194 	           file,
 195 	           MONITOR_SIGNAL_ITEM_MOVED_FROM);
 196 	add_event ((GHashTable *) user_data,
 197 	           other_file,
 198 	           MONITOR_SIGNAL_ITEM_MOVED_TO);
 199 }
 200 
 201 static void
 202 test_monitor_common_setup (TrackerMonitorTestFixture *fixture,
 203                            gconstpointer              data)
 204 {
 205 	gchar *basename;
 206 
 207 	/* Create HT to store received events */
 208 	fixture->events = g_hash_table_new_full (g_file_hash,
 209 	                                         (GEqualFunc) g_file_equal,
 210 	                                         NULL,
 211 	                                         NULL);
 212 
 213 	/* Create and setup the tracker monitor */
 214 	fixture->monitor = tracker_monitor_new ();
 215 	g_assert (fixture->monitor != NULL);
 216 
 217 	g_signal_connect (fixture->monitor, "item-created",
 218 	                  G_CALLBACK (test_monitor_events_created_cb),
 219 	                  fixture->events);
 220 	g_signal_connect (fixture->monitor, "item-updated",
 221 	                  G_CALLBACK (test_monitor_events_updated_cb),
 222 	                  fixture->events);
 223 	g_signal_connect (fixture->monitor, "item-attribute-updated",
 224 	                  G_CALLBACK (test_monitor_events_attribute_updated_cb),
 225 	                  fixture->events);
 226 	g_signal_connect (fixture->monitor, "item-deleted",
 227 	                  G_CALLBACK (test_monitor_events_deleted_cb),
 228 	                  fixture->events);
 229 	g_signal_connect (fixture->monitor, "item-moved",
 230 	                  G_CALLBACK (test_monitor_events_moved_cb),
 231 	                  fixture->events);
 232 
 233 	/* Initially, set it disabled */
 234 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 235 
 236 	/* Create a temp directory to monitor in the test */
 237 	basename = g_strdup_printf ("monitor-test-%d", getpid ());
 238 	fixture->monitored_directory = g_build_path (G_DIR_SEPARATOR_S, g_get_tmp_dir (), basename, NULL);
 239 	fixture->monitored_directory_file = g_file_new_for_path (fixture->monitored_directory);
 240 	g_assert (fixture->monitored_directory_file != NULL);
 241 	g_assert_cmpint (g_file_make_directory_with_parents (fixture->monitored_directory_file, NULL, NULL), ==, TRUE);
 242 	g_free (basename);
 243 	g_assert_cmpint (tracker_monitor_add (fixture->monitor, fixture->monitored_directory_file), ==, TRUE);
 244 	g_assert_cmpint (tracker_monitor_get_count (fixture->monitor), ==, 1);
 245 
 246 	/* Setup also not-monitored directory */
 247 	fixture->not_monitored_directory = g_strdup (g_get_tmp_dir ());
 248 
 249 	/* Create new main loop */
 250 	fixture->main_loop = g_main_loop_new (NULL, FALSE);
 251 	g_assert (fixture->main_loop != NULL);
 252 }
 253 
 254 static void
 255 test_monitor_common_teardown (TrackerMonitorTestFixture *fixture,
 256                               gconstpointer              data)
 257 {
 258 	/* Remove the main loop */
 259 	g_main_loop_unref (fixture->main_loop);
 260 
 261 	/* Cleanup monitor */
 262 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, fixture->monitored_directory_file), ==, TRUE);
 263 	g_assert_cmpint (tracker_monitor_get_count (fixture->monitor), ==, 0);
 264 
 265 	/* Destroy monitor */
 266 	g_assert (fixture->monitor != NULL);
 267 	g_object_unref (fixture->monitor);
 268 
 269 	/* Remove the HT of events */
 270 	g_hash_table_destroy (fixture->events);
 271 
 272 	/* Remove base test directories */
 273 	g_assert (fixture->monitored_directory_file != NULL);
 274 	g_assert (fixture->monitored_directory != NULL);
 275 	g_assert_cmpint (g_file_delete (fixture->monitored_directory_file, NULL, NULL), ==, TRUE);
 276 	g_object_unref (fixture->monitored_directory_file);
 277 	g_free (fixture->monitored_directory);
 278 
 279 	g_assert (fixture->not_monitored_directory != NULL);
 280 	g_free (fixture->not_monitored_directory);
 281 }
 282 
 283 static void
 284 create_directory (const gchar  *parent,
 285                   const gchar  *directory_name,
 286                   GFile       **outfile)
 287 {
 288 	GFile *dirfile;
 289 	gchar *path;
 290 
 291 	path = g_build_path (G_DIR_SEPARATOR_S, parent, directory_name, NULL);
 292 	dirfile = g_file_new_for_path (path);
 293 	g_assert (dirfile != NULL);
 294 	g_assert_cmpint (g_file_make_directory_with_parents (dirfile, NULL, NULL), ==, TRUE);
 295 	if (outfile) {
 296 		*outfile = dirfile;
 297 	} else {
 298 		g_object_unref (dirfile);
 299 	}
 300 	g_free (path);
 301 }
 302 
 303 static void
 304 set_file_contents (const gchar  *directory,
 305                    const gchar  *filename,
 306                    const gchar  *contents,
 307                    GFile       **outfile)
 308 {
 309 	FILE *file;
 310 	size_t length;
 311 	gchar *file_path;
 312 
 313 	g_assert (directory != NULL);
 314 	g_assert (filename != NULL);
 315 	g_assert (contents != NULL);
 316 
 317 	file_path = g_build_filename (directory, filename, NULL);
 318 
 319 	file = g_fopen (file_path, "wb");
 320 	g_assert (file != NULL);
 321 	length = strlen (contents);
 322 	g_assert_cmpint (fwrite (contents, 1, length, file), >=, length);
 323 	g_assert_cmpint (fflush (file), ==, 0);
 324 	g_assert_cmpint (fclose (file), !=, EOF);
 325 
 326 	if (outfile) {
 327 		*outfile = g_file_new_for_path (file_path);
 328 	}
 329 	g_free (file_path);
 330 }
 331 
 332 static void
 333 set_file_permissions (const gchar  *directory,
 334                       const gchar  *filename,
 335                       gint          permissions)
 336 {
 337 	gchar *file_path;
 338 
 339 	g_assert (directory != NULL);
 340 	g_assert (filename != NULL);
 341 
 342 	file_path = g_build_filename (directory, filename, NULL);
 343 	g_assert_cmpint (g_chmod (file_path, permissions), ==, 0);
 344 	g_free (file_path);
 345 }
 346 
 347 static void
 348 print_file_events_cb (gpointer key,
 349                       gpointer value,
 350                       gpointer user_data)
 351 {
 352 	GFile *file;
 353 	guint events;
 354 	gchar *uri;
 355 
 356 	file = key;
 357 	events = GPOINTER_TO_UINT (value);
 358 	uri = g_file_get_uri (file);
 359 
 360 	g_print ("Signals received for '%s': \n"
 361 	         "   CREATED:           %s\n"
 362 	         "   UPDATED:           %s\n"
 363 	         "   ATTRIBUTE UPDATED: %s\n"
 364 	         "   DELETED:           %s\n"
 365 	         "   MOVED_FROM:        %s\n"
 366 	         "   MOVED_TO:          %s\n",
 367 	         uri,
 368 	         events & MONITOR_SIGNAL_ITEM_CREATED ? "yes" : "no",
 369 	         events & MONITOR_SIGNAL_ITEM_UPDATED ? "yes" : "no",
 370 	         events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED ? "yes" : "no",
 371 	         events & MONITOR_SIGNAL_ITEM_DELETED ? "yes" : "no",
 372 	         events & MONITOR_SIGNAL_ITEM_MOVED_FROM ? "yes" : "no",
 373 	         events & MONITOR_SIGNAL_ITEM_MOVED_TO ? "yes" : "no");
 374 
 375 	g_free (uri);
 376 }
 377 
 378 static gboolean
 379 timeout_cb (gpointer data)
 380 {
 381 	g_main_loop_quit ((GMainLoop *) data);
 382 	return FALSE;
 383 }
 384 
 385 static void
 386 events_wait (TrackerMonitorTestFixture *fixture)
 387 {
 388 	/* Setup timeout to stop the main loop after some seconds */
 389 	g_timeout_add_seconds (TEST_TIMEOUT, timeout_cb, fixture->main_loop);
 390 	g_debug ("Waiting %u seconds for monitor events...", TEST_TIMEOUT);
 391 	g_main_loop_run (fixture->main_loop);
 392 
 393 	/* Print signals received for each file */
 394 	g_hash_table_foreach (fixture->events, print_file_events_cb, NULL);
 395 }
 396 
 397 /* ----------------------------- FILE EVENT TESTS --------------------------------- */
 398 
 399 static void
 400 test_monitor_file_event_created (TrackerMonitorTestFixture *fixture,
 401                                  gconstpointer              data)
 402 {
 403 	GFile *test_file;
 404 	guint file_events;
 405 
 406 	/* Set up environment */
 407 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 408 
 409 	/* Create file to test with */
 410 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
 411 	g_assert (test_file != NULL);
 412 	g_hash_table_insert (fixture->events,
 413 	                     g_object_ref (test_file),
 414 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 415 
 416 	/* Wait for events */
 417 	events_wait (fixture);
 418 
 419 	/* Get events in the file */
 420 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 421 
 422 	/* Fail if we didn't get the CREATE signal */
 423 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), >, 0);
 424 
 425 	/* Fail if we got a MOVE or DELETE signal */
 426 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 427 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 428 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 429 
 430 	/* A single CREATED event should now never trigger an UPDATED event */
 431 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 432 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 433 
 434 	/* Cleanup environment */
 435 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 436 
 437 	/* Remove the test file */
 438 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 439 	g_object_unref (test_file);
 440 }
 441 
 442 static void
 443 test_monitor_file_event_updated (TrackerMonitorTestFixture *fixture,
 444                                  gconstpointer              data)
 445 {
 446 	GFile *test_file;
 447 	guint file_events;
 448 
 449 	/* Create file to test with, before setting up environment */
 450 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", NULL);
 451 
 452 	/* Set up environment */
 453 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 454 
 455 	/* Now, trigger update of the already created file */
 456 	set_file_contents (fixture->monitored_directory, "created.txt", "barrrr", &test_file);
 457 	g_assert (test_file != NULL);
 458 	g_hash_table_insert (fixture->events,
 459 	                     g_object_ref (test_file),
 460 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 461 
 462 	/* Wait for events */
 463 	events_wait (fixture);
 464 
 465 	/* Get events in the file */
 466 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 467 
 468 	/* Fail if we didn't get the UPDATE signal */
 469 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), >, 0);
 470 
 471 	/* Fail if we got a CREATE, MOVE or DELETE signal */
 472 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 473 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 474 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 475 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 476 
 477 	/* Cleanup environment */
 478 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 479 
 480 	/* Remove the test file */
 481 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 482 	g_object_unref (test_file);
 483 }
 484 
 485 static void
 486 test_monitor_file_event_attribute_updated (TrackerMonitorTestFixture *fixture,
 487                                            gconstpointer              data)
 488 {
 489 	GFile *test_file;
 490 	guint file_events;
 491 
 492 	/* Create file to test with, before setting up environment */
 493 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
 494 	g_assert (test_file != NULL);
 495 
 496 	/* Set up environment */
 497 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 498 
 499 	/* Now, trigger attribute update of the already created file */
 500 	set_file_permissions (fixture->monitored_directory,
 501 	                      "created.txt",
 502 	                      S_IRWXU);
 503 
 504 	g_hash_table_insert (fixture->events,
 505 	                     g_object_ref (test_file),
 506 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 507 
 508 	/* Wait for events */
 509 	events_wait (fixture);
 510 
 511 	/* Get events in the file */
 512 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 513 
 514 	/* Fail if we didn't get the ATTRIBUTE UPDATE signal */
 515 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), >, 0);
 516 
 517 	/* Fail if we got a UPDATE, CREATE, MOVE or DELETE signal */
 518 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 519 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 520 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 521 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 522 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 523 
 524 	/* Cleanup environment */
 525 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 526 
 527 	/* Remove the test file */
 528 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 529 	g_object_unref (test_file);
 530 }
 531 
 532 static void
 533 test_monitor_file_event_deleted (TrackerMonitorTestFixture *fixture,
 534                                  gconstpointer              data)
 535 {
 536 	GFile *test_file;
 537 	guint file_events;
 538 
 539 	/* Create file to test with, before setting up environment */
 540 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
 541 	g_assert (test_file != NULL);
 542 
 543 	/* Set up environment */
 544 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 545 
 546 	/* Now, remove file */
 547 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 548 	g_hash_table_insert (fixture->events,
 549 	                     g_object_ref (test_file),
 550 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 551 
 552 	/* Wait for events */
 553 	events_wait (fixture);
 554 
 555 	/* Get events in the file */
 556 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 557 
 558 	/* Fail if we didn't get the DELETED signal */
 559 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), >, 0);
 560 
 561 	/* Fail if we got a CREATE, UDPATE or MOVE signal */
 562 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 563 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 564 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 565 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 566 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 567 
 568 	/* Cleanup environment */
 569 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 570 	g_object_unref (test_file);
 571 }
 572 
 573 static void
 574 test_monitor_file_event_moved_to_monitored (TrackerMonitorTestFixture *fixture,
 575                                             gconstpointer              data)
 576 {
 577 	GFile *source_file;
 578 	gchar *source_path;
 579 	GFile *dest_file;
 580 	gchar *dest_path;
 581 	guint file_events;
 582 
 583 	/* Create file to test with, before setting up environment */
 584 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &source_file);
 585 	g_assert (source_file != NULL);
 586 
 587 	/* Set up environment */
 588 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 589 
 590 	/* Now, rename the file */
 591 	source_path = g_file_get_path (source_file);
 592 	dest_path = g_build_filename (fixture->monitored_directory, "renamed.txt", NULL);
 593 	dest_file = g_file_new_for_path (dest_path);
 594 	g_assert (dest_file != NULL);
 595 
 596 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
 597 
 598 	g_hash_table_insert (fixture->events,
 599 	                     g_object_ref (source_file),
 600 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 601 	g_hash_table_insert (fixture->events,
 602 	                     g_object_ref (dest_file),
 603 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 604 
 605 	/* Wait for events */
 606 	events_wait (fixture);
 607 
 608 	/* Get events in the source file */
 609 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_file));
 610 	/* Fail if we didn't get the MOVED_FROM signal */
 611 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
 612 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE_TO signal */
 613 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 614 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 615 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 616 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 617 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 618 
 619 	/* Get events in the dest file */
 620 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_file));
 621 	/* Fail if we didn't get the MOVED_TO signal */
 622 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
 623 	/* Fail if we got a CREATE, DELETE or MOVE_FROM signal (UPDATE may actually be possible) */
 624 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 625 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 626 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 627 
 628 	/* Cleanup environment */
 629 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 630 	g_assert_cmpint (g_file_delete (dest_file, NULL, NULL), ==, TRUE);
 631 	g_object_unref (source_file);
 632 	g_object_unref (dest_file);
 633 	g_free (source_path);
 634 	g_free (dest_path);
 635 }
 636 
 637 static void
 638 test_monitor_file_event_moved_to_not_monitored (TrackerMonitorTestFixture *fixture,
 639                                                 gconstpointer              data)
 640 {
 641 	GFile *source_file;
 642 	gchar *source_path;
 643 	GFile *dest_file;
 644 	gchar *dest_path;
 645 	guint file_events;
 646 
 647 	/* Create file to test with, before setting up environment */
 648 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &source_file);
 649 	g_assert (source_file != NULL);
 650 
 651 	/* Set up environment */
 652 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 653 
 654 	/* Now, rename the file */
 655 	source_path = g_file_get_path (source_file);
 656 	dest_path = g_build_filename (fixture->not_monitored_directory, "out.txt", NULL);
 657 	dest_file = g_file_new_for_path (dest_path);
 658 	g_assert (dest_file != NULL);
 659 
 660 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
 661 
 662 	g_hash_table_insert (fixture->events,
 663 	                     g_object_ref (source_file),
 664 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 665 	g_hash_table_insert (fixture->events,
 666 	                     g_object_ref (dest_file),
 667 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 668 
 669 	/* Wait for events */
 670 	events_wait (fixture);
 671 
 672 	/* Get events in the source file */
 673 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_file));
 674 	/* Fail if we didn't get the DELETED signal */
 675 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), >, 0);
 676 	/* Fail if we got a CREATE, UPDATE or MOVE signal */
 677 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 678 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 679 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 680 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 681 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 682 
 683 	/* Get events in the dest file */
 684 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_file));
 685 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE signal */
 686 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 687 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 688 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 689 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 690 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 691 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 692 
 693 	/* Cleanup environment */
 694 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 695 	g_assert_cmpint (g_file_delete (dest_file, NULL, NULL), ==, TRUE);
 696 	g_object_unref (source_file);
 697 	g_object_unref (dest_file);
 698 	g_free (source_path);
 699 	g_free (dest_path);
 700 }
 701 
 702 static void
 703 test_monitor_file_event_moved_from_not_monitored (TrackerMonitorTestFixture *fixture,
 704                                                   gconstpointer              data)
 705 {
 706 	GFile *source_file;
 707 	gchar *source_path;
 708 	GFile *dest_file;
 709 	gchar *dest_path;
 710 	guint file_events;
 711 
 712 	/* Create file to test with, before setting up environment */
 713 	set_file_contents (fixture->not_monitored_directory, "created.txt", "foo", &source_file);
 714 	g_assert (source_file != NULL);
 715 
 716 	/* Set up environment */
 717 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 718 
 719 	/* Now, rename the file */
 720 	source_path = g_file_get_path (source_file);
 721 	dest_path = g_build_filename (fixture->monitored_directory, "in.txt", NULL);
 722 	dest_file = g_file_new_for_path (dest_path);
 723 	g_assert (dest_file != NULL);
 724 
 725 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
 726 
 727 	g_hash_table_insert (fixture->events,
 728 	                     g_object_ref (source_file),
 729 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 730 	g_hash_table_insert (fixture->events,
 731 	                     g_object_ref (dest_file),
 732 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 733 
 734 	/* Wait for events */
 735 	events_wait (fixture);
 736 
 737 	/* Get events in the source file */
 738 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_file));
 739 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE signal */
 740 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 741 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 742 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 743 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 744 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 745 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 746 
 747 	/* Get events in the dest file */
 748 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_file));
 749 	/* Fail if we didn't get the CREATED signal */
 750 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), >, 0);
 751 	/* Fail if we got a DELETE, UPDATE or MOVE signal */
 752 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 753 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 754 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 755 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 756 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 757 
 758 	/* Cleanup environment */
 759 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 760 	g_assert_cmpint (g_file_delete (dest_file, NULL, NULL), ==, TRUE);
 761 	g_object_unref (source_file);
 762 	g_object_unref (dest_file);
 763 	g_free (source_path);
 764 	g_free (dest_path);
 765 }
 766 
 767 /* ----------------------------- FILE EVENT BLACKLISTING TESTS -------------- */
 768 
 769 static void
 770 test_monitor_file_event_blacklisting_created_updated (TrackerMonitorTestFixture *fixture,
 771                                                       gconstpointer              data)
 772 {
 773 	GFile *test_file;
 774 	guint file_events;
 775 	guint i;
 776 
 777 	/*
 778 	 * Event merging:
 779 	 *  CREATED + N*UPDATED = CREATED
 780 	 */
 781 
 782 	/* Set up environment */
 783 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 784 
 785 	/* Create file to test with, before setting up environment */
 786 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
 787 	g_assert (test_file != NULL);
 788 
 789 	/* Now, trigger 10 updates of the already created file.
 790 	 * This will generate 10 CHANGED+CHANGES_DONE_HINT events in GIO
 791 	 */
 792 	for (i=0; i<10; i++) {
 793 		set_file_contents (fixture->monitored_directory, "created.txt", "barrrr", NULL);
 794 	}
 795 
 796 	g_hash_table_insert (fixture->events,
 797 	                     g_object_ref (test_file),
 798 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 799 
 800 	/* Wait for events */
 801 	events_wait (fixture);
 802 
 803 	/* Get events in the file */
 804 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 805 
 806 	/* Fail if we didn't get the CREATED signal */
 807 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), >, 0);
 808 
 809 	/* Fail if we got a UPDATE, MOVE or DELETE signal */
 810 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 811 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 812 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 813 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 814 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 815 
 816 	/* Cleanup environment */
 817 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 818 
 819 	/* Remove the test file */
 820 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 821 	g_object_unref (test_file);
 822 }
 823 
 824 static void
 825 test_monitor_file_event_blacklisting_created_deleted (TrackerMonitorTestFixture *fixture,
 826                                                       gconstpointer              data)
 827 {
 828 	GFile *test_file;
 829 	guint file_events;
 830 
 831 	/*
 832 	 * Event merging:
 833 	 *  CREATED + DELETED = <nothing>
 834 	 */
 835 
 836 	/* Set up environment */
 837 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 838 
 839 	/* Create file to test with, before setting up environment */
 840 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
 841 	g_assert (test_file != NULL);
 842 
 843 	/* Remove the test file */
 844 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 845 
 846 	g_hash_table_insert (fixture->events,
 847 	                     g_object_ref (test_file),
 848 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 849 
 850 	/* Wait for events */
 851 	events_wait (fixture);
 852 
 853 	/* Get events in the file */
 854 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 855 
 856 	/* Fail if we got any signal */
 857 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 858 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 859 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 860 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 861 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 862 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 863 
 864 	/* Cleanup environment */
 865 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 866 
 867 	g_object_unref (test_file);
 868 }
 869 
 870 static void
 871 test_monitor_file_event_blacklisting_created_updated_deleted (TrackerMonitorTestFixture *fixture,
 872                                                               gconstpointer              data)
 873 {
 874 	GFile *test_file;
 875 	guint file_events;
 876 	guint i;
 877 
 878 	/*
 879 	 * Event merging:
 880 	 *  CREATED + N*UPDATED + DELETED = <nothing>
 881 	 */
 882 
 883 	/* Set up environment */
 884 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 885 
 886 	/* Create file to test with, before setting up environment */
 887 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
 888 	g_assert (test_file != NULL);
 889 
 890 	/* Now, trigger 10 updates of the already created file.
 891 	 * This will generate 10 CHANGED+CHANGES_DONE_HINT events in GIO
 892 	 */
 893 	for (i=0; i<10; i++) {
 894 		set_file_contents (fixture->monitored_directory, "created.txt", "barrrr", NULL);
 895 	}
 896 
 897 	/* Remove the test file */
 898 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
 899 
 900 	g_hash_table_insert (fixture->events,
 901 	                     g_object_ref (test_file),
 902 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 903 
 904 	/* Wait for events */
 905 	events_wait (fixture);
 906 
 907 	/* Get events in the file */
 908 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
 909 
 910 	/* Fail if we got any signal */
 911 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 912 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 913 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 914 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 915 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 916 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 917 
 918 	/* Cleanup environment */
 919 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 920 
 921 	g_object_unref (test_file);
 922 }
 923 
 924 static void
 925 test_monitor_file_event_blacklisting_created_moved (TrackerMonitorTestFixture *fixture,
 926                                                     gconstpointer              data)
 927 {
 928 	GFile *source_file;
 929 	gchar *source_path;
 930 	GFile *dest_file;
 931 	gchar *dest_path;
 932 	guint file_events;
 933 
 934 	/*
 935 	 * Event merging:
 936 	 *  CREATED(A) + MOVED(A->B) = CREATED(B)
 937 	 */
 938 
 939 	/* Set up environment */
 940 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
 941 
 942 	/* Create file to test with, before setting up environment */
 943 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &source_file);
 944 	g_assert (source_file != NULL);
 945 
 946 	/* Now, rename the file */
 947 	source_path = g_file_get_path (source_file);
 948 	dest_path = g_build_filename (fixture->monitored_directory, "renamed.txt", NULL);
 949 	dest_file = g_file_new_for_path (dest_path);
 950 	g_assert (dest_file != NULL);
 951 
 952 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
 953 
 954 	g_hash_table_insert (fixture->events,
 955 	                     g_object_ref (source_file),
 956 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 957 	g_hash_table_insert (fixture->events,
 958 	                     g_object_ref (dest_file),
 959 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
 960 
 961 	/* Wait for events */
 962 	events_wait (fixture);
 963 
 964 	/* Get events in the source file */
 965 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_file));
 966 
 967 	/* Fail if we got ANY event */
 968 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 969 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
 970 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 971 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 972 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 973 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 974 
 975 	/* Get events in the dest file */
 976 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_file));
 977 
 978 	/* Fail if we didn't get the UPDATED signal */
 979 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), >, 0);
 980 
 981 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE signal */
 982 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
 983 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
 984 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
 985 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
 986 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
 987 
 988 	/* Cleanup environment */
 989 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
 990 	g_assert_cmpint (g_file_delete (dest_file, NULL, NULL), ==, TRUE);
 991 	g_object_unref (source_file);
 992 	g_object_unref (dest_file);
 993 	g_free (source_path);
 994 	g_free (dest_path);
 995 }
 996 
 997 static void
 998 test_monitor_file_event_blacklisting_updated_deleted (TrackerMonitorTestFixture *fixture,
 999                                                       gconstpointer              data)
1000 {
1001 	GFile *test_file;
1002 	guint file_events;
1003 	guint i;
1004 
1005 	/*
1006 	 * Event merging:
1007 	 *  N*UPDATED + DELETED = DELETED
1008 	 */
1009 
1010 	/* Create file to test with, before setting up environment */
1011 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &test_file);
1012 	g_assert (test_file != NULL);
1013 
1014 	/* Set up environment */
1015 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1016 
1017 	/* Now, trigger 10 updates of the already created file.
1018 	 * This will generate 10 CHANGED+CHANGES_DONE_HINT events in GIO
1019 	 */
1020 	for (i=0; i<10; i++) {
1021 		set_file_contents (fixture->monitored_directory, "created.txt", "barrrr", NULL);
1022 	}
1023 
1024 	/* Remove the test file */
1025 	g_assert_cmpint (g_file_delete (test_file, NULL, NULL), ==, TRUE);
1026 
1027 	g_hash_table_insert (fixture->events,
1028 	                     g_object_ref (test_file),
1029 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1030 
1031 	/* Wait for events */
1032 	events_wait (fixture);
1033 
1034 	/* Get events in the file */
1035 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_file));
1036 
1037 	/* Fail if we didn't get the DELETED signal */
1038 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), >, 0);
1039 
1040 	/* Fail if we got any signal */
1041 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1042 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1043 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1044 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1045 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1046 
1047 	/* Cleanup environment */
1048 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1049 
1050 	g_object_unref (test_file);
1051 }
1052 
1053 static void
1054 test_monitor_file_event_blacklisting_updated_moved (TrackerMonitorTestFixture *fixture,
1055                                                     gconstpointer              data)
1056 {
1057 	GFile *source_file;
1058 	gchar *source_path;
1059 	GFile *dest_file;
1060 	gchar *dest_path;
1061 	guint file_events;
1062 
1063 	/*
1064 	 * Event merging:
1065 	 *  UPDATED(A) + MOVED(A->B) = MOVED(A->B) + UPDATED(B)
1066 	 */
1067 
1068 	/* Create file to test with, before setting up environment */
1069 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &source_file);
1070 	g_assert (source_file != NULL);
1071 
1072 	/* Set up environment */
1073 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1074 
1075 	/* Update the file */
1076 	set_file_contents (fixture->monitored_directory, "created.txt", "barrrr", NULL);
1077 
1078 	/* Now, rename the file */
1079 	source_path = g_file_get_path (source_file);
1080 	dest_path = g_build_filename (fixture->monitored_directory, "renamed.txt", NULL);
1081 	dest_file = g_file_new_for_path (dest_path);
1082 	g_assert (dest_file != NULL);
1083 
1084 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1085 
1086 	g_hash_table_insert (fixture->events,
1087 	                     g_object_ref (source_file),
1088 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1089 	g_hash_table_insert (fixture->events,
1090 	                     g_object_ref (dest_file),
1091 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1092 
1093 	/* Wait for events */
1094 	events_wait (fixture);
1095 
1096 	/* Get events in the source file */
1097 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_file));
1098 
1099 	/* Fail if we didn't get the MOVED_FROM event */
1100 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
1101 
1102 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1103 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1104 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1105 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1106 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1107 
1108 	/* Get events in the dest file */
1109 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_file));
1110 
1111 	/* Fail if we didn't get the MOVED_TO and UPDATED signals */
1112 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
1113 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), >, 0);
1114 
1115 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE signal */
1116 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1117 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1118 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1119 
1120 	/* Cleanup environment */
1121 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1122 	g_assert_cmpint (g_file_delete (dest_file, NULL, NULL), ==, TRUE);
1123 	g_object_unref (source_file);
1124 	g_object_unref (dest_file);
1125 	g_free (source_path);
1126 	g_free (dest_path);
1127 }
1128 
1129 static void
1130 test_monitor_file_event_blacklisting_attribute_updated_moved (TrackerMonitorTestFixture *fixture,
1131                                                               gconstpointer              data)
1132 {
1133 	GFile *source_file;
1134 	gchar *source_path;
1135 	GFile *dest_file;
1136 	gchar *dest_path;
1137 	guint file_events;
1138 
1139 	/*
1140 	 * Event merging:
1141 	 *  ATTRIBUTE_UPDATED(A) + MOVED(A->B) = MOVED(A->B) + UPDATED(B)
1142 	 */
1143 
1144 	/* Create file to test with, before setting up environment */
1145 	set_file_contents (fixture->monitored_directory, "created.txt", "foo", &source_file);
1146 	g_assert (source_file != NULL);
1147 
1148 	/* Set up environment */
1149 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1150 
1151 	/* Now, trigger attribute update of the already created file */
1152 	set_file_permissions (fixture->monitored_directory,
1153 	                      "created.txt",
1154 	                      S_IRWXU);
1155 	set_file_contents (fixture->monitored_directory, "created.txt", "barrrr", NULL);
1156 
1157 	/* Now, rename the file */
1158 	source_path = g_file_get_path (source_file);
1159 	dest_path = g_build_filename (fixture->monitored_directory, "renamed.txt", NULL);
1160 	dest_file = g_file_new_for_path (dest_path);
1161 	g_assert (dest_file != NULL);
1162 
1163 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1164 
1165 	g_hash_table_insert (fixture->events,
1166 	                     g_object_ref (source_file),
1167 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1168 	g_hash_table_insert (fixture->events,
1169 	                     g_object_ref (dest_file),
1170 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1171 
1172 	/* Wait for events */
1173 	events_wait (fixture);
1174 
1175 	/* Get events in the source file */
1176 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_file));
1177 
1178 	/* Fail if we didn't get the MOVED_FROM event */
1179 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
1180 
1181 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1182 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1183 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1184 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1185 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1186 
1187 	/* Get events in the dest file */
1188 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_file));
1189 
1190 	/* Fail if we didn't get the UPDATED signal */
1191 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
1192 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), >, 0);
1193 
1194 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE signal */
1195 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1196 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1197 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1198 
1199 	/* Cleanup environment */
1200 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1201 	g_assert_cmpint (g_file_delete (dest_file, NULL, NULL), ==, TRUE);
1202 	g_object_unref (source_file);
1203 	g_object_unref (dest_file);
1204 	g_free (source_path);
1205 	g_free (dest_path);
1206 }
1207 
1208 /* ----------------------------- DIRECTORY EVENT TESTS --------------------------------- */
1209 
1210 static void
1211 test_monitor_directory_event_created (TrackerMonitorTestFixture *fixture,
1212                                       gconstpointer              data)
1213 {
1214 	GFile *test_dir;
1215 	guint file_events;
1216 
1217 	/* Set up environment */
1218 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1219 
1220 	/* Create directory to test with */
1221 	create_directory (fixture->monitored_directory, "foo", &test_dir);
1222 	g_assert (test_dir != NULL);
1223 	g_hash_table_insert (fixture->events,
1224 	                     g_object_ref (test_dir),
1225 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1226 
1227 	/* Wait for events */
1228 	events_wait (fixture);
1229 
1230 	/* Get events in the file */
1231 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, test_dir));
1232 
1233 	/* Fail if we didn't get the CREATE signal */
1234 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), >, 0);
1235 
1236 	/* Fail if we got a MOVE or DELETE signal (update may actually happen) */
1237 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1238 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1239 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1240 
1241 	/* Cleanup environment */
1242 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1243 
1244 	/* Remove the test dir */
1245 	g_assert_cmpint (g_file_delete (test_dir, NULL, NULL), ==, TRUE);
1246 	g_object_unref (test_dir);
1247 }
1248 
1249 static void
1250 test_monitor_directory_event_deleted (TrackerMonitorTestFixture *fixture,
1251 				      gconstpointer              data)
1252 {
1253 	GFile *source_dir;
1254 	gchar *source_path;
1255 	guint file_events;
1256 
1257 	/* Create directory to test with in a monitored place,
1258 	 * before setting up the environment */
1259 	create_directory (fixture->monitored_directory, "foo", &source_dir);
1260 	source_path = g_file_get_path (source_dir);
1261 	g_assert (source_dir != NULL);
1262 
1263 	/* Set to monitor the new dir also */
1264 	g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
1265 
1266 	/* Set up environment */
1267 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1268 
1269 	/* Now, delete the directory  */
1270 	g_assert_cmpint (g_file_delete (source_dir, NULL, NULL), ==, TRUE);
1271 
1272 	g_hash_table_insert (fixture->events,
1273 	                     g_object_ref (source_dir),
1274 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1275 
1276 	/* Wait for events */
1277 	events_wait (fixture);
1278 
1279 	/* Get events in the source dir */
1280 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
1281 	/* Fail if we didn't get DELETED signal */
1282 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), >, 0);
1283 	/* Fail if we got a CREATEd, UPDATED, MOVED_FROM or MOVED_TO signal */
1284 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1285 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1286 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1287 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1288 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1289 
1290 	/* Cleanup environment */
1291 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1292 	g_object_unref (source_dir);
1293 	g_free (source_path);
1294 }
1295 
1296 
1297 static void
1298 test_monitor_directory_event_moved_to_monitored (TrackerMonitorTestFixture *fixture,
1299                                                  gconstpointer              data)
1300 {
1301 	GFile *source_dir;
1302 	gchar *source_path;
1303 	GFile *dest_dir;
1304 	gchar *dest_path;
1305 	GFile *file_in_source_dir;
1306 	GFile *file_in_dest_dir;
1307 	gchar *file_in_dest_dir_path;
1308 	guint file_events;
1309 
1310 	/* Create directory to test with, before setting up the environment */
1311 	create_directory (fixture->monitored_directory, "foo", &source_dir);
1312 	source_path = g_file_get_path (source_dir);
1313 	g_assert (source_dir != NULL);
1314 
1315 	/* Add some file to the new dir */
1316 	set_file_contents (source_path, "lalala.txt", "whatever", &file_in_source_dir);
1317 
1318 	/* Set up environment */
1319 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1320 
1321 	/* Set to monitor the new dir also */
1322 	g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
1323 
1324 	/* Get final path of the file */
1325 	file_in_dest_dir_path = g_build_path (G_DIR_SEPARATOR_S,
1326 	                                      fixture->monitored_directory,
1327 	                                      "renamed",
1328 	                                      "lalala.txt",
1329 	                                      NULL);
1330 	file_in_dest_dir = g_file_new_for_path (file_in_dest_dir_path);
1331 	g_assert (file_in_dest_dir != NULL);
1332 
1333 	/* Now, rename the directory */
1334 	dest_dir = g_file_get_parent (file_in_dest_dir);
1335 	dest_path = g_file_get_path (dest_dir);
1336 
1337 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1338 
1339 	g_hash_table_insert (fixture->events,
1340 	                     g_object_ref (source_dir),
1341 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1342 	g_hash_table_insert (fixture->events,
1343 	                     g_object_ref (dest_dir),
1344 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1345 	g_hash_table_insert (fixture->events,
1346 	                     g_object_ref (file_in_dest_dir),
1347 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1348 	g_hash_table_insert (fixture->events,
1349 	                     g_object_ref (file_in_source_dir),
1350 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1351 
1352 	/* Wait for events */
1353 	events_wait (fixture);
1354 
1355 	/* Get events in the source dir */
1356 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
1357 	/* Fail if we didn't get the MOVED_FROM signal */
1358 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
1359 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE_TO signal */
1360 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1361 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1362 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1363 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1364 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1365 
1366 	/* Get events in the dest file */
1367 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_dir));
1368 	/* Fail if we didn't get the MOVED_TO signal */
1369 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
1370 	/* Fail if we got a CREATE, DELETE or MOVE_FROM signal (UPDATE may actually be possible) */
1371 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1372 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1373 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1374 
1375 	/* Get events in the file in source dir */
1376 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_source_dir));
1377 	/* Fail if we got ANY signal */
1378 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1379 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1380 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1381 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1382 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1383 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1384 
1385 	/* Get events in the file in dest dir */
1386 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_dest_dir));
1387 	/* Fail if we got ANY signal */
1388 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1389 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1390 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1391 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1392 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1393 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1394 
1395 
1396 	/* Cleanup environment */
1397 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1398 	/* Since tracker 0.9.33, monitors are NOT moved to the new location directly when the
1399 	 * directory is moved, that is done by the upper layers.
1400 	 * Note that monitor is now in dest_dir */
1401 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, source_dir), ==, TRUE);
1402 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), !=, TRUE);
1403 	g_assert_cmpint (g_file_delete (file_in_dest_dir, NULL, NULL), ==, TRUE);
1404 	g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
1405 	g_object_unref (source_dir);
1406 	g_object_unref (file_in_source_dir);
1407 	g_object_unref (dest_dir);
1408 	g_object_unref (file_in_dest_dir);
1409 	g_free (source_path);
1410 	g_free (file_in_dest_dir_path);
1411 	g_free (dest_path);
1412 }
1413 
1414 /* Same test as before, BUT, creating a new file in the directory while it's being monitored.
1415  * In this case, GIO dumps an extra DELETE event after the MOVE
1416  */
1417 static void
1418 test_monitor_directory_event_moved_to_monitored_after_file_create (TrackerMonitorTestFixture *fixture,
1419                                                                    gconstpointer              data)
1420 {
1421 	GFile *source_dir;
1422 	gchar *source_path;
1423 	GFile *dest_dir;
1424 	gchar *dest_path;
1425 	GFile *file_in_source_dir;
1426 	GFile *file_in_dest_dir;
1427 	gchar *file_in_dest_dir_path;
1428 	guint file_events;
1429 
1430 	/* Create directory to test with, before setting up the environment */
1431 	create_directory (fixture->monitored_directory, "foo", &source_dir);
1432 	source_path = g_file_get_path (source_dir);
1433 	g_assert (source_dir != NULL);
1434 
1435 	/* Set up environment */
1436 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1437 
1438 	/* Set to monitor the new dir also */
1439 	g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
1440 
1441 	/* Add some file to the new dir, WHILE ALREADY MONITORING */
1442 	set_file_contents (source_path, "lalala.txt", "whatever", &file_in_source_dir);
1443 
1444 	/* Get final path of the file */
1445 	file_in_dest_dir_path = g_build_path (G_DIR_SEPARATOR_S,
1446 	                                      fixture->monitored_directory,
1447 	                                      "renamed",
1448 	                                      "lalala.txt",
1449 	                                      NULL);
1450 	file_in_dest_dir = g_file_new_for_path (file_in_dest_dir_path);
1451 	g_assert (file_in_dest_dir != NULL);
1452 
1453 	/* Now, rename the directory */
1454 	dest_dir = g_file_get_parent (file_in_dest_dir);
1455 	dest_path = g_file_get_path (dest_dir);
1456 
1457 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1458 
1459 	g_hash_table_insert (fixture->events,
1460 	                     g_object_ref (source_dir),
1461 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1462 	g_hash_table_insert (fixture->events,
1463 	                     g_object_ref (dest_dir),
1464 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1465 	g_hash_table_insert (fixture->events,
1466 	                     g_object_ref (file_in_dest_dir),
1467 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1468 	g_hash_table_insert (fixture->events,
1469 	                     g_object_ref (file_in_source_dir),
1470 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1471 
1472 	/* Wait for events */
1473 	events_wait (fixture);
1474 
1475 	/* Get events in the source dir */
1476 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
1477 	/* Fail if we didn't get the MOVED_FROM signal */
1478 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
1479 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE_TO signal */
1480 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1481 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1482 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1483 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1484 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1485 
1486 	/* Get events in the dest file */
1487 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_dir));
1488 	/* Fail if we didn't get the MOVED_TO signal */
1489 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
1490 	/* Fail if we got a CREATE, DELETE or MOVE_FROM signal (UPDATE may actually be possible) */
1491 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1492 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1493 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1494 
1495 	/* Get events in the file in source dir */
1496 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_source_dir));
1497 	/* Fail if we got ANY signal != CREATED (we created the file while monitoring) */
1498 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1499 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1500 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1501 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1502 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1503 
1504 	/* Get events in the file in dest dir */
1505 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_dest_dir));
1506 	/* Fail if we got ANY signal */
1507 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1508 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1509 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1510 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1511 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1512 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1513 
1514 
1515 	/* Cleanup environment */
1516 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1517 	/* Since tracker 0.9.33, monitors are NOT moved to the new location directly when the
1518 	 * directory is moved, that is done by the upper layers.
1519 	 * Note that monitor is now in dest_dir */
1520 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, source_dir), ==, TRUE);
1521 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), !=, TRUE);
1522 	g_assert_cmpint (g_file_delete (file_in_dest_dir, NULL, NULL), ==, TRUE);
1523 	g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
1524 	g_object_unref (source_dir);
1525 	g_object_unref (file_in_source_dir);
1526 	g_object_unref (dest_dir);
1527 	g_object_unref (file_in_dest_dir);
1528 	g_free (source_path);
1529 	g_free (file_in_dest_dir_path);
1530 	g_free (dest_path);
1531 }
1532 
1533 /* Same test as before, BUT, updating an existing file in the directory while it's being monitored.
1534  * In this case, GIO dumps an extra DELETE event after the MOVE
1535  */
1536 static void
1537 test_monitor_directory_event_moved_to_monitored_after_file_update (TrackerMonitorTestFixture *fixture,
1538                                                                    gconstpointer              data)
1539 {
1540 	GFile *source_dir;
1541 	gchar *source_path;
1542 	GFile *dest_dir;
1543 	gchar *dest_path;
1544 	GFile *file_in_source_dir;
1545 	GFile *file_in_dest_dir;
1546 	gchar *file_in_dest_dir_path;
1547 	guint file_events;
1548 
1549 	/* Create directory to test with, before setting up the environment */
1550 	create_directory (fixture->monitored_directory, "foo", &source_dir);
1551 	source_path = g_file_get_path (source_dir);
1552 	g_assert (source_dir != NULL);
1553 
1554 	/* Add some file to the new dir */
1555 	set_file_contents (source_path, "lalala.txt", "whatever", &file_in_source_dir);
1556 
1557 	/* Set up environment */
1558 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1559 
1560 	/* Set to monitor the new dir also */
1561 	g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
1562 
1563 	/* Get final path of the file */
1564 	file_in_dest_dir_path = g_build_path (G_DIR_SEPARATOR_S,
1565 	                                      fixture->monitored_directory,
1566 	                                      "renamed",
1567 	                                      "lalala.txt",
1568 	                                      NULL);
1569 	file_in_dest_dir = g_file_new_for_path (file_in_dest_dir_path);
1570 	g_assert (file_in_dest_dir != NULL);
1571 
1572 	/* Update file contents */
1573 	set_file_contents (source_path, "lalala.txt", "hohoho", &file_in_source_dir);
1574 
1575 	/* Now, rename the directory */
1576 	dest_dir = g_file_get_parent (file_in_dest_dir);
1577 	dest_path = g_file_get_path (dest_dir);
1578 
1579 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1580 
1581 	g_hash_table_insert (fixture->events,
1582 	                     g_object_ref (source_dir),
1583 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1584 	g_hash_table_insert (fixture->events,
1585 	                     g_object_ref (dest_dir),
1586 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1587 	g_hash_table_insert (fixture->events,
1588 	                     g_object_ref (file_in_dest_dir),
1589 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1590 	g_hash_table_insert (fixture->events,
1591 	                     g_object_ref (file_in_source_dir),
1592 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1593 
1594 	/* Wait for events */
1595 	events_wait (fixture);
1596 
1597 	/* Get events in the source dir */
1598 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
1599 	/* Fail if we didn't get the MOVED_FROM signal */
1600 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
1601 	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE_TO signal */
1602 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1603 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1604 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1605 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1606 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1607 
1608 	/* Get events in the dest file */
1609 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_dir));
1610 	/* Fail if we didn't get the MOVED_TO signal */
1611 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
1612 	/* Fail if we got a CREATE, DELETE or MOVE_FROM signal (UPDATE may actually be possible) */
1613 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1614 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1615 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1616 
1617 	/* Get events in the file in source dir */
1618 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_source_dir));
1619 	/* Fail if we didn't get the UPDATE signal */
1620 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), >=, 0);
1621 	/* Fail if we got ANY signal */
1622 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1623 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1624 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1625 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1626 
1627 	/* Get events in the file in dest dir */
1628 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_dest_dir));
1629 	/* Fail if we got ANY signal */
1630 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1631 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1632 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1633 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1634 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1635 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1636 
1637 
1638 	/* Cleanup environment */
1639 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1640 	/* Since tracker 0.9.33, monitors are NOT moved to the new location directly when the
1641 	 * directory is moved, that is done by the upper layers.
1642 	 * Note that monitor is now in dest_dir */
1643 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, source_dir), ==, TRUE);
1644 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), !=, TRUE);
1645 	g_assert_cmpint (g_file_delete (file_in_dest_dir, NULL, NULL), ==, TRUE);
1646 	g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
1647 	g_object_unref (source_dir);
1648 	g_object_unref (file_in_source_dir);
1649 	g_object_unref (dest_dir);
1650 	g_object_unref (file_in_dest_dir);
1651 	g_free (source_path);
1652 	g_free (file_in_dest_dir_path);
1653 	g_free (dest_path);
1654 }
1655 
1656 static void
1657 test_monitor_directory_event_moved_to_not_monitored (TrackerMonitorTestFixture *fixture,
1658 						     gconstpointer              data)
1659 {
1660 	GFile *source_dir;
1661 	gchar *source_path;
1662 	GFile *dest_dir;
1663 	gchar *dest_path;
1664 	guint file_events;
1665 
1666 	/* Create directory to test with, before setting up the environment */
1667 	create_directory (fixture->monitored_directory, "foo", &source_dir);
1668 	source_path = g_file_get_path (source_dir);
1669 	g_assert (source_dir != NULL);
1670 
1671 	/* Set to monitor the new dir also */
1672 	g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
1673 
1674 	/* Set up environment */
1675 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1676 
1677 	/* Now, rename the directory */
1678 	dest_path = g_build_path (G_DIR_SEPARATOR_S, fixture->not_monitored_directory, "foo", NULL);
1679 	dest_dir = g_file_new_for_path (dest_path);
1680 
1681 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1682 
1683 	g_hash_table_insert (fixture->events,
1684 	                     g_object_ref (source_dir),
1685 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1686 	g_hash_table_insert (fixture->events,
1687 	                     g_object_ref (dest_dir),
1688 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1689 
1690 	/* Wait for events */
1691 	events_wait (fixture);
1692 
1693 	/* Get events in the source dir */
1694 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
1695 	/* Fail if we didn't get the DELETED signal */
1696 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), >, 0);
1697 	/* Fail if we got a CREATE, UPDATE, MOVE_FROM or MOVE_TO signal */
1698 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1699 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1700 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1701 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1702 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1703 
1704 	/* Get events in the dest file */
1705 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_dir));
1706 	/* Fail if we got any signal */
1707 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1708 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1709 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1710 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1711 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1712 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1713 
1714 	/* Cleanup environment */
1715 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1716 	/* Note that monitor is NOT in dest_dir, so FAIL if we could remove it */
1717 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), !=, TRUE);
1718 	g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
1719 	g_object_unref (source_dir);
1720 	g_object_unref (dest_dir);
1721 	g_free (source_path);
1722 	g_free (dest_path);
1723 }
1724 
1725 static void
1726 test_monitor_directory_event_moved_from_not_monitored (TrackerMonitorTestFixture *fixture,
1727 						       gconstpointer              data)
1728 {
1729 	GFile *source_dir;
1730 	gchar *source_path;
1731 	GFile *dest_dir;
1732 	gchar *dest_path;
1733 	guint file_events;
1734 
1735 	/* Create directory to test with in a not-monitored place,
1736 	 * before setting up the environment */
1737 	create_directory (fixture->not_monitored_directory, "foo", &source_dir);
1738 	source_path = g_file_get_path (source_dir);
1739 	g_assert (source_dir != NULL);
1740 
1741 	/* Set up environment */
1742 	tracker_monitor_set_enabled (fixture->monitor, TRUE);
1743 
1744 	/* Now, rename the directory to somewhere monitored */
1745 	dest_path = g_build_path (G_DIR_SEPARATOR_S, fixture->monitored_directory, "foo", NULL);
1746 	dest_dir = g_file_new_for_path (dest_path);
1747 
1748 	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
1749 
1750 	g_hash_table_insert (fixture->events,
1751 	                     g_object_ref (source_dir),
1752 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1753 	g_hash_table_insert (fixture->events,
1754 	                     g_object_ref (dest_dir),
1755 	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
1756 
1757 	/* Wait for events */
1758 	events_wait (fixture);
1759 
1760 	/* Get events in the source dir */
1761 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
1762 	/* Fail if we got any signal */
1763 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
1764 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1765 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1766 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1767 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1768 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1769 
1770 	/* Get events in the dest file */
1771 	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_dir));
1772 	/* Fail if we didn't get the CREATED signal */
1773 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), >, 0);
1774 	/* Fail if we got a CREATE, UPDATE, MOVE_FROM or MOVE_TO signal */
1775 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
1776 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_ATTRIBUTE_UPDATED), ==, 0);
1777 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
1778 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
1779 	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
1780 
1781 	/* Cleanup environment */
1782 	tracker_monitor_set_enabled (fixture->monitor, FALSE);
1783 	/* Note that monitor is now in dest_dir, BUT TrackerMonitor should
1784 	 * NOT add automatically a new monitor, so FAIL if we can remove it */
1785 	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), !=, TRUE);
1786 	g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
1787 	g_object_unref (source_dir);
1788 	g_object_unref (dest_dir);
1789 	g_free (source_path);
1790 	g_free (dest_path);
1791 }
1792 
1793 /* ----------------------------- BASIC API TESTS --------------------------------- */
1794 
1795 static void
1796 test_monitor_basic (void)
1797 {
1798 	TrackerMonitor *monitor;
1799 	gchar *basename;
1800 	gchar *path_for_monitor;
1801 	GFile *file_for_monitor;
1802 	GFile *file_for_tmp;
1803 
1804 	/* Setup directories */
1805 	basename = g_strdup_printf ("monitor-test-%d", getpid ());
1806 	path_for_monitor = g_build_path (G_DIR_SEPARATOR_S, g_get_tmp_dir (), basename, NULL);
1807 	g_free (basename);
1808 	g_assert_cmpint (g_mkdir_with_parents (path_for_monitor, 00755), ==, 0);
1809 
1810 	file_for_monitor = g_file_new_for_path (path_for_monitor);
1811 	g_assert (G_IS_FILE (file_for_monitor));
1812 
1813 	file_for_tmp = g_file_new_for_path (g_get_tmp_dir ());
1814 	g_assert (G_IS_FILE (file_for_tmp));
1815 
1816 	/* Create a monitor */
1817 	monitor = tracker_monitor_new ();
1818 	g_assert (monitor != NULL);
1819 
1820 	/* Test general API with monitors enabled */
1821 	tracker_monitor_set_enabled (monitor, TRUE);
1822 	g_assert_cmpint (tracker_monitor_get_enabled (monitor), ==, TRUE);
1823 
1824 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 0);
1825 	g_assert_cmpint (tracker_monitor_add (monitor, file_for_monitor), ==, TRUE);
1826 	g_assert_cmpint (tracker_monitor_add (monitor, file_for_monitor), ==, TRUE); /* Test double add on purpose */
1827 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 1);
1828 	g_assert_cmpint (tracker_monitor_is_watched (monitor, file_for_monitor), ==, TRUE);
1829 	g_assert_cmpint (tracker_monitor_is_watched_by_string (monitor, path_for_monitor), ==, TRUE);
1830 	g_assert_cmpint (tracker_monitor_remove (monitor, file_for_monitor), ==, TRUE);
1831 	g_assert_cmpint (tracker_monitor_is_watched (monitor, file_for_monitor), ==, FALSE);
1832 	g_assert_cmpint (tracker_monitor_is_watched_by_string (monitor, path_for_monitor), ==, FALSE);
1833 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 0);
1834 
1835 	tracker_monitor_add (monitor, file_for_monitor);
1836 	tracker_monitor_add (monitor, file_for_tmp);
1837 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 2);
1838 	g_assert_cmpint (tracker_monitor_remove_recursively (monitor, file_for_tmp), ==, TRUE);
1839 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 0);
1840 
1841 	/* Test general API with monitors disabled */
1842 	tracker_monitor_set_enabled (monitor, FALSE);
1843 	g_assert_cmpint (tracker_monitor_get_enabled (monitor), ==, FALSE);
1844 
1845 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 0);
1846 	g_assert_cmpint (tracker_monitor_add (monitor, file_for_monitor), ==, TRUE);
1847 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 1);
1848 	g_assert_cmpint (tracker_monitor_is_watched (monitor, file_for_monitor), ==, FALSE);
1849 	g_assert_cmpint (tracker_monitor_is_watched_by_string (monitor, path_for_monitor), ==, FALSE);
1850 	g_assert_cmpint (tracker_monitor_remove (monitor, file_for_monitor), ==, TRUE);
1851 	g_assert_cmpint (tracker_monitor_is_watched (monitor, file_for_monitor), ==, FALSE);
1852 	g_assert_cmpint (tracker_monitor_is_watched_by_string (monitor, path_for_monitor), ==, FALSE);
1853 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 0);
1854 
1855 	tracker_monitor_add (monitor, file_for_monitor);
1856 	tracker_monitor_add (monitor, file_for_tmp);
1857 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 2);
1858 	g_assert_cmpint (tracker_monitor_remove_recursively (monitor, file_for_tmp), ==, TRUE);
1859 	g_assert_cmpint (tracker_monitor_get_count (monitor), ==, 0);
1860 
1861 	/* Cleanup */
1862 	g_assert_cmpint (g_rmdir (path_for_monitor), ==, 0);
1863 	g_assert (file_for_tmp != NULL);
1864 	g_object_unref (file_for_tmp);
1865 	g_assert (file_for_monitor != NULL);
1866 	g_object_unref (file_for_monitor);
1867 	g_assert (path_for_monitor != NULL);
1868 	g_free (path_for_monitor);
1869 	g_assert (monitor != NULL);
1870 	g_object_unref (monitor);
1871 }
1872 
1873 gint
1874 main (gint    argc,
1875       gchar **argv)
1876 {
1877 	g_test_init (&argc, &argv, NULL);
1878 
1879 	g_test_message ("Testing filesystem monitor");
1880 
1881 	/* Basic API tests */
1882 	g_test_add_func ("/libtracker-miner/tracker-monitor/basic",
1883 	                 test_monitor_basic);
1884 
1885 	/* File Event tests */
1886 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/created",
1887 	            TrackerMonitorTestFixture,
1888 	            NULL,
1889 	            test_monitor_common_setup,
1890 	            test_monitor_file_event_created,
1891 	            test_monitor_common_teardown);
1892 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/updated",
1893 	            TrackerMonitorTestFixture,
1894 	            NULL,
1895 	            test_monitor_common_setup,
1896 	            test_monitor_file_event_updated,
1897 	            test_monitor_common_teardown);
1898 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/attribute-updated",
1899 	            TrackerMonitorTestFixture,
1900 	            NULL,
1901 	            test_monitor_common_setup,
1902 	            test_monitor_file_event_attribute_updated,
1903 	            test_monitor_common_teardown);
1904 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/deleted",
1905 	            TrackerMonitorTestFixture,
1906 	            NULL,
1907 	            test_monitor_common_setup,
1908 	            test_monitor_file_event_deleted,
1909 	            test_monitor_common_teardown);
1910 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/moved/to-monitored",
1911 	            TrackerMonitorTestFixture,
1912 	            NULL,
1913 	            test_monitor_common_setup,
1914 	            test_monitor_file_event_moved_to_monitored,
1915 	            test_monitor_common_teardown);
1916 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/moved/to-not-monitored",
1917 	            TrackerMonitorTestFixture,
1918 	            NULL,
1919 	            test_monitor_common_setup,
1920 	            test_monitor_file_event_moved_to_not_monitored,
1921 	            test_monitor_common_teardown);
1922 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/moved/from-not-monitored",
1923 	            TrackerMonitorTestFixture,
1924 	            NULL,
1925 	            test_monitor_common_setup,
1926 	            test_monitor_file_event_moved_from_not_monitored,
1927 	            test_monitor_common_teardown);
1928 
1929 	/* File event blacklisting tests */
1930 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/created-updated",
1931 	            TrackerMonitorTestFixture,
1932 	            NULL,
1933 	            test_monitor_common_setup,
1934 	            test_monitor_file_event_blacklisting_created_updated,
1935 	            test_monitor_common_teardown);
1936 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/created-deleted",
1937 	            TrackerMonitorTestFixture,
1938 	            NULL,
1939 	            test_monitor_common_setup,
1940 	            test_monitor_file_event_blacklisting_created_deleted,
1941 	            test_monitor_common_teardown);
1942 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/created-updated-deleted",
1943 	            TrackerMonitorTestFixture,
1944 	            NULL,
1945 	            test_monitor_common_setup,
1946 	            test_monitor_file_event_blacklisting_created_updated_deleted,
1947 	            test_monitor_common_teardown);
1948 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/created-moved",
1949 	            TrackerMonitorTestFixture,
1950 	            NULL,
1951 	            test_monitor_common_setup,
1952 	            test_monitor_file_event_blacklisting_created_moved,
1953 	            test_monitor_common_teardown);
1954 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/updated-deleted",
1955 	            TrackerMonitorTestFixture,
1956 	            NULL,
1957 	            test_monitor_common_setup,
1958 	            test_monitor_file_event_blacklisting_updated_deleted,
1959 	            test_monitor_common_teardown);
1960 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/updated-moved",
1961 	            TrackerMonitorTestFixture,
1962 	            NULL,
1963 	            test_monitor_common_setup,
1964 	            test_monitor_file_event_blacklisting_updated_moved,
1965 	            test_monitor_common_teardown);
1966 	g_test_add ("/libtracker-miner/tracker-monitor/file-event/blacklisting/attribute-updated-moved",
1967 	            TrackerMonitorTestFixture,
1968 	            NULL,
1969 	            test_monitor_common_setup,
1970 	            test_monitor_file_event_blacklisting_attribute_updated_moved,
1971 	            test_monitor_common_teardown);
1972 
1973 	/* Directory Event tests */
1974 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/created",
1975 	            TrackerMonitorTestFixture,
1976 	            NULL,
1977 	            test_monitor_common_setup,
1978 	            test_monitor_directory_event_created,
1979 	            test_monitor_common_teardown);
1980 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/deleted",
1981 	            TrackerMonitorTestFixture,
1982 	            NULL,
1983 	            test_monitor_common_setup,
1984 	            test_monitor_directory_event_deleted,
1985 	            test_monitor_common_teardown);
1986 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored",
1987 	            TrackerMonitorTestFixture,
1988 	            NULL,
1989 	            test_monitor_common_setup,
1990 	            test_monitor_directory_event_moved_to_monitored,
1991 	            test_monitor_common_teardown);
1992 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored-after-file-create",
1993 	            TrackerMonitorTestFixture,
1994 	            NULL,
1995 	            test_monitor_common_setup,
1996 	            test_monitor_directory_event_moved_to_monitored_after_file_create,
1997 	            test_monitor_common_teardown);
1998 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored-after-file-update",
1999 	            TrackerMonitorTestFixture,
2000 	            NULL,
2001 	            test_monitor_common_setup,
2002 	            test_monitor_directory_event_moved_to_monitored_after_file_update,
2003 	            test_monitor_common_teardown);
2004 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-not-monitored",
2005 	            TrackerMonitorTestFixture,
2006 	            NULL,
2007 	            test_monitor_common_setup,
2008 		    test_monitor_directory_event_moved_to_not_monitored,
2009 	            test_monitor_common_teardown);
2010 	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/from-not-monitored",
2011 	            TrackerMonitorTestFixture,
2012 	            NULL,
2013 	            test_monitor_common_setup,
2014 		    test_monitor_directory_event_moved_from_not_monitored,
2015 	            test_monitor_common_teardown);
2016 
2017 	return g_test_run ();
2018 }