[gnome-builder/wip/chergert/unittests: 11/11] testing: start on unit testing



commit 1eea8f4dbd811d65021ca4825b37b9e67d7c5c2d
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 13 17:40:19 2017 -0700

    testing: start on unit testing

 src/libide/ide-context.c               |   50 ++++++++-
 src/libide/ide-context.h               |    1 +
 src/libide/ide-types.h                 |    4 +
 src/libide/ide.h                       |    2 +
 src/libide/meson.build                 |    1 +
 src/libide/testing/ide-test-manager.c  |  198 ++++++++++++++++++++++++++++++++
 src/libide/testing/ide-test-manager.h  |   29 +++++
 src/libide/testing/ide-test-provider.c |  117 +++++++++++++++++++
 src/libide/testing/ide-test-provider.h |   52 +++++++++
 src/libide/testing/ide-test.c          |  166 ++++++++++++++++++++++++++
 src/libide/testing/ide-test.h          |   45 +++++++
 src/libide/testing/meson.build         |   16 +++
 12 files changed, 680 insertions(+), 1 deletions(-)
---
diff --git a/src/libide/ide-context.c b/src/libide/ide-context.c
index 9e5a826..6ad0ced 100644
--- a/src/libide/ide-context.c
+++ b/src/libide/ide-context.c
@@ -39,6 +39,7 @@
 #include "debugger/ide-debug-manager.h"
 #include "devices/ide-device-manager.h"
 #include "doap/ide-doap.h"
+#include "documentation/ide-documentation.h"
 #include "plugins/ide-extension-util.h"
 #include "projects/ide-project-files.h"
 #include "projects/ide-project-item.h"
@@ -49,7 +50,7 @@
 #include "search/ide-search-engine.h"
 #include "search/ide-search-provider.h"
 #include "snippets/ide-source-snippets-manager.h"
-#include "documentation/ide-documentation.h"
+#include "testing/ide-test-manager.h"
 #include "transfers/ide-transfer-manager.h"
 #include "util/ide-async-helper.h"
 #include "util/ide-settings.h"
@@ -78,6 +79,7 @@ struct _IdeContext
   IdeRuntimeManager        *runtime_manager;
   IdeSearchEngine          *search_engine;
   IdeSourceSnippetsManager *snippets_manager;
+  IdeTestManager           *test_manager;
   IdeProject               *project;
   GFile                    *project_file;
   gchar                    *root_build_dir;
@@ -534,6 +536,7 @@ ide_context_finalize (GObject *object)
   g_clear_object (&self->project_file);
   g_clear_object (&self->recent_manager);
   g_clear_object (&self->runtime_manager);
+  g_clear_object (&self->test_manager);
   g_clear_object (&self->unsaved_files);
   g_clear_object (&self->vcs);
 
@@ -817,6 +820,10 @@ ide_context_init (IdeContext *self)
                                         "context", self,
                                         NULL);
 
+  self->test_manager = g_object_new (IDE_TYPE_TEST_MANAGER,
+                                     "context", self,
+                                     NULL);
+
   self->unsaved_files = g_object_new (IDE_TYPE_UNSAVED_FILES,
                                       "context", self,
                                       NULL);
@@ -1118,6 +1125,28 @@ ide_context_init_snippets (gpointer             source_object,
 }
 
 static void
+ide_context_init_tests (gpointer             source_object,
+                        GCancellable        *cancellable,
+                        GAsyncReadyCallback  callback,
+                        gpointer             user_data)
+{
+  IdeContext *self = source_object;
+  g_autoptr(GTask) task = NULL;
+  g_autoptr(GError) error = NULL;
+
+  g_return_if_fail (IDE_IS_CONTEXT (self));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_priority (task, G_PRIORITY_LOW);
+  g_task_set_source_tag (task, ide_context_init_tests);
+
+  if (!g_initable_init (G_INITABLE (self->test_manager), cancellable, &error))
+    g_task_return_error (task, g_steal_pointer (&error));
+  else
+    g_task_return_boolean (task, TRUE);
+}
+
+static void
 ide_context_service_added (PeasExtensionSet *set,
                            PeasPluginInfo   *info,
                            PeasExtension    *exten,
@@ -1648,6 +1677,7 @@ ide_context_init_async (GAsyncInitable      *initable,
                         ide_context_init_build_manager,
                         ide_context_init_run_manager,
                         ide_context_init_diagnostics_manager,
+                        ide_context_init_tests,
                         ide_context_init_loaded,
                         NULL);
 }
@@ -2320,6 +2350,24 @@ ide_context_get_debug_manager (IdeContext *self)
 }
 
 /**
+ * ide_context_get_test_manager:
+ * @self: An #IdeTestManager
+ *
+ * Gets the test manager for the #IdeContext.
+ *
+ * Returns: (transfer none): An #IdeTestManager
+ *
+ * Since: 3.28
+ */
+IdeTestManager *
+ide_context_get_test_manager (IdeContext *self)
+{
+  g_return_val_if_fail (IDE_IS_CONTEXT (self), NULL);
+
+  return self->test_manager;
+}
+
+/**
  * ide_context_add_pausable:
  * @self: an #IdeContext
  * @pausable: an #IdePausable
diff --git a/src/libide/ide-context.h b/src/libide/ide-context.h
index e2a3351..5b5161e 100644
--- a/src/libide/ide-context.h
+++ b/src/libide/ide-context.h
@@ -47,6 +47,7 @@ IdeSettings              *ide_context_get_settings              (IdeContext
                                                                  const gchar          *schema_id,
                                                                  const gchar          *relative_path);
 IdeSourceSnippetsManager *ide_context_get_snippets_manager      (IdeContext           *self);
+IdeTestManager           *ide_context_get_test_manager          (IdeContext           *self);
 IdeUnsavedFiles          *ide_context_get_unsaved_files         (IdeContext           *self);
 IdeVcs                   *ide_context_get_vcs                   (IdeContext           *self);
 const gchar              *ide_context_get_root_build_dir        (IdeContext           *self);
diff --git a/src/libide/ide-types.h b/src/libide/ide-types.h
index 49a43de..72a05b6 100644
--- a/src/libide/ide-types.h
+++ b/src/libide/ide-types.h
@@ -129,6 +129,10 @@ typedef struct _IdeSubprocessLauncher          IdeSubprocessLauncher;
 typedef struct _IdeSymbol                      IdeSymbol;
 typedef struct _IdeSymbolResolver              IdeSymbolResolver;
 
+typedef struct _IdeTest                        IdeTest;
+typedef struct _IdeTestManager                 IdeTestManager;
+typedef struct _IdeTestProvider                IdeTestProvider;
+
 typedef struct _IdeTransferManager             IdeTransferManager;
 typedef struct _IdeTransfer                    IdeTransfer;
 
diff --git a/src/libide/ide.h b/src/libide/ide.h
index 2958a44..ae81bcf 100644
--- a/src/libide/ide.h
+++ b/src/libide/ide.h
@@ -164,6 +164,8 @@ G_BEGIN_DECLS
 #include "symbols/ide-tags-builder.h"
 #include "template/ide-project-template.h"
 #include "template/ide-template-provider.h"
+#include "testing/ide-test.h"
+#include "testing/ide-test-provider.h"
 #include "threading/ide-thread-pool.h"
 #include "transfers/ide-pkcon-transfer.h"
 #include "transfers/ide-transfer.h"
diff --git a/src/libide/meson.build b/src/libide/meson.build
index 5e1473f..67fc7af 100644
--- a/src/libide/meson.build
+++ b/src/libide/meson.build
@@ -87,6 +87,7 @@ subdir('sourceview')
 subdir('subprocess')
 subdir('symbols')
 subdir('template')
+subdir('testing')
 subdir('threading')
 subdir('transfers')
 subdir('util')
diff --git a/src/libide/testing/ide-test-manager.c b/src/libide/testing/ide-test-manager.c
new file mode 100644
index 0000000..0bc1d41
--- /dev/null
+++ b/src/libide/testing/ide-test-manager.c
@@ -0,0 +1,198 @@
+/* ide-test-manager.c
+ *
+ * Copyright © 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-test-manager"
+
+#include <libpeas/peas.h>
+
+#include "ide-debug.h"
+
+#include "testing/ide-test-manager.h"
+#include "testing/ide-test-provider.h"
+
+/**
+ * SECTION:ide-test-manager
+ * @title: IdeTestManager
+ * @short_description: Unit test discover and execution manager
+ *
+ * The #IdeTestManager is responsible for loading unit test provider
+ * plugins (via the #IdeTestProvider interface) and running those unit
+ * tests on behalf of the user.
+ *
+ * You can access the test manager using ide_context_get_text_manager()
+ * using the #IdeContext for the loaded project.
+ *
+ * Since: 3.28
+ */
+
+struct _IdeTestManager
+{
+  IdeObject         parent_instance;
+  PeasExtensionSet *providers;
+  guint             busy : 1;
+};
+
+enum {
+  PROP_0,
+  PROP_BUSY,
+  N_PROPS
+};
+
+static void initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (IdeTestManager, ide_test_manager, IDE_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_test_manager_dispose (GObject *object)
+{
+  IdeTestManager *self = (IdeTestManager *)object;
+
+  g_clear_object (&self->providers);
+
+  G_OBJECT_CLASS (ide_test_manager_parent_class)->dispose (object);
+}
+
+static void
+ide_test_manager_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  IdeTestManager *self = IDE_TEST_MANAGER (object);
+
+  switch (prop_id)
+    {
+    case PROP_BUSY:
+      g_value_set_boolean (value, self->busy);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_test_manager_class_init (IdeTestManagerClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = ide_test_manager_dispose;
+  object_class->get_property = ide_test_manager_get_property;
+
+  /**
+   * IdeTestManager:busy:
+   *
+   * The "busy" property indicates if the #IdeTestManager is currently
+   * processing various background unit tests.
+   *
+   * Since: 3.28
+   */
+  properties [PROP_BUSY] =
+    g_param_spec_boolean ("busy",
+                          "Busy",
+                          "If the test manager is busy processing",
+                          FALSE,
+                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_test_manager_init (IdeTestManager *self)
+{
+}
+
+static void
+ide_test_manager_provider_added (PeasExtensionSet *set,
+                                 PeasPluginInfo   *plugin_info,
+                                 PeasExtension    *exten,
+                                 gpointer          user_data)
+{
+  IdeTestManager *self = user_data;
+  IdeTestProvider *provider = (IdeTestProvider *)exten;
+
+  IDE_ENTRY;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_TEST_PROVIDER (provider));
+  g_assert (IDE_IS_TEST_MANAGER (self));
+
+  IDE_EXIT;
+}
+
+static void
+ide_test_manager_provider_removed (PeasExtensionSet *set,
+                                   PeasPluginInfo   *plugin_info,
+                                   PeasExtension    *exten,
+                                   gpointer          user_data)
+{
+  IdeTestManager *self = user_data;
+  IdeTestProvider *provider = (IdeTestProvider *)exten;
+
+  IDE_ENTRY;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_TEST_PROVIDER (provider));
+  g_assert (IDE_IS_TEST_MANAGER (self));
+
+  IDE_EXIT;
+}
+
+static gboolean
+ide_test_manager_initiable_init (GInitable     *initable,
+                                 GCancellable  *cancellable,
+                                 GError       **error)
+{
+  IdeTestManager *self = (IdeTestManager *)initable;
+  IdeContext *context;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_TEST_MANAGER (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  context = ide_object_get_context (IDE_OBJECT (self));
+
+  self->providers = peas_extension_set_new (peas_engine_get_default (),
+                                            IDE_TYPE_TEST_PROVIDER,
+                                            "context", context,
+                                            NULL);
+
+  g_signal_connect (self->providers,
+                    "extension-added",
+                    G_CALLBACK (ide_test_manager_provider_added),
+                    self);
+
+  g_signal_connect (self->providers,
+                    "extension-removed",
+                    G_CALLBACK (ide_test_manager_provider_removed),
+                    self);
+
+  IDE_RETURN (TRUE);
+}
+
+static void
+initable_iface_init (GInitableIface *iface)
+{
+  iface->init = ide_test_manager_initiable_init;
+}
diff --git a/src/libide/testing/ide-test-manager.h b/src/libide/testing/ide-test-manager.h
new file mode 100644
index 0000000..f05e603
--- /dev/null
+++ b/src/libide/testing/ide-test-manager.h
@@ -0,0 +1,29 @@
+/* ide-test-manager.h
+ *
+ * Copyright © 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ide-object.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TEST_MANAGER (ide_test_manager_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeTestManager, ide_test_manager, IDE, TEST_MANAGER, IdeObject)
+
+G_END_DECLS
diff --git a/src/libide/testing/ide-test-provider.c b/src/libide/testing/ide-test-provider.c
new file mode 100644
index 0000000..ce71dc2
--- /dev/null
+++ b/src/libide/testing/ide-test-provider.c
@@ -0,0 +1,117 @@
+/* ide-test-provider.c
+ *
+ * Copyright © 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-test-provider"
+
+#include "ide-test-provider.h"
+
+G_DEFINE_INTERFACE (IdeTestProvider, ide_test_provider, IDE_TYPE_OBJECT)
+
+static void
+ide_test_provider_real_load_tests_async (IdeTestProvider     *self,
+                                         GCancellable        *cancellable,
+                                         GAsyncReadyCallback  callback,
+                                         gpointer             user_data)
+{
+  g_autoptr(GTask) task = NULL;
+
+  g_return_if_fail (IDE_IS_TEST_PROVIDER (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, ide_test_provider_load_tests_async);
+  g_task_set_priority (task, G_PRIORITY_LOW);
+  g_task_return_new_error (task,
+                           G_IO_ERROR,
+                           G_IO_ERROR_NOT_SUPPORTED,
+                           "Loading tasks is not currently supported");
+}
+
+static GPtrArray *
+ide_test_provider_real_load_tests_finish (IdeTestProvider  *self,
+                                          GAsyncResult     *result,
+                                          GError          **error)
+{
+  return g_task_propagate_pointer (G_TASK (result), error);
+}
+
+static void
+ide_test_provider_default_init (IdeTestProviderInterface *iface)
+{
+  iface->load_tests_async = ide_test_provider_real_load_tests_async;
+  iface->load_tests_finish = ide_test_provider_real_load_tests_finish;
+}
+
+/**
+ * ide_test_provider_load_tests_async:
+ * @self: An #IdeTestProvider
+ * @cancellable: (nullable): A #GCancellable, or %NULL
+ * @callback: A callback for asynchronous notification
+ * @user_data: user data for @callback
+ *
+ * This function will asynchronously load the unit tests that are known
+ * about by a particular #IdeTestProvider plugin.
+ *
+ * @callback is expected to call ide_test_provider_load_tests_finish()
+ * to retrieve the result of this asynchronous operation.
+ *
+ * Since: 3.28
+ */
+void
+ide_test_provider_load_tests_async (IdeTestProvider     *self,
+                                    GCancellable        *cancellable,
+                                    GAsyncReadyCallback  callback,
+                                    gpointer             user_data)
+{
+  g_return_if_fail (IDE_IS_TEST_PROVIDER (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  IDE_TEST_PROVIDER_GET_IFACE (self)->load_tests_async (self,
+                                                        cancellable,
+                                                        callback,
+                                                        user_data);
+}
+
+/**
+ * ide_test_provider_load_tests_finish:
+ * @self: An #IdeTestProvider
+ * @result: A #GAsyncResult provided to callback
+ * @error: A location for a #GError, or %NULL
+ *
+ * Completes an asynchronous operation to
+ * ide_test_provider_load_tests_async().
+ *
+ * If no tests were discovered, and empty #GPtrArray is returned
+ * instead of %NULL.
+ *
+ * Returns: (transfer container) (element-type Ide.Test): An array of
+ *   #IdeTest that were discovered by the test provider; or %NULL upon
+ *   failure and @error is set.
+ *
+ * Since: 3.28
+ */
+GPtrArray *
+ide_test_provider_load_tests_finish (IdeTestProvider  *self,
+                                     GAsyncResult     *result,
+                                     GError          **error)
+{
+  g_return_val_if_fail (IDE_IS_TEST_PROVIDER (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+  return IDE_TEST_PROVIDER_GET_IFACE (self)->load_tests_finish (self, result, error);
+}
diff --git a/src/libide/testing/ide-test-provider.h b/src/libide/testing/ide-test-provider.h
new file mode 100644
index 0000000..b629c24
--- /dev/null
+++ b/src/libide/testing/ide-test-provider.h
@@ -0,0 +1,52 @@
+/* ide-test-provider.h
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ide-object.h"
+
+#include "testing/ide-test.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TEST_PROVIDER (ide_test_provider_get_type ())
+
+G_DECLARE_INTERFACE (IdeTestProvider, ide_test_provider, IDE, TEST_PROVIDER, IdeObject)
+
+struct _IdeTestProviderInterface
+{
+  GTypeInterface parent;
+
+  void (*load_tests_async)        (IdeTestProvider      *self,
+                                   GCancellable         *cancellable,
+                                   GAsyncReadyCallback   callback,
+                                   gpointer              user_data);
+  GPtrArray *(*load_tests_finish) (IdeTestProvider      *self,
+                                   GAsyncResult         *result,
+                                   GError              **error);
+};
+
+void       ide_test_provider_load_tests_async  (IdeTestProvider      *self,
+                                                GCancellable         *cancellable,
+                                                GAsyncReadyCallback   callback,
+                                                gpointer              user_data);
+GPtrArray *ide_test_provider_load_tests_finish (IdeTestProvider      *self,
+                                                GAsyncResult         *result,
+                                                GError              **error);
+
+G_END_DECLS
diff --git a/src/libide/testing/ide-test.c b/src/libide/testing/ide-test.c
new file mode 100644
index 0000000..4c30037
--- /dev/null
+++ b/src/libide/testing/ide-test.c
@@ -0,0 +1,166 @@
+/* ide-test.c
+ *
+ * Copyright © 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-test.h"
+
+typedef struct
+{
+  gchar *name;
+} IdeTestPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeTest, ide_test, G_TYPE_OBJECT)
+
+enum {
+  PROP_0,
+  PROP_NAME,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+IdeTest *
+ide_test_new (void)
+{
+  return g_object_new (IDE_TYPE_TEST, NULL);
+}
+
+static void
+ide_test_finalize (GObject *object)
+{
+  IdeTest *self = (IdeTest *)object;
+  IdeTestPrivate *priv = ide_test_get_instance_private (self);
+
+  g_clear_pointer (&priv->name, g_free);
+
+  G_OBJECT_CLASS (ide_test_parent_class)->finalize (object);
+}
+
+static void
+ide_test_get_property (GObject    *object,
+                       guint       prop_id,
+                       GValue     *value,
+                       GParamSpec *pspec)
+{
+  IdeTest *self = IDE_TEST (object);
+
+  switch (prop_id)
+    {
+    case PROP_NAME:
+      g_value_set_string (value, ide_test_get_name (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_test_set_property (GObject      *object,
+                       guint         prop_id,
+                       const GValue *value,
+                       GParamSpec   *pspec)
+{
+  IdeTest *self = IDE_TEST (object);
+
+  switch (prop_id)
+    {
+    case PROP_NAME:
+      ide_test_set_name (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_test_class_init (IdeTestClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_test_finalize;
+  object_class->get_property = ide_test_get_property;
+  object_class->set_property = ide_test_set_property;
+
+  /**
+   * IdeTest:name:
+   *
+   * The "name" property contains the display name of the test as
+   * the user is expected to read in UI elements.
+   *
+   * Since: 3.28
+   */
+  properties [PROP_NAME] =
+    g_param_spec_string ("name",
+                         "Name",
+                         "The name of the unit test",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_test_init (IdeTest *self)
+{
+}
+
+/**
+ * ide_test_get_name:
+ * @self: An #IdeTest
+ *
+ * Gets the "name" property of the test.
+ *
+ * Returns: (nullable): The name of the test or %NULL
+ *
+ * Since: 3.28
+ */
+const gchar *
+ide_test_get_name (IdeTest *self)
+{
+  IdeTestPrivate *priv = ide_test_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_TEST (self), NULL);
+
+  return priv->name;
+}
+
+/**
+ * ide_test_set_name:
+ * @self: An #IdeTest
+ * @name: (nullable): The name of the test, or %NULL to unset
+ *
+ * Sets the "name" property of the unit test.
+ *
+ * Since: 3.28
+ */
+void
+ide_test_set_name (IdeTest     *self,
+                   const gchar *name)
+{
+  IdeTestPrivate *priv = ide_test_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_TEST (self));
+
+  if (g_strcmp0 (name, priv->name) != 0)
+    {
+      g_free (priv->name);
+      priv->name = g_strdup (priv->name);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_NAME]);
+    }
+}
diff --git a/src/libide/testing/ide-test.h b/src/libide/testing/ide-test.h
new file mode 100644
index 0000000..7469815
--- /dev/null
+++ b/src/libide/testing/ide-test.h
@@ -0,0 +1,45 @@
+/* ide-test.h
+ *
+ * Copyright © 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TEST (ide_test_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (IdeTest, ide_test, IDE, TEST, GObject)
+
+struct _IdeTestClass
+{
+  GObjectClass parent;
+
+  /*< private >*/
+  gpointer _reserved1;
+  gpointer _reserved2;
+  gpointer _reserved3;
+  gpointer _reserved4;
+};
+
+IdeTest     *ide_test_new      (void);
+const gchar *ide_test_get_name (IdeTest     *self);
+void         ide_test_set_name (IdeTest     *self,
+                                const gchar *name);
+
+G_END_DECLS
diff --git a/src/libide/testing/meson.build b/src/libide/testing/meson.build
new file mode 100644
index 0000000..02fa382
--- /dev/null
+++ b/src/libide/testing/meson.build
@@ -0,0 +1,16 @@
+testing_headers = [
+  'ide-test.h',
+  'ide-test-manager.h',
+  'ide-test-provider.h',
+]
+
+testing_sources = [
+  'ide-test.c',
+  'ide-test-manager.c',
+  'ide-test-provider.c',
+]
+
+libide_public_headers += files(testing_headers)
+libide_public_sources += files(testing_sources)
+
+install_headers(testing_headers, subdir: join_paths(libide_header_subdir, 'testing'))


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