build: Add missing "static" keyword where it should be used
[platform/upstream/glib.git] / tests / testgdateparser.c
1 #undef G_DISABLE_ASSERT
2 #undef G_LOG_DOMAIN
3
4 #ifdef GLIB_COMPILATION
5 #undef GLIB_COMPILATION
6 #endif
7
8 #include "glib.h"
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <locale.h>
13
14 static void
15 g_date_debug_print (GDate* d)
16 {
17   if (!d) g_print("NULL!\n");
18   else 
19     g_print("julian: %u (%s) DMY: %u %u %u (%s)\n",
20             d->julian_days, 
21             d->julian ? "valid" : "invalid",
22             d->day,
23             d->month,
24             d->year,
25             d->dmy ? "valid" : "invalid");
26   
27   fflush(stdout);
28 }
29
30 /* These only work in the POSIX locale, maybe C too - 
31  * type POSIX into the program to check them
32  */
33 char* posix_tests [] = {
34   "19981024",
35   "981024",
36   "October 1998",
37   "October 98",
38   "oCT 98",
39   "10/24/98",
40   "10 -- 24 -- 98",
41   "10/24/1998",
42   "October 24, 1998",
43   NULL
44 };
45
46 int main(int argc, char** argv)
47 {
48   GDate* d;
49   gchar* loc;
50   gchar input[1024];
51
52   loc = setlocale(LC_ALL,"");
53   if (loc) 
54     g_print("\nLocale set to %s\n", loc);
55   else 
56     g_print("\nLocale unchanged\n");
57
58   d = g_date_new();
59
60   while (fgets(input, 1023, stdin))
61     {
62       if (input[0] == '\n') 
63         {
64           g_print("Enter a date to parse and press enter, or type `POSIX':\n");
65           continue;
66         }
67
68       if (strcmp(input,"POSIX\n") == 0) 
69         {
70           char** s = posix_tests;
71           while (*s) {
72             g_date_set_parse(d, *s);
73             
74             g_print("POSIXy parse test `%s' ...", *s);
75
76             if (!g_date_valid(d))
77               {
78                 g_print(" failed.\n");
79               }
80             else 
81               {
82                 gchar buf[256];
83                 
84                 g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n",
85                                 d);
86                 g_print("%s", buf);
87               }
88
89             ++s;
90           }
91         }
92       else 
93         {
94           g_date_set_parse(d, input);
95           
96           if (!g_date_valid(d))
97             {
98               g_print("Parse failed.\n");
99             }
100           else 
101             {
102               gchar buf[256];
103               
104               g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n",
105                               d);
106               g_print("%s", buf);
107             }
108         }
109     }
110
111   g_date_free(d);
112
113   return 0;
114 }
115
116