Move BZ#11261 from 2.18 to 2.16 bug list.
[glibc.git] / time / bug-getdate1.c
blob3d68cf2a79f69fba08689314703abc8c869bc637
1 /* BZ #5451 */
2 #include <time.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 static char *templ_filename;
8 // Writes template given as parameter to file,
9 // specified as the argument
10 static void
11 output_to_template_file (const char *str)
13 FILE *fd = fopen (templ_filename, "w");
14 if (fd == NULL)
16 printf ("Can not open file for writing\n");
17 exit (1);
20 fprintf (fd, "%s\n", str);
21 fclose (fd);
24 // Calls getdate() function with specified parameter,
25 // specified as the argument, also checks the contents of
26 // file with template and prints the result
27 static int
28 process_getdate_on (const char *str)
30 struct tm *res;
31 char templ[1000];
32 FILE *fd = fopen (templ_filename, "r");
34 if (fd == NULL)
36 printf ("Can not open file for reading\n");
37 exit (1);
40 if (fgets (templ, 1000, fd) == NULL)
42 printf ("Can not read file\n");
43 exit (1);
45 fclose (fd);
47 res = getdate (str);
48 if (res == NULL)
50 printf ("Failed on getdate(\"%s\"), template is: %s", str, templ);
51 printf ("Error number: %d\n\n", getdate_err);
52 return 1;
54 printf ("Success on getdate(\"%s\"), template is: %s\n", str, templ);
55 printf ("Result is\n");
56 printf ("Seconds: %d\n", res->tm_sec);
57 printf ("Minutes: %d\n", res->tm_min);
58 printf ("Hour: %d\n", res->tm_hour);
59 printf ("Day of month: %d\n", res->tm_mday);
60 printf ("Month of year: %d\n", res->tm_mon);
61 printf ("Years since 1900: %d\n", res->tm_year);
62 printf ("Day of week: %d\n", res->tm_wday);
63 printf ("Day of year: %d\n", res->tm_yday);
64 printf ("Daylight Savings flag: %d\n\n", res->tm_isdst);
65 return 0;
68 static int
69 do_test (int argc, char *argv[])
72 templ_filename = argv[1];
74 setenv ("DATEMSK", templ_filename, 1);
77 * The following 4 testcases reproduce the problem:
78 * 1. Templates "%S" and "%M" are not processed,
79 * when used without "%H" template
81 int res = 0;
82 output_to_template_file ("%M");
83 res |= process_getdate_on ("1");
85 output_to_template_file ("%M %H");
86 res |= process_getdate_on ("1 2");
88 output_to_template_file ("%S");
89 res |= process_getdate_on ("1");
91 output_to_template_file ("%S %H");
92 res |= process_getdate_on ("1 2");
95 * The following 9 testcases reproduce the problem:
96 * 2. Templates "%Y", "%y", "%d", "%C", "%C %y"
97 * are not processed separately
99 output_to_template_file ("%Y");
100 process_getdate_on ("2001");
102 output_to_template_file ("%Y %m");
103 res |= process_getdate_on ("2001 3");
105 output_to_template_file ("%y");
106 res |= process_getdate_on ("70");
108 output_to_template_file ("%y %m");
109 res |= process_getdate_on ("70 3");
111 output_to_template_file ("%d");
112 res |= process_getdate_on ("06");
114 output_to_template_file ("%d %m");
115 res |= process_getdate_on ("25 3");
117 output_to_template_file ("%C");
118 res |= process_getdate_on ("20");
120 output_to_template_file ("%C %y %m");
121 res |= process_getdate_on ("20 3 2");
123 output_to_template_file ("%C %y");
124 res |= process_getdate_on ("20 5");
127 * The following testcase reproduces the problem:
128 * 3. When template is "%Y %m", day of month is not set
129 * to 1 as standard requires
131 output_to_template_file ("%Y %m");
132 res |= process_getdate_on ("2008 3");
134 return res;
137 #define PREPARE(argc, argv) \
138 if (argc < 2) \
140 puts ("Command line: progname template_filename_full_path"); \
141 exit (1); \
143 add_temp_file (argv[1])
145 #define TEST_FUNCTION do_test (argc, argv)
146 #include "../test-skeleton.c"