[sysprof] tests: add test for process model from UI



commit 854634e4b00dabf70849cde076080bd6011577cc
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 24 21:59:22 2017 -0800

    tests: add test for process model from UI
    
    This can help shake out issues when dealing with ::items-changed
    events.

 tests/meson.build          |    6 +++
 tests/test-process-model.c |   96 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index a7ada76..591104b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -26,6 +26,12 @@ if get_option('enable_gtk')
   )
   test('test-model-filter', test_model_filter, env: test_env)
 
+  test_process_model = executable('test-process-model',
+    'test-process-model.c',
+    dependencies: libsysprof_ui_dep,
+  )
+  test('test-process-model', test_process_model, env: test_env)
+
   test_zoom = executable('test-zoom',
     'test-zoom.c',
     dependencies: libsysprof_ui_dep,
diff --git a/tests/test-process-model.c b/tests/test-process-model.c
new file mode 100644
index 0000000..f18111f
--- /dev/null
+++ b/tests/test-process-model.c
@@ -0,0 +1,96 @@
+#include <sysprof.h>
+#include <sysprof-ui.h>
+#include <string.h>
+
+static GtkWidget *list;
+
+static GtkWidget *
+create_row (gpointer item,
+            gpointer user_data)
+{
+  return sp_process_model_row_new (item);
+}
+
+static gboolean
+filter_cb (GObject  *object,
+           gpointer  user_data)
+{
+  const gchar *needle = user_data;
+  const gchar *command = sp_process_model_item_get_command_line (SP_PROCESS_MODEL_ITEM (object));
+
+  return !!strstr (command, needle);
+}
+
+static void
+on_entry_changed (GtkEntry      *entry,
+                  SpModelFilter *filter)
+{
+  const gchar *text;
+
+  g_assert (GTK_IS_ENTRY (entry));
+  g_assert (SP_IS_MODEL_FILTER (filter));
+
+  text = gtk_entry_get_text (entry);
+  sp_model_filter_set_filter_func (filter, filter_cb, g_strdup (text), g_free);
+
+  //gtk_list_box_bind_model (GTK_LIST_BOX (list), G_LIST_MODEL (filter), create_row, NULL, NULL);
+}
+
+gint
+main (gint argc,
+      gchar *argv[])
+{
+  SpProcessModel *model;
+  SpModelFilter *filter;
+  GtkWidget *window;
+  GtkWidget *box;
+  GtkWidget *scroller;
+  GtkWidget *entry;
+
+  gtk_init (&argc, &argv);
+
+  window = g_object_new (GTK_TYPE_WINDOW,
+                         "title", "Sysprof Process List",
+                         "default-height", 700,
+                         "default-width", 300,
+                         NULL);
+
+  box = g_object_new (GTK_TYPE_BOX,
+                      "orientation", GTK_ORIENTATION_VERTICAL,
+                      "visible", TRUE,
+                      NULL);
+  gtk_container_add (GTK_CONTAINER (window), box);
+
+  entry = g_object_new (GTK_TYPE_ENTRY,
+                        "visible", TRUE,
+                        NULL);
+  gtk_container_add (GTK_CONTAINER (box), entry);
+
+  scroller = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
+                           "visible", TRUE,
+                           "expand", TRUE,
+                           NULL);
+  gtk_container_add (GTK_CONTAINER (box), scroller);
+
+  list = g_object_new (GTK_TYPE_LIST_BOX,
+                       "visible", TRUE,
+                       NULL);
+  gtk_container_add (GTK_CONTAINER (scroller), list);
+
+  model = sp_process_model_new ();
+  filter = sp_model_filter_new (G_LIST_MODEL (model));
+  gtk_list_box_bind_model (GTK_LIST_BOX (list), G_LIST_MODEL (filter), create_row, NULL, NULL);
+
+  g_signal_connect (entry,
+                    "changed",
+                    G_CALLBACK (on_entry_changed),
+                    filter);
+
+  gtk_window_present (GTK_WINDOW (window));
+  g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
+  gtk_main ();
+
+  g_object_unref (model);
+
+  return 0;
+}


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