[libgweather] lib: Add test for show-virtual property



commit 2e34a45c4f60e227f5b81f7aa0536dac8a3948be
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Nov 30 13:04:03 2017 +0100

    lib: Add test for show-virtual property
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791066

 libgweather/meson.build          |    4 ++
 libgweather/test_locations_utc.c |   67 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/meson.build b/libgweather/meson.build
index ad038db..660e05d 100644
--- a/libgweather/meson.build
+++ b/libgweather/meson.build
@@ -99,6 +99,10 @@ executable('test_locations',
   ['test_locations.c'],
   dependencies: libgweather_dep,
   install: false)
+executable('test_locations_utc',
+  ['test_locations_utc.c'],
+  dependencies: libgweather_dep,
+  install: false)
 #executable('test_metar',
 #  ['test_metar.c', 'weather-metar.c'],
 #  dependencies: libgweather_dep,
diff --git a/libgweather/test_locations_utc.c b/libgweather/test_locations_utc.c
new file mode 100644
index 0000000..a071318
--- /dev/null
+++ b/libgweather/test_locations_utc.c
@@ -0,0 +1,67 @@
+
+#include <gweather-version.h>
+#include "gweather-location-entry.h"
+#include "gweather-timezone-menu.h"
+
+static void
+deleted (GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+    gtk_main_quit ();
+}
+
+static void
+location_changed (GObject *object, GParamSpec *param, gpointer tzmenu)
+{
+    GWeatherLocationEntry *entry = GWEATHER_LOCATION_ENTRY (object);
+    GWeatherLocation *loc;
+    GWeatherTimezone *zone;
+
+    loc = gweather_location_entry_get_location (entry);
+    if (loc == NULL)
+      return;
+
+    zone = gweather_location_get_timezone (loc);
+    if (zone)
+       gweather_timezone_menu_set_tzid (tzmenu, gweather_timezone_get_tzid (zone));
+    else
+       gweather_timezone_menu_set_tzid (tzmenu, NULL);
+    if (zone)
+       gweather_timezone_unref (zone);
+    gweather_location_unref (loc);
+}
+
+int
+main (int argc, char **argv)
+{
+    GtkWidget *window, *vbox, *entry;
+    GtkWidget *combo;
+
+    gtk_init (&argc, &argv);
+
+    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    gtk_window_set_title (GTK_WINDOW (window), "location");
+    gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+    g_signal_connect (window, "delete-event",
+                     G_CALLBACK (deleted), NULL);
+
+    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
+    gtk_container_add (GTK_CONTAINER (window), vbox);
+
+    entry = g_object_new (GWEATHER_TYPE_LOCATION_ENTRY,
+                         "show-named-timezones", TRUE,
+                         NULL);
+    gtk_widget_set_size_request (entry, 400, -1);
+    gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, TRUE, 0);
+
+    combo = gweather_timezone_menu_new (NULL);
+    gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, TRUE, 0);
+
+    g_signal_connect (entry, "notify::location",
+                     G_CALLBACK (location_changed), combo);
+
+    gtk_widget_show_all (window);
+
+    gtk_main ();
+
+    return 0;
+}


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