tests: Rework test-timezone-gfx

This commit is contained in:
Georges Basile Stavracas Neto 2018-05-09 16:16:25 -03:00
parent 0b854910bb
commit c23e8f3547

View file

@ -1,5 +1,6 @@
#include <config.h> #include <config.h>
#include <locale.h> #include <locale.h>
#include <gtk/gtk.h>
#include "cc-datetime-resources.h" #include "cc-datetime-resources.h"
#include "tz.h" #include "tz.h"
@ -7,40 +8,44 @@
static void static void
test_timezone_gfx (gconstpointer data) test_timezone_gfx (gconstpointer data)
{ {
const char *pixmap_dir = data;
g_autoptr(TzDB) db = NULL; g_autoptr(TzDB) db = NULL;
GPtrArray *locs; GPtrArray *locs;
const char *pixmap_dir;
guint i; guint i;
pixmap_dir = data;
db = tz_load_db (); db = tz_load_db ();
locs = tz_get_locations (db); locs = tz_get_locations (db);
for (i = 0; i < locs->len ; i++) {
TzLocation *loc = locs->pdata[i]; for (i = 0; i < locs->len ; i++)
TzInfo *info; {
g_autofree gchar *filename = NULL; g_autofree gchar *filename = NULL;
g_autofree gchar *path = NULL; g_autofree gchar *path = NULL;
TzLocation *location;
TzInfo *info;
gdouble selected_offset; gdouble selected_offset;
char buf[16]; gchar buf[16];
info = tz_info_from_location (loc); location = locs->pdata[i];
selected_offset = tz_location_get_utc_offset (loc) info = tz_info_from_location (location);
/ (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0); selected_offset = tz_location_get_utc_offset (location) / (60.0 * 60.0) + (info->daylight ? -1.0 : 0.0);
filename = g_strdup_printf ("timezone_%s.png", filename = g_strdup_printf ("timezone_%s.png", g_ascii_formatd (buf, sizeof (buf), "%g", selected_offset));
g_ascii_formatd (buf, sizeof (buf),
"%g", selected_offset));
path = g_build_filename (pixmap_dir, filename, NULL); path = g_build_filename (pixmap_dir, filename, NULL);
if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) { if (!g_file_test (path, G_FILE_TEST_IS_REGULAR))
g_message ("File '%s' missing for zone '%s'", filename, loc->zone); {
g_message ("File '%s' missing for zone '%s'", filename, location->zone);
g_test_fail (); g_test_fail ();
} }
} }
} }
int main (int argc, char **argv) gint
main (gint argc,
gchar **argv)
{ {
char *pixmap_dir; gchar *pixmap_dir;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
@ -49,11 +54,16 @@ int main (int argc, char **argv)
g_resources_register (cc_datetime_get_resource ()); g_resources_register (cc_datetime_get_resource ());
if (argc == 2) { if (argc == 2)
{
pixmap_dir = g_strdup (argv[1]); pixmap_dir = g_strdup (argv[1]);
} else if (argc == 1) { }
else if (argc == 1)
{
pixmap_dir = g_strdup (SRCDIR "/data/"); pixmap_dir = g_strdup (SRCDIR "/data/");
} else { }
else
{
g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]); g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
return 1; return 1;
} }