[libgweather/wip/hadess/serialisation-fix: 13/17] tests: Print metar info when successful



commit 30869ac6a637bae3c034b6e1466fc908af4ee953
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Oct 9 20:18:16 2018 +0200

    tests: Print metar info when successful

 libgweather/test_metar.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/libgweather/test_metar.c b/libgweather/test_metar.c
index 7caf194..46ff76d 100644
--- a/libgweather/test_metar.c
+++ b/libgweather/test_metar.c
@@ -17,14 +17,33 @@
 #endif /* BUFLEN */
 
 static void
-weather_updated_cb (GWeatherInfo *info,
-                   gpointer      user_data)
+print_info (GWeatherInfo *info)
 {
-    if (gweather_info_is_valid (info))
+    if (gweather_info_is_valid (info)) {
         g_message ("Weather updated successfully for %s", info->priv->location.code);
-    else
+    } else {
         g_warning ("Failed to parse weather for %s", info->priv->location.code);
+        return;
+    }
+
+    printf ("Returned info:\n");
+    printf ("  update:   %s", ctime (&info->priv->update));
+    printf ("  sky:      %s\n", gweather_info_get_sky (info));
+    printf ("  cond:     %s\n", gweather_info_get_conditions (info));
+    printf ("  temp:     %s\n", gweather_info_get_temp (info));
+    printf ("  dewp:     %s\n", gweather_info_get_dew (info));
+    printf ("  wind:     %s\n", gweather_info_get_wind (info));
+    printf ("  pressure: %s\n", gweather_info_get_pressure (info));
+    printf ("  vis:      %s\n", gweather_info_get_visibility (info));
+
+    // TODO: retrieve location's lat/lon to display sunrise/set times
+}
 
+static void
+weather_updated_cb (GWeatherInfo *info,
+                   gpointer      user_data)
+{
+    print_info (info);
     g_main_loop_quit (user_data);
 }
 
@@ -94,17 +113,7 @@ main (int argc, char **argv)
        info = g_object_new (GWEATHER_TYPE_INFO, NULL);
        info->priv->valid = 1;
        metar_parse (buf, info);
-       printf ("Returned info:\n");
-       printf ("  update:   %s", ctime (&info->priv->update));
-       printf ("  sky:      %s\n", gweather_info_get_sky (info));
-       printf ("  cond:     %s\n", gweather_info_get_conditions (info));
-       printf ("  temp:     %s\n", gweather_info_get_temp (info));
-       printf ("  dewp:     %s\n", gweather_info_get_dew (info));
-       printf ("  wind:     %s\n", gweather_info_get_wind (info));
-       printf ("  pressure: %s\n", gweather_info_get_pressure (info));
-       printf ("  vis:      %s\n", gweather_info_get_visibility (info));
-
-       // TODO: retrieve location's lat/lon to display sunrise/set times
+       print_info (info);
     }
     return 0;
 }


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