[tracker/drop-inotify: 19/24] tracker-monitor-tests: New directory event unit tests
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/drop-inotify: 19/24] tracker-monitor-tests: New directory event unit tests
- Date: Thu, 8 Jul 2010 09:15:41 +0000 (UTC)
commit 391c84129acea6be402bf1f6c94f6686a289130a
Author: Aleksander Morgado <aleksander lanedo com>
Date: Tue Jul 6 09:33:56 2010 +0200
tracker-monitor-tests: New directory event unit tests
src/libtracker-miner/tracker-monitor.c | 2 +
tests/libtracker-miner/tracker-monitor-test.c | 153 ++++++++++++++++++++++--
2 files changed, 142 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-monitor.c b/src/libtracker-miner/tracker-monitor.c
index f381f7e..e7e347e 100644
--- a/src/libtracker-miner/tracker-monitor.c
+++ b/src/libtracker-miner/tracker-monitor.c
@@ -645,6 +645,8 @@ emit_signal_for_event (TrackerMonitor *monitor,
signals[ITEM_CREATED], 0,
event_data->file,
event_data->is_directory);
+ /* Note that if the created item is a Directory, we must NOT
+ * add automatically a new monitor. */
break;
case G_FILE_MONITOR_EVENT_CHANGED:
diff --git a/tests/libtracker-miner/tracker-monitor-test.c b/tests/libtracker-miner/tracker-monitor-test.c
index 4bc574e..c0e040b 100644
--- a/tests/libtracker-miner/tracker-monitor-test.c
+++ b/tests/libtracker-miner/tracker-monitor-test.c
@@ -176,7 +176,7 @@ test_monitor_events_moved_cb (TrackerMonitor *monitor,
static void
test_monitor_common_setup (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
gchar *basename;
@@ -226,7 +226,7 @@ test_monitor_common_setup (TrackerMonitorTestFixture *fixture,
static void
test_monitor_common_teardown (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
/* Remove the main loop */
g_main_loop_unref (fixture->main_loop);
@@ -354,7 +354,7 @@ events_wait (TrackerMonitorTestFixture *fixture)
static void
test_monitor_file_event_created (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *test_file;
guint file_events;
@@ -393,7 +393,7 @@ test_monitor_file_event_created (TrackerMonitorTestFixture *fixture,
static void
test_monitor_file_event_updated (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *test_file;
guint file_events;
@@ -436,7 +436,7 @@ test_monitor_file_event_updated (TrackerMonitorTestFixture *fixture,
static void
test_monitor_file_event_deleted (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *test_file;
guint file_events;
@@ -476,7 +476,7 @@ test_monitor_file_event_deleted (TrackerMonitorTestFixture *fixture,
static void
test_monitor_file_event_moved_to_monitored (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_file;
gchar *source_path;
@@ -539,7 +539,7 @@ test_monitor_file_event_moved_to_monitored (TrackerMonitorTestFixture *fixture,
static void
test_monitor_file_event_moved_to_not_monitored (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_file;
gchar *source_path;
@@ -602,7 +602,7 @@ test_monitor_file_event_moved_to_not_monitored (TrackerMonitorTestFixture *fixtu
static void
test_monitor_file_event_moved_from_not_monitored (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_file;
gchar *source_path;
@@ -667,7 +667,7 @@ test_monitor_file_event_moved_from_not_monitored (TrackerMonitorTestFixture *fix
static void
test_monitor_directory_event_created (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *test_dir;
guint file_events;
@@ -705,8 +705,55 @@ test_monitor_directory_event_created (TrackerMonitorTestFixture *fixture,
}
static void
+test_monitor_directory_event_deleted (TrackerMonitorTestFixture *fixture,
+ gconstpointer data)
+{
+ GFile *source_dir;
+ gchar *source_path;
+ guint file_events;
+
+ /* Create directory to test with in a monitored place,
+ * 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);
+
+ /* Set to monitor the new dir also */
+ g_assert_cmpint (tracker_monitor_add (fixture->monitor, source_dir), ==, TRUE);
+
+ /* Set up environment */
+ tracker_monitor_set_enabled (fixture->monitor, TRUE);
+
+ /* Now, delete the directory */
+ g_assert_cmpint (g_file_delete (source_dir, NULL, NULL), ==, TRUE);
+
+ g_hash_table_insert (fixture->events,
+ g_object_ref (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 DELETED signal */
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), >, 0);
+ /* Fail if we got a CREATEd, UPDATED, MOVED_FROM or MOVED_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_MOVED_FROM), ==, 0);
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
+
+ /* Cleanup environment */
+ tracker_monitor_set_enabled (fixture->monitor, FALSE);
+ g_object_unref (source_dir);
+ g_free (source_path);
+}
+
+
+static void
test_monitor_directory_event_moved_to_monitored (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_dir;
gchar *source_path;
@@ -820,7 +867,7 @@ test_monitor_directory_event_moved_to_monitored (TrackerMonitorTestFixture *fixt
*/
static void
test_monitor_directory_event_moved_to_monitored_after_file_create (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_dir;
gchar *source_path;
@@ -933,7 +980,7 @@ test_monitor_directory_event_moved_to_monitored_after_file_create (TrackerMonito
*/
static void
test_monitor_directory_event_moved_to_monitored_after_file_update (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_dir;
gchar *source_path;
@@ -1048,7 +1095,7 @@ test_monitor_directory_event_moved_to_monitored_after_file_update (TrackerMonito
static void
test_monitor_directory_event_moved_to_not_monitored (TrackerMonitorTestFixture *fixture,
- gconstpointer data)
+ gconstpointer data)
{
GFile *source_dir;
gchar *source_path;
@@ -1113,6 +1160,73 @@ test_monitor_directory_event_moved_to_not_monitored (TrackerMonitorTestFixture *
g_free (dest_path);
}
+static void
+test_monitor_directory_event_moved_from_not_monitored (TrackerMonitorTestFixture *fixture,
+ gconstpointer data)
+{
+ GFile *source_dir;
+ gchar *source_path;
+ GFile *dest_dir;
+ gchar *dest_path;
+ guint file_events;
+
+ /* Create directory to test with in a not-monitored place,
+ * before setting up the environment */
+ create_directory (fixture->not_monitored_directory, "foo", &source_dir);
+ source_path = g_file_get_path (source_dir);
+ g_assert (source_dir != NULL);
+
+ /* Set up environment */
+ tracker_monitor_set_enabled (fixture->monitor, TRUE);
+
+ /* Now, rename the directory to somewhere monitored */
+ dest_path = g_build_path (G_DIR_SEPARATOR_S, fixture->monitored_directory, "foo", NULL);
+ dest_dir = g_file_new_for_path (dest_path);
+
+ 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));
+
+ /* 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 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_MOVED_FROM), ==, 0);
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 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 CREATED signal */
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_CREATED), >, 0);
+ /* Fail if we got a CREATE, UPDATE, MOVE_FROM or MOVE_TO signal */
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_UPDATED), ==, 0);
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_FROM), ==, 0);
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_MOVED_TO), ==, 0);
+ g_assert_cmpuint ((file_events & MONITOR_SIGNAL_ITEM_DELETED), ==, 0);
+
+ /* Cleanup environment */
+ tracker_monitor_set_enabled (fixture->monitor, FALSE);
+ /* Note that monitor is now in dest_dir, BUT TrackerMonitor should
+ * NOT add automatically a new monitor, so FAIL if we can remove it */
+ g_assert_cmpint (tracker_monitor_remove (fixture->monitor, dest_dir), !=, TRUE);
+ g_assert_cmpint (g_file_delete (dest_dir, NULL, NULL), ==, TRUE);
+ g_object_unref (source_dir);
+ g_object_unref (dest_dir);
+ g_free (source_path);
+ g_free (dest_path);
+}
+
+
/* ----------------------------- BASIC API TESTS --------------------------------- */
static void
@@ -1258,6 +1372,13 @@ main (gint argc,
test_monitor_directory_event_created,
test_monitor_common_teardown);
+ g_test_add ("/libtracker-miner/tracker-monitor/directory-event/deleted",
+ TrackerMonitorTestFixture,
+ NULL,
+ test_monitor_common_setup,
+ test_monitor_directory_event_deleted,
+ test_monitor_common_teardown);
+
g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/to-monitored",
TrackerMonitorTestFixture,
NULL,
@@ -1286,6 +1407,12 @@ main (gint argc,
test_monitor_directory_event_moved_to_not_monitored,
test_monitor_common_teardown);
+ g_test_add ("/libtracker-miner/tracker-monitor/directory-event/moved/from-not-monitored",
+ TrackerMonitorTestFixture,
+ NULL,
+ test_monitor_common_setup,
+ test_monitor_directory_event_moved_from_not_monitored,
+ test_monitor_common_teardown);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]