6 static char *templ_filename;
8 // Writes template given as parameter to file,
9 // specified as the argument
11 output_to_template_file (const char *str)
13 FILE *fd = fopen (templ_filename, "w");
16 printf ("Can not open file for writing\n");
20 fprintf (fd, "%s\n", str);
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
28 process_getdate_on (const char *str)
32 FILE *fd = fopen (templ_filename, "r");
36 printf ("Can not open file for reading\n");
40 if (fgets (templ, 1000, fd) == NULL)
42 printf ("Can not read file\n");
50 printf ("Failed on getdate(\"%s\"), template is: %s", str, templ);
51 printf ("Error number: %d\n\n", getdate_err);
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);
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
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 ("98");
120 output_to_template_file ("%C %y %m");
121 res |= process_getdate_on ("98 3 2");
123 output_to_template_file ("%C %y");
124 res |= process_getdate_on ("21 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");
137 #define PREPARE(argc, argv) \
140 puts ("Command line: progname template_filename_full_path"); \
143 add_temp_file (argv[1])
145 #define TEST_FUNCTION do_test (argc, argv)
146 #include "../test-skeleton.c"