From 7bb34b71024894a415ce31d82232943ffa99eb15 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 31 Dec 2024 12:17:52 +0000 Subject: [PATCH 1/3] Prodyce more informative logging --- Tests/base/NSCalendarDate/test02.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/base/NSCalendarDate/test02.m b/Tests/base/NSCalendarDate/test02.m index b9cdd4a5dd..689fc4cac9 100644 --- a/Tests/base/NSCalendarDate/test02.m +++ b/Tests/base/NSCalendarDate/test02.m @@ -168,9 +168,9 @@ int main() locale: myLocale] isEqualToString: @"1974"], "%%Y format works in description"); - PASS([[myBirthday descriptionWithCalendarFormat: @"%Z" - locale: myLocale] isEqualToString: @"MET"], - "%%Z format works in description"); + PASS_EQUAL([myBirthday + descriptionWithCalendarFormat: @"%Z" locale: myLocale], + @"MET", "%%Z format works in description") PASS([[myBirthday descriptionWithCalendarFormat: @"%z" locale: myLocale] isEqualToString: @"+0100"], @@ -192,9 +192,9 @@ int main() locale: myLocale] isEqualToString: @"13%00%00"], "%%H%%%%%%M%%%%%%S format works in description"); - PASS([[myBirthday descriptionWithCalendarFormat: @"%H:%M (%Z)" - locale: myLocale] isEqualToString: @"13:00 (MET)"], - "%%H%%M format works in description"); + PASS_EQUAL([myBirthday + descriptionWithCalendarFormat: @"%H:%M (%Z)" locale: myLocale], + @"13:00 (MET)", "%%H%%M format works in description") PASS([[myBirthday descriptionWithCalendarFormat: @"%R" locale: myLocale] isEqualToString: @"13:00"], From 7072a38eb30a31c322dd5fbb57fcc7d9b3d7028c Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 31 Dec 2024 13:13:04 +0000 Subject: [PATCH 2/3] Add tests for MET time zone setup --- Tests/base/NSCalendarDate/test02.m | 12 +++++++++--- Tests/base/NSTimeZone/create.m | 17 ++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Tests/base/NSCalendarDate/test02.m b/Tests/base/NSCalendarDate/test02.m index 689fc4cac9..20297a61df 100644 --- a/Tests/base/NSCalendarDate/test02.m +++ b/Tests/base/NSCalendarDate/test02.m @@ -13,7 +13,8 @@ int main() NSMutableArray *tmpArray; NSMutableDictionary *myLocale; NSCalendarDate *myBirthday; - NSCalendarDate *anotherDay; + NSCalendarDate *anotherDay; + NSTimeZone *tz; myLocale = westernLocale(); @@ -72,13 +73,17 @@ int main() [tmpArray addObject: @"PM"]; [myLocale setObject: tmpArray forKey: NSAMPMDesignation]; + tz = [NSTimeZone timeZoneWithName: @"MET"]; + PASS_EQUAL([tz name], @"MET", "got time zone for dates") + myBirthday = [NSCalendarDate dateWithYear: 1974 month: 11 day: 20 hour: 13 minute: 0 second: 0 - timeZone: [NSTimeZone timeZoneWithName: @"MET"]]; + timeZone: tz]; + PASS_EQUAL([myBirthday timeZone], tz, "myBirthday has expected time zone") anotherDay = [NSCalendarDate dateWithYear: 1974 month: 1 @@ -86,7 +91,8 @@ int main() hour: 3 minute: 0 second: 0 - timeZone: [NSTimeZone timeZoneWithName: @"MET"]]; + timeZone: tz]; + PASS_EQUAL([anotherDay timeZone], tz, "anotherDay has expected time zone") PASS([[myBirthday descriptionWithCalendarFormat: @"%%" locale: myLocale] isEqualToString: @"%"], diff --git a/Tests/base/NSTimeZone/create.m b/Tests/base/NSTimeZone/create.m index 4cad61ed0e..8a2028177e 100644 --- a/Tests/base/NSTimeZone/create.m +++ b/Tests/base/NSTimeZone/create.m @@ -9,31 +9,34 @@ int main() current = [NSTimeZone defaultTimeZone]; PASS(current != nil && [current isKindOfClass: [NSTimeZone class]], - "+defaultTimeZone works"); + "+defaultTimeZone works") current = [NSTimeZone localTimeZone]; PASS(current != nil && [current isKindOfClass: [NSTimeZone class]], - "+localTimeZone works"); + "+localTimeZone works") current = [NSTimeZone systemTimeZone]; PASS(current != nil && [current isKindOfClass: [NSTimeZone class]], - "+systemTimeZone works"); + "+systemTimeZone works") current = [NSTimeZone timeZoneForSecondsFromGMT: 900]; PASS(current != nil && [current isKindOfClass: [NSTimeZone class]], - "+timeZoneForSecondsFromGMT works"); + "+timeZoneForSecondsFromGMT: works") current = [NSTimeZone timeZoneForSecondsFromGMT: 90000]; PASS(current == nil, - "+timeZoneForSecondsFromGMT fails for bad offset"); + "+timeZoneForSecondsFromGMT: fails for bad offset") current = [NSTimeZone timeZoneWithAbbreviation: @"MST"]; PASS(current != nil && [current isKindOfClass: [NSTimeZone class]], - "+timeZoneWithAbbreviation works"); + "+timeZoneWithAbbreviation: works") current = [NSTimeZone timeZoneWithName: @"GB"]; PASS(current != nil && [current isKindOfClass: [NSTimeZone class]], - "+timeZoneWithName works"); + "+timeZoneWithName: works") + + current = [NSTimeZone timeZoneWithName: @"MET"]; + PASS_EQUAL([current name], @"MET", "+timeZoneWithName: preserved name") [arp release]; arp = nil; return 0; From 46d19b5dd5b35484aa87545b185cd998ec520ef7 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 31 Dec 2024 14:31:43 +0000 Subject: [PATCH 3/3] Updates for changes to IANA time zone data. --- ChangeLog | 14 ++++++++++++- Source/NSTimeZone.m | 24 ++++++++++++++-------- Tests/base/NSCalendarDate/TestInfo | 2 ++ Tests/base/NSCalendarDate/test02.m | 32 +++++++++++++++--------------- Tests/base/NSTimeZone/TestInfo | 3 +++ 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 362cbe4dfd..f1f245883a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,20 @@ +2024-12-31 Richard Frith-Macdonald + + * Source/NSTimeZone.m: Add GNUSTEP_BUILTIN_TZ environment variable to + force the use of the IANA standard based time zone files we provide + in the distribution rather than the system supplied time zone data. + This allows us to standardise test behavior across different systems. + * Tests/base/NSCalendarDate/TestInfo: set GNUSTEP_BUILTIN_TZ=1 + * Tests/base/NSCalendarDate/test02.m: Change from using the MET zone + to using CET for tests since the IANA data has changed to make MET + behave aas CET. + * Tests/base/NSTimeZone/TestInfo: set GNUSTEP_BUILTIN_TZ=1 + 2024-11-29 Richard Frith-Macdonald * Source/NSURLProtocol.m: fix leaks due to retain loops. * Source/Additions/NSObject+GNUstepBase.m: fix issues in new - -trackOownership mechanism to log tracked instances at exist and to + -trackOwnership mechanism to log tracked instances at exist and to handle cases where we track instances of a class and instances of its subclasses. diff --git a/Source/NSTimeZone.m b/Source/NSTimeZone.m index 6eea6fd010..5ac959bcfa 100644 --- a/Source/NSTimeZone.m +++ b/Source/NSTimeZone.m @@ -33,6 +33,8 @@ Time zone names can be different from system to system, but usually the user has already set up his timezone independant of GNUstep, so we should respect that information. + For testing purposes, the GNUSTEP_BUILTIN_TZ environment variable can + be set to force the system independent data to be used. We do not use a dictionary for storing time zones, since such a dictionary would be VERY large (~500K). And we would have to use a @@ -2500,17 +2502,23 @@ + (NSString*) _getTimeZoneFile: (NSString *)name } GS_MUTEX_UNLOCK(zone_mutex); } - /* Use the system zone info if possible, otherwise, use our installed - info. */ - if (tzdir && [[NSFileManager defaultManager] fileExistsAtPath: - [tzdir stringByAppendingPathComponent: name] isDirectory: &isDir] == YES - && isDir == NO) + + if (NO == [[[[NSProcessInfo processInfo] environment] + objectForKey: @"GNUSTEP_BUILTIN_TZ"] boolValue]) { - dir = tzdir; + /* Use the system zone info if possible, otherwise, use our installed + * info. + */ + if (tzdir && [[NSFileManager defaultManager] fileExistsAtPath: + [tzdir stringByAppendingPathComponent: name] isDirectory: &isDir] + && isDir == NO) + { + dir = tzdir; + } } if (dir == nil) { - dir = _time_zone_path (ZONES_DIR, nil); + dir = _time_zone_path(ZONES_DIR, nil); } return [dir stringByAppendingPathComponent: name]; } @@ -3065,7 +3073,7 @@ - (id) initWithName: (NSString*)name data: (NSData*)data NS_DURING { - size_t nread; + size_t nread; union input_buffer *up; lsp = malloc(sizeof(*lsp)); diff --git a/Tests/base/NSCalendarDate/TestInfo b/Tests/base/NSCalendarDate/TestInfo index e69de29bb2..4e74c9feac 100644 --- a/Tests/base/NSCalendarDate/TestInfo +++ b/Tests/base/NSCalendarDate/TestInfo @@ -0,0 +1,2 @@ +# On unix systems force testing using our inbuilt time zone data. +export GNUSTEP_BUILTIN_TZ=1 diff --git a/Tests/base/NSCalendarDate/test02.m b/Tests/base/NSCalendarDate/test02.m index 20297a61df..40c7e03b40 100644 --- a/Tests/base/NSCalendarDate/test02.m +++ b/Tests/base/NSCalendarDate/test02.m @@ -73,25 +73,25 @@ int main() [tmpArray addObject: @"PM"]; [myLocale setObject: tmpArray forKey: NSAMPMDesignation]; - tz = [NSTimeZone timeZoneWithName: @"MET"]; - PASS_EQUAL([tz name], @"MET", "got time zone for dates") + tz = [NSTimeZone timeZoneWithName: @"CET"]; + PASS_EQUAL([tz name], @"CET", "got time zone for dates") myBirthday = [NSCalendarDate dateWithYear: 1974 - month: 11 - day: 20 - hour: 13 - minute: 0 - second: 0 - timeZone: tz]; + month: 11 + day: 20 + hour: 13 + minute: 0 + second: 0 + timeZone: tz]; PASS_EQUAL([myBirthday timeZone], tz, "myBirthday has expected time zone") anotherDay = [NSCalendarDate dateWithYear: 1974 - month: 1 - day: 2 - hour: 3 - minute: 0 - second: 0 - timeZone: tz]; + month: 1 + day: 2 + hour: 3 + minute: 0 + second: 0 + timeZone: tz]; PASS_EQUAL([anotherDay timeZone], tz, "anotherDay has expected time zone") PASS([[myBirthday descriptionWithCalendarFormat: @"%%" @@ -176,7 +176,7 @@ int main() PASS_EQUAL([myBirthday descriptionWithCalendarFormat: @"%Z" locale: myLocale], - @"MET", "%%Z format works in description") + @"CET", "%%Z format works in description") PASS([[myBirthday descriptionWithCalendarFormat: @"%z" locale: myLocale] isEqualToString: @"+0100"], @@ -200,7 +200,7 @@ int main() PASS_EQUAL([myBirthday descriptionWithCalendarFormat: @"%H:%M (%Z)" locale: myLocale], - @"13:00 (MET)", "%%H%%M format works in description") + @"13:00 (CET)", "%%H%%M format works in description") PASS([[myBirthday descriptionWithCalendarFormat: @"%R" locale: myLocale] isEqualToString: @"13:00"], diff --git a/Tests/base/NSTimeZone/TestInfo b/Tests/base/NSTimeZone/TestInfo index e69de29bb2..0b9b8df484 100644 --- a/Tests/base/NSTimeZone/TestInfo +++ b/Tests/base/NSTimeZone/TestInfo @@ -0,0 +1,3 @@ +# On unix systems force testing using our inbuilt time zone data. +export GNUSTEP_BUILTIN_TZ=1 +