[gnome-bluetooth/wip/hadess/lib-changes] lib: Add UI test for the devices GListStore



commit 56bbb5323efeabf876331bc62b5ca9dbe569299f
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Nov 25 11:13:33 2021 +0100

    lib: Add UI test for the devices GListStore

 lib/meson.build      |  1 +
 lib/test-liststore.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
---
diff --git a/lib/meson.build b/lib/meson.build
index 4465e8c0..ed12c5e0 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -150,6 +150,7 @@ test_names = [
   'test-agent',
   'test-class',
   'test-client',
+  'test-liststore',
   'test-pairing-dialog',
   'test-pin',
   'test-settings',
diff --git a/lib/test-liststore.c b/lib/test-liststore.c
new file mode 100644
index 00000000..2900aacc
--- /dev/null
+++ b/lib/test-liststore.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 Bastien Nocera <hadess hadess net>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include <gtk/gtk.h>
+#include <adwaita.h>
+
+#include "bluetooth-client.h"
+#include "bluetooth-device.h"
+
+static GtkWidget *
+create_device_cb (gpointer item, gpointer user_data)
+{
+       BluetoothDevice *device = BLUETOOTH_DEVICE (item);
+       g_autofree char *label_str = NULL;
+       GtkWidget *row;
+
+       label_str = bluetooth_device_to_string (device);
+       row = gtk_list_box_row_new ();
+       gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), gtk_label_new (label_str));
+       return row;
+}
+
+int main (int argc, char **argv)
+{
+       GtkWidget *window;
+       GtkWidget *listbox;
+       GListStore *model;
+       g_autoptr(BluetoothClient) client = NULL;
+
+       gtk_init();
+       adw_init ();
+
+       window = gtk_window_new();
+       gtk_window_set_title(GTK_WINDOW(window), "Test client");
+       gtk_window_set_icon_name(GTK_WINDOW(window), "bluetooth");
+       gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
+
+       client = bluetooth_client_new ();
+       model = bluetooth_client_get_devices (client);
+       listbox = gtk_list_box_new ();
+       gtk_list_box_bind_model (GTK_LIST_BOX (listbox), G_LIST_MODEL (model), create_device_cb, NULL, NULL);
+       gtk_window_set_child (GTK_WINDOW (window), listbox);
+       gtk_widget_show (window);
+
+       while (g_list_model_get_n_items (gtk_window_get_toplevels()) > 0)
+               g_main_context_iteration (NULL, TRUE);
+
+       return 0;
+}


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