From e05dcdde03b112620e3a490cf0bfe223c803c230 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 20 Jun 2023 11:10:43 -0700 Subject: [PATCH] libsysprof-gtk: start on test for charts --- src/libsysprof-gtk/tests/test-charts.c | 106 +++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/libsysprof-gtk/tests/test-charts.c diff --git a/src/libsysprof-gtk/tests/test-charts.c b/src/libsysprof-gtk/tests/test-charts.c new file mode 100644 index 00000000..4b01a4ff --- /dev/null +++ b/src/libsysprof-gtk/tests/test-charts.c @@ -0,0 +1,106 @@ +/* test-charts.c + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include +#include +#include +#include + +static GMainLoop *main_loop; +static char *filename; +static const GOptionEntry entries[] = { + { 0 } +}; + +int +main (int argc, + char *argv[]) +{ + g_autoptr(GOptionContext) context = g_option_context_new ("- test various charts"); + g_autoptr(SysprofDocumentLoader) loader = NULL; + g_autoptr(SysprofDocument) document = NULL; + g_autoptr(SysprofSession) session = NULL; + g_autoptr(GError) error = NULL; + GtkWidget *chart; + GtkWidget *layer; + GtkWindow *window; + GtkWidget *box; + + sysprof_clock_init (); + + gtk_init (); + adw_init (); + + g_option_context_add_main_entries (context, entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_printerr ("%s\n", error->message); + return 1; + } + + if (argc != 2) + { + g_print ("usage: %s [OPTIONS] CAPTURE_FILE\n", argv[0]); + return 1; + } + + filename = argv[1]; + + main_loop = g_main_loop_new (NULL, FALSE); + + loader = sysprof_document_loader_new (filename); + sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ()); + + if (!(document = sysprof_document_loader_load (loader, NULL, &error))) + g_error ("Failed to load document: %s", error->message); + + session = sysprof_session_new (document); + + window = g_object_new (GTK_TYPE_WINDOW, + "default-width", 800, + "default-height", 600, + NULL); + g_signal_connect_swapped (window, + "close-request", + G_CALLBACK (g_main_loop_quit), + main_loop); + + box = g_object_new (GTK_TYPE_BOX, + "orientation", GTK_ORIENTATION_VERTICAL, + NULL); + gtk_window_set_child (window, GTK_WIDGET (box)); + + chart = g_object_new (SYSPROF_TYPE_CHART, + "session", session, + "title", "Stack Traces", + NULL); + layer = g_object_new (SYSPROF_TYPE_DEPTH_LAYER, + NULL); + sysprof_chart_add_layer (SYSPROF_CHART (chart), + SYSPROF_CHART_LAYER (layer)); + gtk_box_append (GTK_BOX (box), chart); + + gtk_window_present (window); + g_main_loop_run (main_loop); + + return 0; +}