[nautilus] tag-manager: Skip tracker initialization in tests



commit 7a2b3e21419533c6e87799bf84e2c3d6b6376b11
Author: António Fernandes <antoniof gnome org>
Date:   Tue May 31 19:03:42 2022 +0100

    tag-manager: Skip tracker initialization in tests
    
    Fixes test failures introduced by df78c517516cec20892f2a108df47613153ddf5b
    
    Before that commit, we used to fully initiate the tag manager only from
    NautilusApplication, because the tests didn't call set_cancellable().
    
    Now that initialization is completed on construction, add a constructor
    which skips the part of initialization that the tests don't need.

 src/nautilus-tag-manager.c                         | 26 ++++++++++++++++++++++
 src/nautilus-tag-manager.h                         |  1 +
 .../displayless/test-file-operations-copy-files.c  |  2 +-
 .../displayless/test-file-operations-move-files.c  |  2 +-
 .../test-file-operations-trash-or-delete.c         |  2 +-
 5 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c
index 22aed9011..959eee89e 100644
--- a/src/nautilus-tag-manager.c
+++ b/src/nautilus-tag-manager.c
@@ -51,6 +51,9 @@ G_DEFINE_TYPE (NautilusTagManager, nautilus_tag_manager, G_TYPE_OBJECT);
 
 static NautilusTagManager *tag_manager = NULL;
 
+/* See nautilus_tag_manager_new_dummy() documentation for details. */
+static gboolean make_dummy_instance = FALSE;
+
 typedef struct
 {
     NautilusTagManager *tag_manager;
@@ -586,6 +589,23 @@ nautilus_tag_manager_new (void)
     return tag_manager;
 }
 
+/**
+ * nautilus_tag_manager_new_dummy:
+ *
+ * Creates a dummy tag manager without database.
+ *
+ * Useful only for tests where the tag manager is needed but not being tested
+ * and we don't want to fail the tests due to irrelevant D-Bus failures.
+ *
+ * Returns: (transfer full): the #NautilusTagManager singleton object.
+ */
+NautilusTagManager *
+nautilus_tag_manager_new_dummy (void)
+{
+    make_dummy_instance = TRUE;
+    return nautilus_tag_manager_new ();
+}
+
 /**
  * nautilus_tag_manager_get:
  *
@@ -665,6 +685,12 @@ nautilus_tag_manager_init (NautilusTagManager *self)
                                                      NULL);
     self->home = g_file_new_for_path (g_get_home_dir ());
 
+    if (make_dummy_instance)
+    {
+        /* Skip database initiation for nautilus_tag_manager_new_dummy(). */
+        return;
+    }
+
     self->cancellable = g_cancellable_new ();
     self->database_ok = setup_database (self, self->cancellable, &error);
     if (error)
diff --git a/src/nautilus-tag-manager.h b/src/nautilus-tag-manager.h
index 24ef72459..5bfc3c7ad 100644
--- a/src/nautilus-tag-manager.h
+++ b/src/nautilus-tag-manager.h
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (NautilusTagManager, nautilus_tag_manager, NAUTILUS, TAG_MANAGER, GObject);
 
 NautilusTagManager* nautilus_tag_manager_new                (void);
+NautilusTagManager* nautilus_tag_manager_new_dummy          (void);
 NautilusTagManager* nautilus_tag_manager_get                (void);
 
 GList*              nautilus_tag_manager_get_starred_files (NautilusTagManager *self);
diff --git a/test/automated/displayless/test-file-operations-copy-files.c 
b/test/automated/displayless/test-file-operations-copy-files.c
index 601b0090d..09e79a479 100644
--- a/test/automated/displayless/test-file-operations-copy-files.c
+++ b/test/automated/displayless/test-file-operations-copy-files.c
@@ -1309,7 +1309,7 @@ main (int   argc,
     int ret;
 
     undo_manager = nautilus_file_undo_manager_new ();
-    tag_manager = nautilus_tag_manager_new ();
+    tag_manager = nautilus_tag_manager_new_dummy ();
     g_test_init (&argc, &argv, NULL);
     g_test_set_nonfatal_assertions ();
     nautilus_ensure_extension_points ();
diff --git a/test/automated/displayless/test-file-operations-move-files.c 
b/test/automated/displayless/test-file-operations-move-files.c
index fc528c486..43757c609 100644
--- a/test/automated/displayless/test-file-operations-move-files.c
+++ b/test/automated/displayless/test-file-operations-move-files.c
@@ -1940,7 +1940,7 @@ main (int   argc,
     int ret;
 
     undo_manager = nautilus_file_undo_manager_new ();
-    tag_manager = nautilus_tag_manager_new ();
+    tag_manager = nautilus_tag_manager_new_dummy ();
     g_test_init (&argc, &argv, NULL);
     g_test_set_nonfatal_assertions ();
     nautilus_ensure_extension_points ();
diff --git a/test/automated/displayless/test-file-operations-trash-or-delete.c 
b/test/automated/displayless/test-file-operations-trash-or-delete.c
index 7f9934375..f0c5eb12e 100644
--- a/test/automated/displayless/test-file-operations-trash-or-delete.c
+++ b/test/automated/displayless/test-file-operations-trash-or-delete.c
@@ -578,7 +578,7 @@ main (int   argc,
     g_test_set_nonfatal_assertions ();
     nautilus_ensure_extension_points ();
     undo_manager = nautilus_file_undo_manager_new ();
-    tag_manager = nautilus_tag_manager_new ();
+    tag_manager = nautilus_tag_manager_new_dummy ();
 
     setup_test_suite ();
 


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