summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-04-24 18:46:41 +0200
committerBastien Nocera <hadess@hadess.net>2018-04-24 18:49:01 +0200
commite768f098c918573995dfaaa450e5f25cb159731e (patch)
tree3629598e74e4758160bfc2bcb1afb4d3ccdc1237
parent1cacbda9e76a95217f2c95e777f9c557865df4e0 (diff)
downloadlibgweather-e768f098c918573995dfaaa450e5f25cb159731e.tar.gz
tests: Add online interactive METAR test
Given an ICAO code, fetch the METAR weather for that station. This makes it easier to debug problems with the live system.
-rw-r--r--libgweather/test_metar.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/libgweather/test_metar.c b/libgweather/test_metar.c
index 877ec7e..535ddf6 100644
--- a/libgweather/test_metar.c
+++ b/libgweather/test_metar.c
@@ -16,15 +16,28 @@
#define BUFLEN 4096
#endif /* BUFLEN */
+static void
+weather_updated_cb (GWeatherInfo *info,
+ gpointer user_data)
+{
+ if (gweather_info_is_valid (info))
+ g_message ("Weather updated successfully for %s", info->priv->location.code);
+ else
+ g_warning ("Failed to parse weather for %s", info->priv->location.code);
+
+ g_main_loop_quit (user_data);
+}
+
int
main (int argc, char **argv)
{
FILE *stream = stdin;
gchar* filename = NULL;
+ gchar* code = NULL;
GOptionEntry entries[] = {
- { "file", 'f', 0, G_OPTION_ARG_FILENAME, &filename,
- "file containing METAR observations", NULL },
- { NULL }
+ { "file", 'f', 0, G_OPTION_ARG_FILENAME, &filename, "file containing METAR observations", NULL },
+ { "code", 'c', 0, G_OPTION_ARG_STRING, &code, "ICAO code to get METAR observations from", NULL },
+ { NULL }
};
GOptionContext* context;
GError* error = NULL;
@@ -40,6 +53,25 @@ main (int argc, char **argv)
perror (error->message);
return error->code;
}
+
+ if (code) {
+ GMainLoop *loop;
+
+ loop = g_main_loop_new (NULL, TRUE);
+
+ info = g_object_new (GWEATHER_TYPE_INFO, NULL);
+ info->priv->location.code = g_strdup (code);
+ info->priv->session = soup_session_new ();
+ g_signal_connect (G_OBJECT (info), "updated",
+ G_CALLBACK (weather_updated_cb), loop);
+
+ metar_start_open (info);
+
+ g_main_loop_run (loop);
+
+ return 0;
+ }
+
if (filename) {
stream = fopen (filename, "r");
if (!stream) {