diff --git a/ChangeLog b/ChangeLog index 79ea74324..9fbf6008b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-04-04 Richard Frith-Macdonald + + * Source/NSBundle.m: ([+initialize]) change to use 'right' path + handling so that our core paths are established correctly even if + an app has set the wrong path handling mode for the currenty platform. + * Tests\base\NSURL\basic.m: + * Tests\base\NSString\test02.m: + Fix path portability bugs in tests. + 2011-04-03 Richard Frith-Macdonald * Source/NSThread.m: fix leak spotted by Fred. diff --git a/Source/NSBundle.m b/Source/NSBundle.m index efc416c3e..ef30d98b1 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -845,9 +845,14 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) { if (self == [NSBundle class]) { - NSDictionary *env; - NSString *str; + extern const char *GSPathHandling(const char *); + const char *mode; + NSDictionary *env; + NSString *str; + /* Ensure we do 'right' path handling while initializing core paths. + */ + mode = GSPathHandling("right"); _emptyTable = RETAIN([NSDictionary dictionary]); /* Initialise manager here so it's thread-safe. @@ -935,6 +940,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) objc_close_main_module(handle); _loadingBundle = nil; #endif + GSPathHandling(mode); } } diff --git a/Tests/base/NSRunLoop/thread.m b/Tests/base/NSRunLoop/thread.m index aaece248e..97a43ee38 100644 --- a/Tests/base/NSRunLoop/thread.m +++ b/Tests/base/NSRunLoop/thread.m @@ -3,6 +3,7 @@ #import #import #import +#import #import #import #import @@ -21,12 +22,18 @@ char moreForTimer; char performed; } +- (void) notified: (NSNotification*)n; - (void) timeout: (NSTimer*)t; - (void) thread1: (id)o; @end @implementation ThreadTest +- (void) notified: (NSNotification*)n +{ + NSLog(@"Notified: %@", n); +} + - (void) timeout: (NSTimer*)t { } @@ -34,12 +41,14 @@ - (void) thread1: (id)o { NSAutoreleasePool *pool = [NSAutoreleasePool new]; + NSNotificationCenter *nc; NSRunLoop *loop; NSFileHandle *fh; NSTimer *timer; NSDate *end; NSDate *start; + nc = [NSNotificationCenter defaultCenter]; loop = [NSRunLoop currentRunLoop]; end = [loop limitDateForMode: NSDefaultRunLoopMode]; @@ -100,6 +109,8 @@ [timer invalidate]; fh = [NSFileHandle fileHandleWithStandardInput]; + [nc addObserver: self selector:@selector(notified:) + name: nil object:fh]; [fh readInBackgroundAndNotify]; end = [loop limitDateForMode: NSDefaultRunLoopMode]; if ([end isEqual: [NSDate distantFuture]] == YES) @@ -117,7 +128,7 @@ blockForInput = 'N'; else blockForInput = 'Y'; - + [nc removeObserver: self]; [pool release]; } diff --git a/Tests/base/NSString/test02.m b/Tests/base/NSString/test02.m index 041601d1e..f737ff426 100644 --- a/Tests/base/NSString/test02.m +++ b/Tests/base/NSString/test02.m @@ -247,6 +247,10 @@ int main() PASS_EQUAL([@"/home/.//././user" stringByStandardizingPath], @"/home/user", "/home/.//././user stringByStandardizingPath == /home/user"); +#if defined(GNUSTEP_BASE_LIBRARY) + GSPathHandling("unix"); +#endif + PASS_EQUAL([@"/home/../nicola" stringByStandardizingPath], @"/nicola", "/home/../nicola stringByStandardizingPath == /nicola"); @@ -283,6 +287,7 @@ int main() [fm removeFileAtPath: tmpsrc handler: nil]; [fm createSymbolicLinkAtPath: tmpsrc pathContent: tmpdst]; +#if !defined(__MINGW32__) PASS_EQUAL([tmpsrc stringByStandardizingPath], tmpsrc, "foo->bar symlink not expanded by stringByStandardizingPath") PASS_EQUAL([tmpsrc stringByResolvingSymlinksInPath], tmpdst, @@ -291,6 +296,8 @@ int main() [fm changeCurrentDirectoryPath: tmpdir]; PASS_EQUAL([@"foo" stringByResolvingSymlinksInPath], tmpdst, "foo->bar relative symlink expanded by stringByResolvingSymlinksInPath") +#endif + PASS(NO == [[@"~" stringByResolvingSymlinksInPath] isEqual: @"~"], "tilde is expanded by stringByResolvingSymlinksInPath") [fm changeCurrentDirectoryPath: cwd]; @@ -302,6 +309,11 @@ int main() "/.. stringByStandardizingPath == /"); PASS_EQUAL([@"/." stringByStandardizingPath], @"/.", "/. stringByStandardizingPath == /. (OSX special case)"); + +#if defined(GNUSTEP_BASE_LIBRARY) + GSPathHandling("gnustep"); +#endif + result = [NSArray arrayWithObjects: @"nicola",@"core",nil]; result = [@"home" stringsByAppendingPaths:result]; diff --git a/Tests/base/NSURL/basic.m b/Tests/base/NSURL/basic.m index 4a2e1afb9..5355b5cdb 100644 --- a/Tests/base/NSURL/basic.m +++ b/Tests/base/NSURL/basic.m @@ -2,6 +2,10 @@ #import "Testing.h" #import "ObjectTesting.h" +#if GNUSTEP +extern const char *GSPathHandling(const char *); +#endif + int main() { NSAutoreleasePool *arp = [NSAutoreleasePool new]; @@ -73,29 +77,38 @@ int main() PASS([str isEqual: @"http://www.w3.org/silly-file-path/"], "Abs of http://www.w3.org/silly-file-path/ is correct"); +#if defined(__MINGW32__) + url = [NSURL fileURLWithPath: @"C:\\WINDOWS"]; + str = [url path]; + PASS_EQUAL(str, @"C:\\WINDOWS", + "Path of file URL C:\\WINDOWS is C:\\WINDOWS"); + PASS_EQUAL([url description], @"file://localhost/C:%5CWINDOWS/", + "File URL C:\\WINDOWS is file://localhost/C:%%5CWINDOWS/"); + PASS_EQUAL([url resourceSpecifier], @"//localhost/C:%5CWINDOWS/", + "resourceSpecifier of C:\\WINDOWS is //localhost/C:%%5CWINDOWS/"); +#else url = [NSURL fileURLWithPath: @"/usr"]; str = [url path]; - PASS([str isEqual: @"/usr"], "Path of file URL /usr is /usr"); - PASS([[url description] isEqual: @"file://localhost/usr/"], + PASS_EQUAL(str, @"/usr", "Path of file URL /usr is /usr"); + PASS_EQUAL([url description], @"file://localhost/usr/", "File URL /usr is file://localhost/usr/"); - PASS([[url resourceSpecifier] isEqual: @"//localhost/usr/"], + PASS_EQUAL([url resourceSpecifier], @"//localhost/usr/", "resourceSpecifier of /usr is //localhost/usr/"); +#endif url = [NSURL URLWithString: @"file:///usr"]; - PASS([[url resourceSpecifier] isEqual: @"/usr"], + PASS_EQUAL([url resourceSpecifier], @"/usr", "resourceSpecifier of file:///usr is /usr"); url = [NSURL URLWithString: @"http://here.and.there/testing/one.html"]; rel = [NSURL URLWithString: @"aaa/bbb/ccc/" relativeToURL: url]; - PASS([[rel absoluteString] - isEqual: @"http://here.and.there/testing/aaa/bbb/ccc/"], + PASS_EQUAL([rel absoluteString], + @"http://here.and.there/testing/aaa/bbb/ccc/", "Simple relative URL absoluteString works"); - PASS([[rel path] - isEqual: @"/testing/aaa/bbb/ccc"], + PASS_EQUAL([rel path], @"/testing/aaa/bbb/ccc", "Simple relative URL path works"); #if GNUSTEP - PASS([[rel fullPath] - isEqual: @"/testing/aaa/bbb/ccc/"], + PASS_EQUAL([rel fullPath], @"/testing/aaa/bbb/ccc/", "Simple relative URL fullPath works"); #endif @@ -188,6 +201,10 @@ int main() //NSLog(@"with link %@, obtained URL: %@ String: %@", str, rel, [rel absoluteString]); PASS([[rel absoluteString] isEqual: @"file://localhost/System/Library/Documentation/Developer/Gui/Reference/NSApplication.html#class$NSApplication"], "Adding relative file URL with fragment works"); +#if defined(__MINGW32__) +GSPathHandling("unix"); +#endif + buf[0] = '/'; for (i = 1; i < 256; i++) { @@ -196,24 +213,24 @@ int main() str = [NSString stringWithCharacters: buf length: 256]; url = [NSURL fileURLWithPath: str]; NSLog(@"path quoting %@", [url absoluteString]); - PASS([[url absoluteString] isEqual: @"file://localhost/%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25&'()*+,-./0123456789:%3B%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%C2%80%C2%81%C2%82%C2%83%C2%84%C2%85%C2%86%C2%87%C2%88%C2%89%C2%8A%C2%8B%C2%8C%C2%8D%C2%8E%C2%8F%C2%90%C2%91%C2%92%C2%93%C2%94%C2%95%C2%96%C2%97%C2%98%C2%99%C2%9A%C2%9B%C2%9C%C2%9D%C2%9E%C2%9F%C2%A0%C2%A1%C2%A2%C2%A3%C2%A4%C2%A5%C2%A6%C2%A7%C2%A8%C2%A9%C2%AA%C2%AB%C2%AC%C2%AD%C2%AE%C2%AF%C2%B0%C2%B1%C2%B2%C2%B3%C2%B4%C2%B5%C2%B6%C2%B7%C2%B8%C2%B9%C2%BA%C2%BB%C2%BC%C2%BD%C2%BE%C2%BF%C3%80%C3%81%C3%82%C3%83%C3%84%C3%85%C3%86%C3%87%C3%88%C3%89%C3%8A%C3%8B%C3%8C%C3%8D%C3%8E%C3%8F%C3%90%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%9B%C3%9C%C3%9D%C3%9E%C3%9F%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%A8%C3%A9%C3%AA%C3%AB%C3%AC%C3%AD%C3%AE%C3%AF%C3%B0%C3%B1%C3%B2%C3%B3%C3%B4%C3%B5%C3%B6%C3%B7%C3%B8%C3%B9%C3%BA%C3%BB%C3%BC%C3%BD%C3%BE%C3%BF"], "path quoting"); + PASS_EQUAL([url absoluteString], + @"file://localhost/%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25&'()*+,-./0123456789:%3B%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%C2%80%C2%81%C2%82%C2%83%C2%84%C2%85%C2%86%C2%87%C2%88%C2%89%C2%8A%C2%8B%C2%8C%C2%8D%C2%8E%C2%8F%C2%90%C2%91%C2%92%C2%93%C2%94%C2%95%C2%96%C2%97%C2%98%C2%99%C2%9A%C2%9B%C2%9C%C2%9D%C2%9E%C2%9F%C2%A0%C2%A1%C2%A2%C2%A3%C2%A4%C2%A5%C2%A6%C2%A7%C2%A8%C2%A9%C2%AA%C2%AB%C2%AC%C2%AD%C2%AE%C2%AF%C2%B0%C2%B1%C2%B2%C2%B3%C2%B4%C2%B5%C2%B6%C2%B7%C2%B8%C2%B9%C2%BA%C2%BB%C2%BC%C2%BD%C2%BE%C2%BF%C3%80%C3%81%C3%82%C3%83%C3%84%C3%85%C3%86%C3%87%C3%88%C3%89%C3%8A%C3%8B%C3%8C%C3%8D%C3%8E%C3%8F%C3%90%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%9B%C3%9C%C3%9D%C3%9E%C3%9F%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%A8%C3%A9%C3%AA%C3%AB%C3%AC%C3%AD%C3%AE%C3%AF%C3%B0%C3%B1%C3%B2%C3%B3%C3%B4%C3%B5%C3%B6%C3%B7%C3%B8%C3%B9%C3%BA%C3%BB%C3%BC%C3%BD%C3%BE%C3%BF", "path quoting"); /* Test +fileURLWithPath: for messy/complex path */ url = [NSURL fileURLWithPath: @"/this#is a Path with % + = & < > ?"]; - //NSLog(@"complex -path %@", [url path]); - PASS([[url path] isEqual: @"/this#is a Path with % + = & < > ?"], + PASS_EQUAL([url path], @"/this#is a Path with % + = & < > ?", "complex -path"); - //NSLog(@"complext -fragment %@", [url fragment]); - PASS([url fragment] == nil, "complex -fragment"); - //NSLog(@"complex -parameter %@", [url parameterString]); - PASS([url parameterString] == nil, "complex -parameterString"); - //NSLog(@"complex -query %@", [url query]); - PASS([url query] == nil, "complex -query"); - //NSLog(@"complex -absoluteString %@", [url absoluteString]); - PASS([[url absoluteString] isEqual: @"file://localhost/this%23is%20a%20Path%20with%20%25%20+%20=%20&%20%3C%20%3E%20%3F"], "complex -absoluteString"); - PASS([[url relativeString] isEqual: @"file://localhost/this%23is%20a%20Path%20with%20%25%20+%20=%20&%20%3C%20%3E%20%3F"], "complex -relativeString"); - PASS([[url description] isEqual: @"file://localhost/this%23is%20a%20Path%20with%20%25%20+%20=%20&%20%3C%20%3E%20%3F"], "complex -description"); + PASS_EQUAL([url fragment], nil, "complex -fragment"); + PASS_EQUAL([url parameterString], nil, "complex -parameterString"); + PASS_EQUAL([url query], nil, "complex -query"); + PASS_EQUAL([url absoluteString], @"file://localhost/this%23is%20a%20Path%20with%20%25%20+%20=%20&%20%3C%20%3E%20%3F", "complex -absoluteString"); + PASS_EQUAL([url relativeString], @"file://localhost/this%23is%20a%20Path%20with%20%25%20+%20=%20&%20%3C%20%3E%20%3F", "complex -relativeString"); + PASS_EQUAL([url description], @"file://localhost/this%23is%20a%20Path%20with%20%25%20+%20=%20&%20%3C%20%3E%20%3F", "complex -description"); + +#if defined(__MINGW32__) +GSPathHandling("right"); +#endif /* Test +URLWithString: for file URL with a messy/complex path */ @@ -242,9 +259,11 @@ int main() str = [str stringByAppendingPathComponent: @"basic.m"]; url = [NSURL fileURLWithPath: str]; PASS([url resourceDataUsingCache: NO] != nil, "can load file URL"); - str = [NSString stringWithFormat: @"file://%@#anchor", str]; + str = [str stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; + str = [NSString stringWithFormat: @"file://localhost/%@#anchor", str]; url = [NSURL URLWithString: str]; - PASS([url resourceDataUsingCache: NO] != nil, "can load file URL with achor"); + PASS([url resourceDataUsingCache: NO] != nil, + "can load file URL with anchor"); [arp release]; arp = nil;