2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSObject.h>
23 #include <NGExtensions/NSURL+misc.h>
27 @interface TestURL : NSObject
29 - (int)runWithArguments:(NSArray *)_args;
35 @implementation TestURL
37 - (void)testUrlSlashSuffix:(NSString *)_url {
40 url = [NSURL URLWithString:_url];
41 [self logWithFormat:@"Url URL: %@", url];
42 [self logWithFormat:@" Abs: %@", [url absoluteString]];
43 [self logWithFormat:@" Path: %@", [url path]];
44 [self logWithFormat:@" RelPath: %@", [url relativePath]];
46 if ([[url absoluteString] hasSuffix:@"/"]
47 != [[url path] hasSuffix:@"/"]) {
48 [self logWithFormat:@"ERROR: path suffix different from URL suffix!"];
51 [self logWithFormat:@"OK: suffix seems to match."];
54 - (void)testStringValueRelativeToURL:(NSString *)_url base:(NSString *)_base
55 expect:(NSString *)_result
60 base = [NSURL URLWithString:_base];
61 [self logWithFormat:@"Base URL: %@", base];
62 [self logWithFormat:@" Abs: %@", [base absoluteString]];
63 [self logWithFormat:@" Path: %@", [base path]];
65 url = [NSURL URLWithString:_url];
66 [self logWithFormat:@"Url URL: %@", url];
67 [self logWithFormat:@" Abs: %@", [url absoluteString]];
68 [self logWithFormat:@" Path: %@", [url path]];
70 result = [url stringValueRelativeToURL:base];
71 [self logWithFormat:@"Relative: %@", result];
73 if ([result isEqualToString:_result])
74 [self logWithFormat:@"OK matches expected result '%@'", _result];
76 [self logWithFormat:@"ERROR: does not meet expectation: '%@'", _result];
79 - (int)runWithArguments:(NSArray *)_args {
80 [self testUrlSlashSuffix:@"http://localhost:20000/dbd.woa/so/localhost/"];
82 [self testStringValueRelativeToURL:
83 @"http://localhost:20000/dbd.woa/so/localhost/Databases/OGo"
84 base:@"http://localhost:20000/dbd.woa/so/localhost/"
85 expect:@"Databases/OGo"];
91 int main(int argc, char **argv, char **env) {
92 NSAutoreleasePool *pool;
96 pool = [[NSAutoreleasePool alloc] init];
98 #if LIB_FOUNDATION_LIBRARY
99 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
102 tool = [[TestURL alloc] init];
103 rc = [tool runWithArguments:
104 [[NSProcessInfo processInfo] argumentsWithoutDefaults]];