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
23 #import <Foundation/NSObject.h>
24 #include <NGExtensions/NSURL+misc.h>
28 @interface TestURL : NSObject
30 - (int)runWithArguments:(NSArray *)_args;
36 @implementation TestURL
38 - (void)testUrlSlashSuffix:(NSString *)_url {
41 url = [NSURL URLWithString:_url];
42 [self logWithFormat:@"Url URL: %@", url];
43 [self logWithFormat:@" Abs: %@", [url absoluteString]];
44 [self logWithFormat:@" Path: %@", [url path]];
45 [self logWithFormat:@" RelPath: %@", [url relativePath]];
47 if ([[url absoluteString] hasSuffix:@"/"]
48 != [[url path] hasSuffix:@"/"]) {
49 [self logWithFormat:@"ERROR: path suffix different from URL suffix!"];
52 [self logWithFormat:@"OK: suffix seems to match."];
55 - (void)testStringValueRelativeToURL:(NSString *)_url base:(NSString *)_base
56 expect:(NSString *)_result
61 base = [NSURL URLWithString:_base];
62 [self logWithFormat:@"Base URL: %@", base];
63 [self logWithFormat:@" Abs: %@", [base absoluteString]];
64 [self logWithFormat:@" Path: %@", [base path]];
66 url = [NSURL URLWithString:_url];
67 [self logWithFormat:@"Url URL: %@", url];
68 [self logWithFormat:@" Abs: %@", [url absoluteString]];
69 [self logWithFormat:@" Path: %@", [url path]];
71 result = [url stringValueRelativeToURL:base];
72 [self logWithFormat:@"Relative: %@", result];
74 if ([result isEqualToString:_result])
75 [self logWithFormat:@"OK matches expected result '%@'", _result];
77 [self logWithFormat:@"ERROR: does not meet expectation: '%@'", _result];
80 - (int)runWithArguments:(NSArray *)_args {
81 [self testUrlSlashSuffix:@"http://localhost:20000/dbd.woa/so/localhost/"];
83 [self testStringValueRelativeToURL:
84 @"http://localhost:20000/dbd.woa/so/localhost/Databases/OGo"
85 base:@"http://localhost:20000/dbd.woa/so/localhost/"
86 expect:@"Databases/OGo"];
92 int main(int argc, char **argv, char **env) {
93 NSAutoreleasePool *pool;
97 pool = [[NSAutoreleasePool alloc] init];
99 #if LIB_FOUNDATION_LIBRARY
100 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
103 tool = [[TestURL alloc] init];
104 rc = [tool runWithArguments:
105 [[NSProcessInfo processInfo] argumentsWithoutDefaults]];