Remove set-hooks.h from generic includes
[glibc.git] / time / bug-getdate1.c
blob9afafba5bebc6919d44a42a081620548b552c730
1 /* BZ #5451 */
2 #include <time.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #include <support/temp_file.h>
8 static char *templ_filename;
10 // Writes template given as parameter to file,
11 // specified as the argument
12 static void
13 output_to_template_file (const char *str)
15 FILE *fd = fopen (templ_filename, "w");
16 if (fd == NULL)
18 printf ("Can not open file for writing\n");
19 exit (1);
22 fprintf (fd, "%s\n", str);
23 fclose (fd);
26 // Calls getdate() function with specified parameter,
27 // specified as the argument, also checks the contents of
28 // file with template and prints the result
29 static int
30 process_getdate_on (const char *str)
32 struct tm *res;
33 char templ[1000];
34 FILE *fd = fopen (templ_filename, "r");
36 if (fd == NULL)
38 printf ("Can not open file for reading\n");
39 exit (1);
42 if (fgets (templ, 1000, fd) == NULL)
44 printf ("Can not read file\n");
45 exit (1);
47 fclose (fd);
49 res = getdate (str);
50 if (res == NULL)
52 printf ("Failed on getdate(\"%s\"), template is: %s", str, templ);
53 printf ("Error number: %d\n\n", getdate_err);
54 return 1;
56 printf ("Success on getdate(\"%s\"), template is: %s\n", str, templ);
57 printf ("Result is\n");
58 printf ("Seconds: %d\n", res->tm_sec);
59 printf ("Minutes: %d\n", res->tm_min);
60 printf ("Hour: %d\n", res->tm_hour);
61 printf ("Day of month: %d\n", res->tm_mday);
62 printf ("Month of year: %d\n", res->tm_mon);
63 printf ("Years since 1900: %d\n", res->tm_year);
64 printf ("Day of week: %d\n", res->tm_wday);
65 printf ("Day of year: %d\n", res->tm_yday);
66 printf ("Daylight Savings flag: %d\n\n", res->tm_isdst);
67 return 0;
70 static int
71 do_test (int argc, char *argv[])
74 templ_filename = argv[1];
76 setenv ("DATEMSK", templ_filename, 1);
79 * The following 4 testcases reproduce the problem:
80 * 1. Templates "%S" and "%M" are not processed,
81 * when used without "%H" template
83 int res = 0;
84 output_to_template_file ("%M");
85 res |= process_getdate_on ("1");
87 output_to_template_file ("%M %H");
88 res |= process_getdate_on ("1 2");
90 output_to_template_file ("%S");
91 res |= process_getdate_on ("1");
93 output_to_template_file ("%S %H");
94 res |= process_getdate_on ("1 2");
97 * The following 9 testcases reproduce the problem:
98 * 2. Templates "%Y", "%y", "%d", "%C", "%C %y"
99 * are not processed separately
101 output_to_template_file ("%Y");
102 process_getdate_on ("2001");
104 output_to_template_file ("%Y %m");
105 res |= process_getdate_on ("2001 3");
107 output_to_template_file ("%y");
108 res |= process_getdate_on ("70");
110 output_to_template_file ("%y %m");
111 res |= process_getdate_on ("70 3");
113 output_to_template_file ("%d");
114 res |= process_getdate_on ("06");
116 output_to_template_file ("%d %m");
117 res |= process_getdate_on ("25 3");
119 output_to_template_file ("%C");
120 res |= process_getdate_on ("20");
122 output_to_template_file ("%C %y %m");
123 res |= process_getdate_on ("20 3 2");
125 output_to_template_file ("%C %y");
126 res |= process_getdate_on ("20 5");
129 * The following testcase reproduces the problem:
130 * 3. When template is "%Y %m", day of month is not set
131 * to 1 as standard requires
133 output_to_template_file ("%Y %m");
134 res |= process_getdate_on ("2008 3");
136 return res;
138 #define TEST_FUNCTION_ARGV do_test
140 static void
141 do_prepare (int argc, char **argv)
143 if (argc < 2)
145 puts ("Command line: progname template_filename_full_path");
146 exit (1);
148 add_temp_file (argv[1]);
150 #define PREPARE do_prepare
152 #include <support/test-driver.c>