[tracker/drop-inotify] tracker-monitor-tests: New directory-move unit test after file update



commit a50fe4cdd64ff6217bad177726364e11713d4d24
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Mon Jul 5 09:37:53 2010 +0200

    tracker-monitor-tests: New directory-move unit test after file update

 tests/libtracker-miner/tracker-monitor-test.c |  134 ++++++++++++++++++++++++-
 1 files changed, 130 insertions(+), 4 deletions(-)
---
diff --git a/tests/libtracker-miner/tracker-monitor-test.c b/tests/libtracker-miner/tracker-monitor-test.c
index 95896ee..ab9378a 100644
--- a/tests/libtracker-miner/tracker-monitor-test.c
+++ b/tests/libtracker-miner/tracker-monitor-test.c
@@ -819,8 +819,8 @@ test_monitor_directory_event_moved_to_monitored (TrackerMonitorTestFixture *fixt
  * In this case, GIO dumps an extra DELETE event after the MOVE
  */
 static void
-test_monitor_directory_event_moved_to_monitored_with_delete (TrackerMonitorTestFixture *fixture,
-                                                             gconstpointer data)
+test_monitor_directory_event_moved_to_monitored_after_file_create (TrackerMonitorTestFixture *fixture,
+                                                                   gconstpointer data)
 {
 	GFile *source_dir;
 	gchar *source_path;
@@ -928,6 +928,124 @@ test_monitor_directory_event_moved_to_monitored_with_delete (TrackerMonitorTestF
 	g_free (dest_path);
 }
 
+/* Same test as before, BUT, updating an existing file in the directory while it's being monitored.
+ * In this case, GIO dumps an extra DELETE event after the MOVE
+ */
+static void
+test_monitor_directory_event_moved_to_monitored_after_file_update (TrackerMonitorTestFixture *fixture,
+                                                                   gconstpointer data)
+{
+	GFile *source_dir;
+	gchar *source_path;
+	GFile *dest_dir;
+	gchar *dest_path;
+	GFile *file_in_source_dir;
+	GFile *file_in_dest_dir;
+	gchar *file_in_dest_dir_path;
+	guint file_events;
+
+	/* Create directory to test with, before setting up the environment */
+	create_directory (fixture->monitored_directory, "foo", &source_dir);
+	source_path = g_file_get_path (source_dir);
+	g_assert (source_dir != NULL);
+
+	/* Add some file to the new dir */
+	set_file_contents (source_path, "lalala.txt", "whatever", &file_in_source_dir);
+
+	/* Set up environment */
+	tracker_monitor_set_enabled (fixture->monitor, TRUE);
+
+	/* Set to monitor the new dir also */
+	g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
+
+	/* Get final path of the file */
+	file_in_dest_dir_path = g_build_path (G_DIR_SEPARATOR_S,
+	                                      fixture->monitored_directory,
+	                                      "renamed",
+	                                      "lalala.txt",
+	                                      NULL);
+	file_in_dest_dir = g_file_new_for_path (file_in_dest_dir_path);
+	g_assert (file_in_dest_dir != NULL);
+
+	/* Update file contents */
+	set_file_contents (source_path, "lalala.txt", "hohoho", &file_in_source_dir);
+
+	/* Now, rename the directory */
+	dest_dir = g_file_get_parent (file_in_dest_dir);
+	dest_path = g_file_get_path (dest_dir);
+
+	g_assert_cmpint (g_rename (source_path, dest_path), ==, 0);
+
+	g_hash_table_insert (fixture->events,
+	                     g_object_ref (source_dir),
+	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
+	g_hash_table_insert (fixture->events,
+	                     g_object_ref (dest_dir),
+	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
+	g_hash_table_insert (fixture->events,
+	                     g_object_ref (file_in_dest_dir),
+	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
+	g_hash_table_insert (fixture->events,
+	                     g_object_ref (file_in_source_dir),
+	                     GUINT_TO_POINTER (MONITOR_SIGNAL_NONE));
+
+	/* Wait for events */
+	events_wait (fixture);
+
+	/* Get events in the source dir */
+	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, source_dir));
+	/* Fail if we didn't get the MOVED_FROM signal */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), >, 0);
+	/* Fail if we got a CREATE, UPDATE, DELETE or MOVE_TO signal */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
+
+	/* Get events in the dest file */
+	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, dest_dir));
+	/* Fail if we didn't get the MOVED_TO signal */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), >, 0);
+	/* Fail if we got a CREATE, DELETE or MOVE_FROM signal (UPDATE may actually be possible) */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
+
+	/* Get events in the file in source dir */
+	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_source_dir));
+	/* Fail if we didn't get the UPDATE signal */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), >=, 0);
+	/* Fail if we got ANY signal */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
+
+	/* Get events in the file in dest dir */
+	file_events = GPOINTER_TO_UINT (g_hash_table_lookup (fixture->events, file_in_dest_dir));
+	/* Fail if we got ANY signal */
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
+	g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
+
+
+	/* Cleanup environment */
+	tracker_monitor_set_enabled (fixture->monitor, FALSE);
+	/* Note that monitor is now in dest_dir */
+	g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), ==, TRUE);
+	g_assert_cmpint (g_file_delete (file_in_dest_dir, NULL, NULL), ==, TRUE);
+	g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
+	g_object_unref (source_dir);
+	g_object_unref (file_in_source_dir);
+	g_object_unref (dest_dir);
+	g_object_unref (file_in_dest_dir);
+	g_free (source_path);
+	g_free (file_in_dest_dir_path);
+	g_free (dest_path);
+}
+
 /* ----------------------------- BASIC API TESTS --------------------------------- */
 
 static void
@@ -1080,12 +1198,20 @@ main (gint    argc,
 	            test_monitor_directory_event_moved_to_monitored,
 	            test_monitor_common_teardown);
 
-	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored-with-delete",
+	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored-after-file-create",
 	            TrackerMonitorTestFixture,
 	            NULL,
 	            test_monitor_common_setup,
-	            test_monitor_directory_event_moved_to_monitored_with_delete,
+	            test_monitor_directory_event_moved_to_monitored_after_file_create,
 	            test_monitor_common_teardown);
 
+	g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored-after-file-update",
+	            TrackerMonitorTestFixture,
+	            NULL,
+	            test_monitor_common_setup,
+	            test_monitor_directory_event_moved_to_monitored_after_file_update,
+	            test_monitor_common_teardown);
+
+
 	return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]