]> err.no Git - sope/blob - sope-core/samples/testurl.m
bumbed versions to 4.5
[sope] / sope-core / samples / testurl.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSObject.h>
23 #include <NGExtensions/NSURL+misc.h>
24
25 @class NSArray;
26
27 @interface TestURL : NSObject
28
29 - (int)runWithArguments:(NSArray *)_args;
30
31 @end
32
33 #include "common.h"
34
35 @implementation TestURL
36
37 - (void)testUrlSlashSuffix:(NSString *)_url {
38   NSURL *url;
39   
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]];
45
46   if ([[url absoluteString] hasSuffix:@"/"]
47       != [[url path] hasSuffix:@"/"]) {
48     [self logWithFormat:@"ERROR: path suffix different from URL suffix!"];
49   }
50   else
51     [self logWithFormat:@"OK: suffix seems to match."];
52 }
53
54 - (void)testStringValueRelativeToURL:(NSString *)_url base:(NSString *)_base 
55   expect:(NSString *)_result
56 {
57   NSURL    *url, *base;
58   NSString *result;
59
60   base = [NSURL URLWithString:_base];
61   [self logWithFormat:@"Base URL:  %@", base];
62   [self logWithFormat:@"     Abs:  %@", [base absoluteString]];
63   [self logWithFormat:@"     Path: %@", [base path]];
64   
65   url  = [NSURL URLWithString:_url];
66   [self logWithFormat:@"Url  URL:  %@", url];
67   [self logWithFormat:@"     Abs:  %@", [url absoluteString]];
68   [self logWithFormat:@"     Path: %@", [url path]];
69   
70   result = [url stringValueRelativeToURL:base];
71   [self logWithFormat:@"Relative: %@", result];
72
73   if ([result isEqualToString:_result])
74     [self logWithFormat:@"OK matches expected result '%@'", _result];
75   else
76     [self logWithFormat:@"ERROR: does not meet expectation: '%@'", _result];
77 }
78
79 - (int)runWithArguments:(NSArray *)_args {
80   [self testUrlSlashSuffix:@"http://localhost:20000/dbd.woa/so/localhost/"];
81   
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"];
86   return 0;
87 }
88
89 @end /* TestURL */
90
91 int main(int argc, char **argv, char **env) {
92   NSAutoreleasePool *pool;
93   TestURL *tool;
94   int rc;
95   
96   pool = [[NSAutoreleasePool alloc] init];
97
98 #if LIB_FOUNDATION_LIBRARY
99   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
100 #endif
101   
102   tool = [[TestURL alloc] init];
103   rc = [tool runWithArguments:
104                [[NSProcessInfo processInfo] argumentsWithoutDefaults]];
105   [tool release];
106   [pool release];
107   return 0;
108 }