Add some more cases to the app-id unit tests
[glib.git] / tests / testgdateparser.c
blobdea5602483b63ad9d18de1aecfedf47fac5a6be7
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 /* These only work in the POSIX locale, maybe C too -
15 * type POSIX into the program to check them
17 char* posix_tests [] = {
18 "19981024",
19 "981024",
20 "October 1998",
21 "October 98",
22 "oCT 98",
23 "10/24/98",
24 "10 -- 24 -- 98",
25 "10/24/1998",
26 "October 24, 1998",
27 NULL
30 int main(int argc, char** argv)
32 GDate* d;
33 gchar* loc;
34 gchar input[1024];
36 loc = setlocale(LC_ALL,"");
37 if (loc)
38 g_print("\nLocale set to %s\n", loc);
39 else
40 g_print("\nLocale unchanged\n");
42 d = g_date_new();
44 while (fgets(input, 1023, stdin))
46 if (input[0] == '\n')
48 g_print("Enter a date to parse and press enter, or type 'POSIX':\n");
49 continue;
52 if (strcmp(input,"POSIX\n") == 0)
54 char** s = posix_tests;
55 while (*s) {
56 g_date_set_parse(d, *s);
58 g_print("POSIXy parse test '%s' ...", *s);
60 if (!g_date_valid(d))
62 g_print(" failed.\n");
64 else
66 gchar buf[256];
68 g_date_strftime(buf,100," parsed '%x' (%B %d %Y)\n",
69 d);
70 g_print("%s", buf);
73 ++s;
76 else
78 g_date_set_parse(d, input);
80 if (!g_date_valid(d))
82 g_print("Parse failed.\n");
84 else
86 gchar buf[256];
88 g_date_strftime(buf,100,"Parsed: '%x' (%B %d %Y)\n",
89 d);
90 g_print("%s", buf);
95 g_date_free(d);
97 return 0;