Fix #132858, Sven Neumann, patch by James Henstridge:
[glib.git] / tests / testgdateparser.c
blobf0e284a2b8b0e61cc4e15e82fb36dace3a3b0e81
1 #undef G_DISABLE_ASSERT
2 #undef G_LOG_DOMAIN
4 #ifdef GLIB_COMPILATION
5 #undef GLIB_COMPILATION
6 #endif
8 #include "glib.h"
10 #include <stdio.h>
11 #include <string.h>
12 #include <locale.h>
14 void g_date_debug_print(GDate* d)
16 if (!d) g_print("NULL!\n");
17 else
18 g_print("julian: %u (%s) DMY: %u %u %u (%s)\n",
19 d->julian_days,
20 d->julian ? "valid" : "invalid",
21 d->day,
22 d->month,
23 d->year,
24 d->dmy ? "valid" : "invalid");
26 fflush(stdout);
29 /* These only work in the POSIX locale, maybe C too -
30 * type POSIX into the program to check them
32 char* posix_tests [] = {
33 "19981024",
34 "981024",
35 "October 1998",
36 "October 98",
37 "oCT 98",
38 "10/24/98",
39 "10 -- 24 -- 98",
40 "10/24/1998",
41 "October 24, 1998",
42 NULL
45 int main(int argc, char** argv)
47 GDate* d;
48 gchar* loc;
49 gchar input[1024];
51 loc = setlocale(LC_ALL,"");
52 if (loc)
53 g_print("\nLocale set to %s\n", loc);
54 else
55 g_print("\nLocale unchanged\n");
57 d = g_date_new();
59 while (fgets(input, 1023, stdin))
61 if (input[0] == '\n')
63 g_print("Enter a date to parse and press enter, or type `POSIX':\n");
64 continue;
67 if (strcmp(input,"POSIX\n") == 0)
69 char** s = posix_tests;
70 while (*s) {
71 g_date_set_parse(d, *s);
73 g_print("POSIXy parse test `%s' ...", *s);
75 if (!g_date_valid(d))
77 g_print(" failed.\n");
79 else
81 gchar buf[256];
83 g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n",
84 d);
85 g_print("%s", buf);
88 ++s;
91 else
93 g_date_set_parse(d, input);
95 if (!g_date_valid(d))
97 g_print("Parse failed.\n");
99 else
101 gchar buf[256];
103 g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n",
105 g_print("%s", buf);
110 g_date_free(d);
112 return 0;