6 #include <support/temp_file.h>
8 static char *templ_filename
;
10 // Writes template given as parameter to file,
11 // specified as the argument
13 output_to_template_file (const char *str
)
15 FILE *fd
= fopen (templ_filename
, "w");
18 printf ("Can not open file for writing\n");
22 fprintf (fd
, "%s\n", str
);
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
30 process_getdate_on (const char *str
)
34 FILE *fd
= fopen (templ_filename
, "r");
38 printf ("Can not open file for reading\n");
42 if (fgets (templ
, 1000, fd
) == NULL
)
44 printf ("Can not read file\n");
52 printf ("Failed on getdate(\"%s\"), template is: %s", str
, templ
);
53 printf ("Error number: %d\n\n", getdate_err
);
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
);
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
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");
138 #define TEST_FUNCTION_ARGV do_test
141 do_prepare (int argc
, char **argv
)
145 puts ("Command line: progname template_filename_full_path");
148 add_temp_file (argv
[1]);
150 #define PREPARE do_prepare
152 #include <support/test-driver.c>