1 /*
2 * Copyright (c) 2005-2015 Balabit
3 * Copyright (c) 2005-2011 Balázs Scheidler
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * As an additional exemption you are allowed to compile & link against the
19 * OpenSSL libraries as published by the OpenSSL project. See the file
20 * COPYING for details.
21 *
22 */
23
24 #include "apphook.h"
25 #include "timeutils/cache.h"
26 #include "timeutils/misc.h"
27 #include "timeutils/zoneinfo.h"
28 #include "timeutils/unixtime.h"
29 #include "timeutils/format.h"
30 #include <criterion/criterion.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdio.h>
34
35
36 typedef struct _TimezoneOffsetTestCase
37 {
38 const gchar *time_zone;
39 time_t utc;
40 long expected_offset;
41 } TimezoneOffsetTestCase;
42
43 typedef struct _TimezoneTestCase
44 {
45 const time_t stamp_to_test;
46 const gchar *time_zone;
47 } TimezoneTestCase;
48
49 typedef struct _TimestampFormatTestCase
50 {
51 gint format;
52 glong zone_offset;
53 gint frac_digits;
54 gchar *expected_format;
55 } TimestampFormatTestCase;
56
57 void
set_time_zone(const gchar * time_zone)58 set_time_zone(const gchar *time_zone)
59 {
60 setenv("TZ", time_zone, TRUE);
61 invalidate_timeutils_cache();
62 }
63
64 int
time_zone_exists(const char * time_zone)65 time_zone_exists(const char *time_zone)
66 {
67 TimeZoneInfo *info;
68
69 set_time_zone(time_zone);
70 info = time_zone_info_new(time_zone);
71
72 if (info)
73 {
74 time_zone_info_free(info);
75 return TRUE;
76 }
77 return FALSE;
78 }
79
80 void
test_time_zone(const time_t stamp_to_test,const char * time_zone)81 test_time_zone(const time_t stamp_to_test, const char *time_zone)
82 {
83 TimeZoneInfo *info;
84 time_t offset, expected_offset;
85
86 set_time_zone(time_zone);
87 info = time_zone_info_new(time_zone);
88 offset = time_zone_info_get_offset(info, stamp_to_test);
89 expected_offset = get_local_timezone_ofs(stamp_to_test);
90 cr_assert_eq(difftime(offset, expected_offset), 0.0,
91 "unixtimestamp: %ld TimeZoneName (%s) localtime offset(%ld), timezone file offset(%ld)\n",
92 (glong) stamp_to_test, time_zone, (glong) expected_offset, (glong) offset);
93
94 time_zone_info_free(info);
95 }
96
97 void
assert_time_zone(TimezoneTestCase c)98 assert_time_zone(TimezoneTestCase c)
99 {
100 if (!time_zone_exists(c.time_zone))
101 {
102 printf("SKIP: %s\n", c.time_zone);
103 return;
104 }
105 test_time_zone(c.stamp_to_test, c.time_zone);
106 test_time_zone(c.stamp_to_test - 6*30*24*60*60, c.time_zone);
107 test_time_zone(c.stamp_to_test + 6*30*24*6, c.time_zone);
108 }
109
110 void
assert_time_zone_offset(TimezoneOffsetTestCase c)111 assert_time_zone_offset(TimezoneOffsetTestCase c)
112 {
113 long offset;
114
115 set_time_zone(c.time_zone);
116
117 offset = get_local_timezone_ofs(c.utc);
118 cr_assert_eq(offset, c.expected_offset,
119 "Timezone offset mismatch: zone: %s, %ld, expected %ld\n", c.time_zone, offset, c.expected_offset);
120 }
121
122 void
assert_timestamp_format(GString * target,UnixTime * stamp,TimestampFormatTestCase c)123 assert_timestamp_format(GString *target, UnixTime *stamp, TimestampFormatTestCase c)
124 {
125 format_unix_time(stamp, target, c.format, c.zone_offset, c.frac_digits);
126 cr_assert_str_eq(target->str, c.expected_format, "Actual: %s, Expected: %s", target->str, c.expected_format);
127 }
128
129 TestSuite(zone, .init = app_startup, .fini = app_shutdown);
130
Test(zone,test_time_zone_offset)131 Test(zone, test_time_zone_offset)
132 {
133 TimezoneOffsetTestCase test_cases[] =
134 {
135 /* 2005-10-14 21:47:37 CEST, dst enabled */
136 {"MET-1METDST", 1129319257, 7200},
137 /* 2005-11-14 10:10:00 CET, dst disabled */
138 {"MET-1METDST", 1131959400, 3600},
139 /* 2005-10-14 21:47:37 GMT, no DST */
140 {"GMT", 1129319257, 0},
141 /* 2005-11-14 10:10:00 GMT, no DST */
142 {"GMT", 1131959400, 0},
143 /* 2005-04-03 01:30:00 ESD, DST disabled */
144 {"EST5EDT", 1112509800, -5*3600},
145 /* 2005-04-03 01:59:59 ESD, DST disabled */
146 {"EST5EDT", 1112511599, -5*3600},
147 /* 2005-04-03 03:00:00 EDT, DST enabled */
148 {"EST5EDT", 1112511600, -4*3600},
149 /* 2005-04-03 03:00:01 EDT, DST enabled */
150 {"EST5EDT", 1112511601, -4*3600},
151 /* 2005-10-30 01:59:59 EDT, DST enabled */
152 {"EST5EDT", 1130651999, -4*3600},
153 /* 2005-10-30 01:00:00 EST, DST disabled */
154 {"EST5EDT", 1130652000, -5*3600},
155 /* 2007-03-11 01:00:00 EST, DST disabled */
156 {"EST5EDT", 1173592800, -5*3600},
157 /* 2007-03-11 01:59:59 EST, DST disabled */
158 {"EST5EDT", 1173596399, -5*3600},
159 /* 2007-03-11 03:00:00 EST, DST enabled */
160 {"EST5EDT", 1173596400, -4*3600},
161 /* 2007-11-04 01:59:59 EST, DST enabled */
162 {"EST5EDT", 1194155999, -4*3600},
163 /* 2007-11-04 01:00:00 EST, DST disabled */
164 {"EST5EDT", 1194156000, -5*3600},
165 /* Oct 31 01:59:59 2004 (EST) +1000 */
166 {"Australia/Victoria", 1099151999, 10*3600},
167 /* Oct 31 03:00:00 2004 (EST) +1100 */
168 {"Australia/Victoria", 1099152000, 11*3600},
169 /* Mar 27 02:59:59 2005 (EST) +1100 */
170 {"Australia/Victoria", 1111852799, 11*3600},
171 /* Mar 27 02:00:00 2005 (EST) +1000 */
172 {"Australia/Victoria", 1111852800, 10*3600},
173 /* Oct 2 01:59:59 2004 (NZT) +1200 */
174 {"NZ", 1128175199, 12*3600},
175 /* Oct 2 03:00:00 2004 (NZDT) +1300 */
176 {"NZ", 1128175200, 13*3600},
177 /* Mar 20 02:59:59 2005 (NZDT) +1300 */
178 {"NZ", 1111240799, 13*3600},
179 /* Mar 20 02:00:00 2005 (NZT) +1200 */
180 {"NZ", 1111240800, 12*3600},
181 };
182 gint i, nr_of_cases;
183
184 nr_of_cases = sizeof(test_cases) / sizeof(test_cases[0]);
185 for (i = 0; i < nr_of_cases; i++)
186 assert_time_zone_offset(test_cases[i]);
187
188 }
189
Test(zone,test_time_zones)190 Test(zone, test_time_zones)
191 {
192 time_t now = time(NULL);
193
194 TimezoneTestCase test_cases[] =
195 {
196 {now, "America/Louisville"},
197 {now, "Hongkong"},
198 {now, "Europe/Budapest"},
199 {1288486800, "Europe/Budapest"},
200 {1288486860, "Europe/Budapest"},
201 {1288486740, "Europe/Budapest"},
202 {1288486800-1800, "Europe/Budapest"},
203 {1288486800+1800, "Europe/Budapest"},
204 {1288486800-3600, "Europe/Budapest"},
205 {1288486800+3600, "Europe/Budapest"},
206 {1288486800-3601, "Europe/Budapest"},
207 {1288486800+3601, "Europe/Budapest"},
208 {now, "Asia/Kuala_Lumpur"},
209 {now, "CST6CDT"},
210 {now, "US/Pacific"},
211 {now, "US/Indiana-Starke"},
212 {now, "US/Samoa"},
213 {now, "US/Arizona"},
214 {now, "US/Aleutian"},
215 {now, "US/Michigan"},
216 {now, "US/Alaska"},
217 {now, "US/Central"},
218 {now, "US/Hawaii"},
219 {now, "US/East-Indiana"},
220 {now, "US/Eastern"},
221 {now, "US/Mountain"},
222 {now, "Pacific/Noumea"},
223 {now, "Pacific/Samoa"},
224 {now, "Pacific/Apia"},
225 {now, "Pacific/Auckland"},
226 {now, "Pacific/Fakaofo"},
227 {now, "Pacific/Saipan"},
228 {now, "Pacific/Easter"},
229 {now, "Pacific/Norfolk"},
230 {now, "Pacific/Kosrae"},
231 {now, "Pacific/Tarawa"},
232 {now, "Pacific/Tahiti"},
233 {now, "Pacific/Pago_Pago"},
234 {now, "Pacific/Majuro"},
235 {now, "Pacific/Guam"},
236 {now, "Pacific/Ponape"},
237 {now, "Pacific/Tongatapu"},
238 {now, "Pacific/Funafuti"},
239 {now, "Pacific/Wallis"},
240 {now, "Pacific/Efate"},
241 {now, "Pacific/Marquesas"},
242 {now, "Pacific/Enderbury"},
243 {now, "Pacific/Pitcairn"},
244 {now, "Pacific/Yap"},
245 {now, "Pacific/Wake"},
246 {now, "Pacific/Johnston"},
247 {now, "Pacific/Kwajalein"},
248 {now, "Pacific/Chatham"},
249 {now, "Pacific/Gambier"},
250 {now, "Pacific/Galapagos"},
251 {now, "Pacific/Kiritimati"},
252 {now, "Pacific/Honolulu"},
253 {now, "Pacific/Truk"},
254 {now, "Pacific/Midway"},
255 {now, "Pacific/Fiji"},
256 {now, "Pacific/Rarotonga"},
257 {now, "Pacific/Guadalcanal"},
258 {now, "Pacific/Nauru"},
259 {now, "Pacific/Palau"},
260 {now, "Pacific/Port_Moresby"},
261 {now, "Pacific/Niue"},
262 {now, "GMT"},
263 {now, "Hongkong"},
264 {now, "ROK"},
265 {now, "Navajo"},
266 {now, "ROC"},
267 {now, "WET"},
268 {now, "posixrules"},
269 {now, "CET"},
270 {now, "MET"},
271 {now, "MST"},
272 {now, "Turkey"},
273 {now, "Zulu"},
274 {now, "GMT+0"},
275 {now, "Canada/Saskatchewan"},
276 {now, "Canada/Pacific"},
277 {now, "Canada/Yukon"},
278 {now, "Canada/East-Saskatchewan"},
279 {now, "Canada/Newfoundland"},
280 {now, "Canada/Central"},
281 {now, "Canada/Eastern"},
282 {now, "Canada/Atlantic"},
283 {now, "Canada/Mountain"},
284 {now, "Singapore"},
285 {now, "UCT"},
286 {now, "Poland"},
287 {now, "Chile/Continental"},
288 {now, "Chile/EasterIsland"},
289 {now, "Portugal"},
290 {now, "Egypt"},
291 {now, "Japan"},
292 {now, "Iran"},
293 {now, "EET"},
294 {now, "Europe/Oslo"},
295 {now, "Europe/Bratislava"},
296 {now, "Europe/Gibraltar"},
297 {now, "Europe/Skopje"},
298 {now, "Europe/Simferopol"},
299 {now, "Europe/Zurich"},
300 {now, "Europe/Vienna"},
301 {now, "Europe/Paris"},
302 {now, "Europe/Jersey"},
303 {now, "Europe/Tallinn"},
304 {now, "Europe/Madrid"},
305 {now, "Europe/Volgograd"},
306 {now, "Europe/Zaporozhye"},
307 {now, "Europe/Mariehamn"},
308 {now, "Europe/Vaduz"},
309 {now, "Europe/Moscow"},
310 {now, "Europe/Stockholm"},
311 {now, "Europe/Minsk"},
312 {now, "Europe/Andorra"},
313 {now, "Europe/Istanbul"},
314 {now, "Europe/Tiraspol"},
315 {now, "Europe/Podgorica"},
316 {now, "Europe/Bucharest"},
317 {now, "Europe/Ljubljana"},
318 {now, "Europe/Brussels"},
319 {now, "Europe/Amsterdam"},
320 {now, "Europe/Riga"},
321 {now, "Europe/Tirane"},
322 {now, "Europe/Berlin"},
323 {now, "Europe/Guernsey"},
324 {now, "Europe/Warsaw"},
325 {now, "Europe/Vatican"},
326 {now, "Europe/Malta"},
327 {now, "Europe/Nicosia"},
328 {now, "Europe/Budapest"},
329 {now, "Europe/Kaliningrad"},
330 {now, "Europe/Sarajevo"},
331 {now, "Europe/Isle_of_Man"},
332 {now, "Europe/Rome"},
333 {now, "Europe/London"},
334 {now, "Europe/Vilnius"},
335 {now, "Europe/Samara"},
336 {now, "Europe/Belfast"},
337 {now, "Europe/Athens"},
338 {now, "Europe/Copenhagen"},
339 {now, "Europe/Belgrade"},
340 {now, "Europe/Sofia"},
341 {now, "Europe/San_Marino"},
342 {now, "Europe/Helsinki"},
343 {now, "Europe/Uzhgorod"},
344 {now, "Europe/Monaco"},
345 {now, "Europe/Prague"},
346 {now, "Europe/Zagreb"},
347 {now, "Europe/Lisbon"},
348 {now, "Europe/Chisinau"},
349 {now, "Europe/Dublin"},
350 {now, "Europe/Luxembourg"},
351 {now, "Europe/Kiev"},
352 {now, "Jamaica"},
353 {now, "Indian/Chagos"},
354 {now, "Indian/Comoro"},
355 {now, "Indian/Mauritius"},
356 {now, "Indian/Mayotte"},
357 {now, "Indian/Kerguelen"},
358 {now, "Indian/Maldives"},
359 {now, "Indian/Antananarivo"},
360 {now, "Indian/Mahe"},
361 {now, "Indian/Cocos"},
362 {now, "Indian/Christmas"},
363 {now, "Indian/Reunion"},
364 {now, "Africa/Accra"},
365 {now, "Africa/Lubumbashi"},
366 {now, "Africa/Bangui"},
367 {now, "Africa/Asmara"},
368 {now, "Africa/Freetown"},
369 {now, "Africa/Mbabane"},
370 {now, "Africa/Djibouti"},
371 {now, "Africa/Ndjamena"},
372 {now, "Africa/Porto-Novo"},
373 {now, "Africa/Nouakchott"},
374 {now, "Africa/Brazzaville"},
375 {now, "Africa/Tunis"},
376 {now, "Africa/Dar_es_Salaam"},
377 {now, "Africa/Lusaka"},
378 {now, "Africa/Banjul"},
379 {now, "Africa/Sao_Tome"},
380 {now, "Africa/Monrovia"},
381 {now, "Africa/Lagos"},
382 {now, "Africa/Conakry"},
383 {now, "Africa/Tripoli"},
384 {now, "Africa/Algiers"},
385 {now, "Africa/Casablanca"},
386 {now, "Africa/Lome"},
387 {now, "Africa/Bamako"},
388 {now, "Africa/Nairobi"},
389 {now, "Africa/Douala"},
390 {now, "Africa/Addis_Ababa"},
391 {now, "Africa/El_Aaiun"},
392 {now, "Africa/Ceuta"},
393 {now, "Africa/Harare"},
394 {now, "Africa/Libreville"},
395 {now, "Africa/Johannesburg"},
396 {now, "Africa/Timbuktu"},
397 {now, "Africa/Niamey"},
398 {now, "Africa/Windhoek"},
399 {now, "Africa/Bissau"},
400 {now, "Africa/Maputo"},
401 {now, "Africa/Kigali"},
402 {now, "Africa/Dakar"},
403 {now, "Africa/Ouagadougou"},
404 {now, "Africa/Gaborone"},
405 {now, "Africa/Khartoum"},
406 {now, "Africa/Bujumbura"},
407 {now, "Africa/Luanda"},
408 {now, "Africa/Malabo"},
409 {now, "Africa/Asmera"},
410 {now, "Africa/Maseru"},
411 {now, "Africa/Abidjan"},
412 {now, "Africa/Kinshasa"},
413 {now, "Africa/Blantyre"},
414 {now, "Africa/Cairo"},
415 {now, "Africa/Kampala"},
416 {now, "Africa/Mogadishu"},
417 {now, "Universal"},
418 {now, "EST"},
419 {now, "Greenwich"},
420 {now, "Eire"},
421 {now, "Asia/Qatar"},
422 {now, "Asia/Makassar"},
423 {now, "Asia/Colombo"},
424 {now, "Asia/Chungking"},
425 {now, "Asia/Macau"},
426 {now, "Asia/Choibalsan"},
427 {now, "Asia/Rangoon"},
428 {now, "Asia/Harbin"},
429 {now, "Asia/Yerevan"},
430 {now, "Asia/Brunei"},
431 {now, "Asia/Omsk"},
432 {now, "Asia/Chongqing"},
433 {now, "Asia/Tbilisi"},
434 {now, "Asia/Tehran"},
435 {now, "Asia/Manila"},
436 {now, "Asia/Yakutsk"},
437 {now, "Asia/Qyzylorda"},
438 {now, "Asia/Dhaka"},
439 {now, "Asia/Singapore"},
440 {now, "Asia/Jakarta"},
441 {now, "Asia/Novosibirsk"},
442 {now, "Asia/Saigon"},
443 {now, "Asia/Krasnoyarsk"},
444 {now, "Asia/Kabul"},
445 {now, "Asia/Bahrain"},
446 {now, "Asia/Urumqi"},
447 {now, "Asia/Thimbu"},
448 {now, "Asia/Ulan_Bator"},
449 {now, "Asia/Taipei"},
450 {now, "Asia/Tashkent"},
451 {now, "Asia/Dacca"},
452 {now, "Asia/Aqtau"},
453 {now, "Asia/Seoul"},
454 {now, "Asia/Istanbul"},
455 {now, "Asia/Tel_Aviv"},
456 {now, "Asia/Almaty"},
457 {now, "Asia/Phnom_Penh"},
458 {now, "Asia/Baku"},
459 {now, "Asia/Anadyr"},
460 {now, "Asia/Aqtobe"},
461 {now, "Asia/Kuwait"},
462 {now, "Asia/Irkutsk"},
463 {now, "Asia/Ulaanbaatar"},
464 {now, "Asia/Tokyo"},
465 {now, "Asia/Gaza"},
466 {now, "Asia/Yekaterinburg"},
467 {now, "Asia/Nicosia"},
468 {now, "Asia/Jayapura"},
469 {now, "Asia/Shanghai"},
470 {now, "Asia/Pyongyang"},
471 {now, "Asia/Macao"},
472 {now, "Asia/Dushanbe"},
473 {now, "Asia/Kuching"},
474 {now, "Asia/Vientiane"},
475 {now, "Asia/Riyadh"},
476 {now, "Asia/Dili"},
477 {now, "Asia/Samarkand"},
478 {now, "Asia/Ashkhabad"},
479 {now, "Asia/Calcutta"},
480 {now, "Asia/Hong_Kong"},
481 {now, "Asia/Sakhalin"},
482 {now, "Asia/Beirut"},
483 {now, "Asia/Damascus"},
484 {now, "Asia/Katmandu"},
485 {now, "Asia/Jerusalem"},
486 {now, "Asia/Vladivostok"},
487 {now, "Asia/Kamchatka"},
488 {now, "Asia/Dubai"},
489 {now, "Asia/Kashgar"},
490 {now, "Asia/Ashgabat"},
491 {now, "Asia/Amman"},
492 {now, "Asia/Karachi"},
493 {now, "Asia/Bangkok"},
494 {now, "Asia/Oral"},
495 {now, "Asia/Thimphu"},
496 {now, "Asia/Bishkek"},
497 {now, "Asia/Baghdad"},
498 {now, "Asia/Kuala_Lumpur"},
499 {now, "Asia/Pontianak"},
500 {now, "Asia/Ujung_Pandang"},
501 {now, "Asia/Muscat"},
502 {now, "Asia/Aden"},
503 {now, "Asia/Hovd"},
504 {now, "Asia/Magadan"},
505 {now, "EST5EDT"},
506 {now, "PST8PDT"},
507 {now, "Atlantic/Bermuda"},
508 {now, "Atlantic/St_Helena"},
509 {now, "Atlantic/Cape_Verde"},
510 {now, "Atlantic/Stanley"},
511 {now, "Atlantic/Azores"},
512 {now, "Atlantic/Jan_Mayen"},
513 {now, "Atlantic/Reykjavik"},
514 {now, "Atlantic/Madeira"},
515 {now, "Atlantic/Canary"},
516 {now, "Atlantic/Faeroe"},
517 {now, "Atlantic/Faroe"},
518 {now, "Atlantic/South_Georgia"},
519 {now, "Kwajalein"},
520 {now, "UTC"},
521 {now, "GMT-0"},
522 {now, "MST7MDT"},
523 {now, "GB-Eire"},
524 {now, "PRC"},
525 {now, "Arctic/Longyearbyen"},
526 {now, "Cuba"},
527 {now, "Israel"},
528 {now, "Etc/GMT-3"},
529 {now, "Etc/GMT+1"},
530 {now, "Etc/GMT-5"},
531 {now, "Etc/GMT"},
532 {now, "Etc/GMT-13"},
533 {now, "Etc/GMT-1"},
534 {now, "Etc/GMT-9"},
535 {now, "Etc/Zulu"},
536 {now, "Etc/GMT+0"},
537 {now, "Etc/UCT"},
538 {now, "Etc/GMT+12"},
539 {now, "Etc/GMT+9"},
540 {now, "Etc/GMT-6"},
541 {now, "Etc/Universal"},
542 {now, "Etc/GMT-2"},
543 {now, "Etc/Greenwich"},
544 {now, "Etc/GMT+3"},
545 {now, "Etc/GMT+8"},
546 {now, "Etc/UTC"},
547 {now, "Etc/GMT-0"},
548 {now, "Etc/GMT-14"},
549 {now, "Etc/GMT+10"},
550 {now, "Etc/GMT+4"},
551 {now, "Etc/GMT+5"},
552 {now, "Etc/GMT-12"},
553 {now, "Etc/GMT-8"},
554 {now, "Etc/GMT+7"},
555 {now, "Etc/GMT-11"},
556 {now, "Etc/GMT+6"},
557 {now, "Etc/GMT0"},
558 {now, "Etc/GMT-7"},
559 {now, "Etc/GMT+11"},
560 {now, "Etc/GMT-4"},
561 {now, "Etc/GMT+2"},
562 {now, "Etc/GMT-10"},
563 {now, "HST"},
564 {now, "Iceland"},
565 {now, "Mexico/BajaNorte"},
566 {now, "Mexico/BajaSur"},
567 {now, "Mexico/General"},
568 {now, "Antarctica/Davis"},
569 {now, "Antarctica/DumontDUrville"},
570 {now, "Antarctica/Syowa"},
571 {now, "Antarctica/Palmer"},
572 {now, "Antarctica/Casey"},
573 {now, "Antarctica/Rothera"},
574 {now, "Antarctica/Mawson"},
575 {now, "Antarctica/McMurdo"},
576 {now, "Antarctica/South_Pole"},
577 {now, "Antarctica/Vostok"},
578 {now, "America/Curacao"},
579 {now, "America/St_Lucia"},
580 {now, "America/Managua"},
581 {now, "America/Lima"},
582 {now, "America/Nipigon"},
583 {now, "America/Cayenne"},
584 {now, "America/Detroit"},
585 {now, "America/Kentucky/Louisville"},
586 {now, "America/Kentucky/Monticello"},
587 {now, "America/Belem"},
588 {now, "America/Jujuy"},
589 {now, "America/Godthab"},
590 {now, "America/Guatemala"},
591 {now, "America/Atka"},
592 {now, "America/Montreal"},
593 {now, "America/Resolute"},
594 {now, "America/Thunder_Bay"},
595 {now, "America/North_Dakota/New_Salem"},
596 {now, "America/North_Dakota/Center"},
597 {now, "America/Panama"},
598 {now, "America/Los_Angeles"},
599 {now, "America/Whitehorse"},
600 {now, "America/Santiago"},
601 {now, "America/Iqaluit"},
602 {now, "America/Dawson"},
603 {now, "America/Juneau"},
604 {now, "America/Thule"},
605 {now, "America/Fortaleza"},
606 {now, "America/Montevideo"},
607 {now, "America/Tegucigalpa"},
608 {now, "America/Port-au-Prince"},
609 {now, "America/Guadeloupe"},
610 {now, "America/Coral_Harbour"},
611 {now, "America/Monterrey"},
612 {now, "America/Anguilla"},
613 {now, "America/Antigua"},
614 {now, "America/Campo_Grande"},
615 {now, "America/Buenos_Aires"},
616 {now, "America/Maceio"},
617 {now, "America/New_York"},
618 {now, "America/Puerto_Rico"},
619 {now, "America/Noronha"},
620 {now, "America/Sao_Paulo"},
621 {now, "America/Cancun"},
622 {now, "America/Aruba"},
623 {now, "America/Yellowknife"},
624 {now, "America/Knox_IN"},
625 {now, "America/Halifax"},
626 {now, "America/Grand_Turk"},
627 {now, "America/Vancouver"},
628 {now, "America/Bogota"},
629 {now, "America/Santo_Domingo"},
630 {now, "America/Tortola"},
631 {now, "America/Blanc-Sablon"},
632 {now, "America/St_Thomas"},
633 {now, "America/Scoresbysund"},
634 {now, "America/Jamaica"},
635 {now, "America/El_Salvador"},
636 {now, "America/Montserrat"},
637 {now, "America/Martinique"},
638 {now, "America/Nassau"},
639 {now, "America/Indianapolis"},
640 {now, "America/Pangnirtung"},
641 {now, "America/Port_of_Spain"},
642 {now, "America/Mexico_City"},
643 {now, "America/Denver"},
644 {now, "America/Dominica"},
645 {now, "America/Eirunepe"},
646 {now, "America/Atikokan"},
647 {now, "America/Glace_Bay"},
648 {now, "America/Rainy_River"},
649 {now, "America/St_Barthelemy"},
650 {now, "America/Miquelon"},
651 {now, "America/Indiana/Vevay"},
652 {now, "America/Indiana/Vincennes"},
653 {now, "America/Indiana/Marengo"},
654 {now, "America/Indiana/Petersburg"},
655 {now, "America/Indiana/Tell_City"},
656 {now, "America/Indiana/Knox"},
657 {now, "America/Indiana/Indianapolis"},
658 {now, "America/Indiana/Winamac"},
659 {now, "America/Menominee"},
660 {now, "America/Porto_Velho"},
661 {now, "America/Phoenix"},
662 {now, "America/Argentina/San_Juan"},
663 {now, "America/Argentina/Jujuy"},
664 {now, "America/Argentina/Ushuaia"},
665 {now, "America/Argentina/Buenos_Aires"},
666 {now, "America/Argentina/La_Rioja"},
667 {now, "America/Argentina/ComodRivadavia"},
668 {now, "America/Argentina/Tucuman"},
669 {now, "America/Argentina/Rio_Gallegos"},
670 {now, "America/Argentina/Mendoza"},
671 {now, "America/Argentina/Cordoba"},
672 {now, "America/Argentina/Catamarca"},
673 {now, "America/Dawson_Creek"},
674 {now, "America/Merida"},
675 {now, "America/Moncton"},
676 {now, "America/Goose_Bay"},
677 {now, "America/Grenada"},
678 {now, "America/Barbados"},
679 {now, "America/Tijuana"},
680 {now, "America/Regina"},
681 {now, "America/Ensenada"},
682 {now, "America/Louisville"},
683 {now, "America/Edmonton"},
684 {now, "America/Bahia"},
685 {now, "America/Nome"},
686 {now, "America/Guayaquil"},
687 {now, "America/La_Paz"},
688 {now, "America/Costa_Rica"},
689 {now, "America/Mazatlan"},
690 {now, "America/Havana"},
691 {now, "America/Marigot"},
692 {now, "America/Mendoza"},
693 {now, "America/Virgin"},
694 {now, "America/Manaus"},
695 {now, "America/Rosario"},
696 {now, "America/Boa_Vista"},
697 {now, "America/Winnipeg"},
698 {now, "America/Paramaribo"},
699 {now, "America/Danmarkshavn"},
700 {now, "America/Caracas"},
701 {now, "America/Swift_Current"},
702 {now, "America/St_Johns"},
703 {now, "America/Araguaina"},
704 {now, "America/Adak"},
705 {now, "America/Cordoba"},
706 {now, "America/Fort_Wayne"},
707 {now, "America/Catamarca"},
708 {now, "America/Recife"},
709 {now, "America/Toronto"},
710 {now, "America/Anchorage"},
711 {now, "America/St_Vincent"},
712 {now, "America/St_Kitts"},
713 {now, "America/Chihuahua"},
714 {now, "America/Cayman"},
715 {now, "America/Belize"},
716 {now, "America/Cambridge_Bay"},
717 {now, "America/Cuiaba"},
718 {now, "America/Chicago"},
719 {now, "America/Guyana"},
720 {now, "America/Inuvik"},
721 {now, "America/Asuncion"},
722 {now, "America/Porto_Acre"},
723 {now, "America/Hermosillo"},
724 {now, "America/Shiprock"},
725 {now, "America/Rio_Branco"},
726 {now, "America/Yakutat"},
727 {now, "America/Rankin_Inlet"},
728 {now, "America/Boise"},
729 {now, "Brazil/West"},
730 {now, "Brazil/Acre"},
731 {now, "Brazil/East"},
732 {now, "Brazil/DeNoronha"},
733 {now, "GMT0"},
734 {now, "Libya"},
735 {now, "W-SU"},
736 {now, "NZ-CHAT"},
737 {now, "Factory"},
738 {now, "GB"},
739 {now, "Australia/West"},
740 {now, "Australia/Canberra"},
741 {now, "Australia/Broken_Hill"},
742 {now, "Australia/Eucla"},
743 {now, "Australia/Currie"},
744 {now, "Australia/South"},
745 {now, "Australia/Lindeman"},
746 {now, "Australia/Hobart"},
747 {now, "Australia/Perth"},
748 {now, "Australia/Yancowinna"},
749 {now, "Australia/Victoria"},
750 {now, "Australia/Sydney"},
751 {now, "Australia/North"},
752 {now, "Australia/Adelaide"},
753 {now, "Australia/ACT"},
754 {now, "Australia/Melbourne"},
755 {now, "Australia/Tasmania"},
756 {now, "Australia/Darwin"},
757 {now, "Australia/Brisbane"},
758 {now, "Australia/LHI"},
759 {now, "Australia/NSW"},
760 {now, "Australia/Queensland"},
761 {now, "Australia/Lord_Howe"},
762 {now, "NZ"},
763 };
764 gint i, nr_of_cases;
765
766 nr_of_cases = sizeof(test_cases) / sizeof (test_cases[0]);
767 for (i = 0; i < nr_of_cases; i++)
768 assert_time_zone(test_cases[i]);
769 }
770
Test(zone,test_logstamp_format)771 Test(zone, test_logstamp_format)
772 {
773 UnixTime stamp;
774 GString *target = g_string_sized_new(32);
775 TimestampFormatTestCase test_cases[] =
776 {
777 /* formats */
778 {TS_FMT_BSD, 3600, 3, "Oct 14 20:47:37.123"},
779 {TS_FMT_ISO, 3600, 3, "2005-10-14T20:47:37.123+01:00"},
780 {TS_FMT_FULL, 3600, 3, "2005 Oct 14 20:47:37.123"},
781 {TS_FMT_UNIX, 3600, 3, "1129319257.123"},
782 /* time_zone offsets */
783 {TS_FMT_ISO, 5400, 3, "2005-10-14T21:17:37.123+01:30"},
784 {TS_FMT_ISO, -3600, 3, "2005-10-14T18:47:37.123-01:00"},
785 {TS_FMT_ISO, -5400, 3, "2005-10-14T18:17:37.123-01:30"},
786 };
787 TimestampFormatTestCase boundary_test_case = {TS_FMT_ISO, -1, 0, "1970-01-01T00:00:00+00:00"};
788 gint i, nr_of_cases;
789
790 stamp.ut_sec = 1129319257;
791 stamp.ut_usec = 123456;
792 stamp.ut_gmtoff = 0;
793 nr_of_cases = sizeof(test_cases) / sizeof(test_cases[0]);
794 for (i = 0; i < nr_of_cases; i++)
795 assert_timestamp_format(target, &stamp, test_cases[i]);
796
797 // boundary testing
798 stamp.ut_sec = 0;
799 stamp.ut_usec = 0;
800 assert_timestamp_format(target, &stamp, boundary_test_case);
801
802 g_string_free(target, TRUE);
803 }
804