mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-gtk: add test to list files in UI
This commit is contained in:
@ -14,6 +14,7 @@ libsysprof_gtk_testsuite_c_args = [
|
||||
libsysprof_gtk_testsuite = {
|
||||
'test-callgraph' : {'skip': true},
|
||||
'test-charts' : {'skip': true},
|
||||
'test-files' : {'skip': true},
|
||||
'test-processes' : {'skip': true},
|
||||
'test-tracks' : {'skip': true},
|
||||
'test-mark-chart' : {'skip': true},
|
||||
|
||||
208
src/libsysprof-gtk/tests/test-files.c
Normal file
208
src/libsysprof-gtk/tests/test-files.c
Normal file
@ -0,0 +1,208 @@
|
||||
/* test-files.c
|
||||
*
|
||||
* Copyright 2023 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/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <adwaita.h>
|
||||
#include <libpanel.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <sysprof-analyze.h>
|
||||
#include <sysprof-gtk.h>
|
||||
|
||||
static GMainLoop *main_loop;
|
||||
static char *filename;
|
||||
static const GOptionEntry entries[] = {
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
#define TEST_TYPE_FILES (test_files_get_type())
|
||||
G_DECLARE_FINAL_TYPE (TestFiles, test_files, TEST, FILES, AdwWindow)
|
||||
|
||||
struct _TestFiles
|
||||
{
|
||||
AdwWindow parent_instance;
|
||||
|
||||
SysprofDocument *document;
|
||||
SysprofSession *session;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (TestFiles, test_files, ADW_TYPE_WINDOW)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DOCUMENT,
|
||||
PROP_SESSION,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
test_files_set_document (TestFiles *self,
|
||||
SysprofDocument *document)
|
||||
{
|
||||
if (g_set_object (&self->document, document))
|
||||
{
|
||||
g_clear_object (&self->session);
|
||||
|
||||
self->session = sysprof_session_new (self->document);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DOCUMENT]);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SESSION]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_files_dispose (GObject *object)
|
||||
{
|
||||
TestFiles *self = (TestFiles *)object;
|
||||
|
||||
g_clear_object (&self->document);
|
||||
g_clear_object (&self->session);
|
||||
|
||||
G_OBJECT_CLASS (test_files_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
test_files_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
TestFiles *self = TEST_FILES (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DOCUMENT:
|
||||
g_value_set_object (value, self->document);
|
||||
break;
|
||||
|
||||
case PROP_SESSION:
|
||||
g_value_set_object (value, self->session);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_files_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
TestFiles *self = TEST_FILES (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DOCUMENT:
|
||||
test_files_set_document (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_files_class_init (TestFilesClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->dispose = test_files_dispose;
|
||||
object_class->get_property = test_files_get_property;
|
||||
object_class->set_property = test_files_set_property;
|
||||
|
||||
properties [PROP_DOCUMENT] =
|
||||
g_param_spec_object ("document", NULL, NULL,
|
||||
SYSPROF_TYPE_DOCUMENT,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_SESSION] =
|
||||
g_param_spec_object ("session", NULL, NULL,
|
||||
SYSPROF_TYPE_SESSION,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/test-files.ui");
|
||||
|
||||
g_type_ensure (SYSPROF_TYPE_DOCUMENT_FILE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_files_init (TestFiles *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
g_autoptr(GOptionContext) context = g_option_context_new ("- test various files");
|
||||
g_autoptr(SysprofDocumentLoader) loader = NULL;
|
||||
g_autoptr(SysprofDocument) document = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
GtkWindow *window;
|
||||
|
||||
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);
|
||||
if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
|
||||
g_error ("Failed to load document: %s", error->message);
|
||||
|
||||
window = g_object_new (TEST_TYPE_FILES,
|
||||
"default-width", 800,
|
||||
"default-height", 600,
|
||||
"document", document,
|
||||
NULL);
|
||||
g_signal_connect_swapped (window,
|
||||
"close-request",
|
||||
G_CALLBACK (g_main_loop_quit),
|
||||
main_loop);
|
||||
gtk_window_present (window);
|
||||
g_main_loop_run (main_loop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
src/libsysprof-gtk/tests/test-files.ui
Normal file
56
src/libsysprof-gtk/tests/test-files.ui
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="TestFiles" parent="AdwWindow">
|
||||
<child>
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar">
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkScrolledWindow">
|
||||
<child>
|
||||
<object class="GtkListView">
|
||||
<property name="show-separators">true</property>
|
||||
<style>
|
||||
<class name="data-table"/>
|
||||
</style>
|
||||
<property name="model">
|
||||
<object class="GtkNoSelection">
|
||||
<binding name="model">
|
||||
<lookup name="files" type="SysprofDocument">
|
||||
<lookup name="document">TestFiles</lookup>
|
||||
</lookup>
|
||||
</binding>
|
||||
</object>
|
||||
</property>
|
||||
<property name="factory">
|
||||
<object class="GtkBuilderListItemFactory">
|
||||
<property name="bytes"><![CDATA[
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GtkListItem">
|
||||
<property name="child">
|
||||
<object class="GtkLabel">
|
||||
<property name="xalign">0</property>
|
||||
<binding name="label">
|
||||
<lookup name="path" type="SysprofDocumentFile">
|
||||
<lookup name="item">GtkListItem</lookup>
|
||||
</lookup>
|
||||
</binding>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>
|
||||
]]>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
@ -2,6 +2,7 @@
|
||||
<gresources>
|
||||
<gresource prefix="/">
|
||||
<file preprocess="xml-stripblanks">test-charts.ui</file>
|
||||
<file preprocess="xml-stripblanks">test-files.ui</file>
|
||||
<file preprocess="xml-stripblanks">test-processes.ui</file>
|
||||
<file preprocess="xml-stripblanks">test-tracks.ui</file>
|
||||
</gresource>
|
||||
|
||||
Reference in New Issue
Block a user