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