root / json-framework-3.2.0 / Tests / ProxyTest.m @ 3ebe9884
History | View | Annotate | Download (3.1 kB)
1 |
/* |
---|---|
2 |
Copyright (C) 2009-2010 Stig Brautaset. All rights reserved. |
3 |
|
4 |
Redistribution and use in source and binary forms, with or without |
5 |
modification, are permitted provided that the following conditions are met: |
6 |
|
7 |
* Redistributions of source code must retain the above copyright notice, this |
8 |
list of conditions and the following disclaimer. |
9 |
|
10 |
* Redistributions in binary form must reproduce the above copyright notice, |
11 |
this list of conditions and the following disclaimer in the documentation |
12 |
and/or other materials provided with the distribution. |
13 |
|
14 |
* Neither the name of the author nor the names of its contributors may be used |
15 |
to endorse or promote products derived from this software without specific |
16 |
prior written permission. |
17 |
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
21 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
22 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
24 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
25 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
26 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 |
*/ |
29 |
|
30 |
#import <SenTestingKit/SenTestingKit.h> |
31 |
#import <SBJson/SBJson.h> |
32 |
|
33 |
#pragma mark Helper objects |
34 |
|
35 |
@interface True : NSObject |
36 |
@end |
37 |
|
38 |
@implementation True |
39 |
- (id)proxyForJson { |
40 |
return [NSNumber numberWithBool:YES]; |
41 |
} |
42 |
@end |
43 |
|
44 |
@interface False : NSObject |
45 |
@end |
46 |
|
47 |
@implementation False |
48 |
- (id)proxyForJson { |
49 |
return [NSNumber numberWithBool:NO]; |
50 |
} |
51 |
@end |
52 |
|
53 |
@interface Bool : NSObject |
54 |
@end |
55 |
|
56 |
@implementation Bool |
57 |
- (id)proxyForJson { |
58 |
return [NSArray arrayWithObjects:[True new], [False new], nil]; |
59 |
} |
60 |
@end |
61 |
|
62 |
@implementation NSDate (Private) |
63 |
- (id)proxyForJson { |
64 |
return [NSArray arrayWithObject:[self description]]; |
65 |
} |
66 |
@end |
67 |
|
68 |
#pragma mark Tests |
69 |
|
70 |
@interface ProxyTest : SenTestCase { |
71 |
SBJsonWriter * writer; |
72 |
} |
73 |
@end |
74 |
|
75 |
|
76 |
@implementation ProxyTest |
77 |
|
78 |
- (void)setUp { |
79 |
writer = [SBJsonWriter new]; |
80 |
} |
81 |
|
82 |
- (void)testUnsupportedWithoutProxy { |
83 |
STAssertNil([writer stringWithObject:[NSArray arrayWithObject:[NSObject new]]], nil); |
84 |
STAssertEqualObjects(writer.error, @"JSON serialisation not supported for NSObject", nil); |
85 |
} |
86 |
|
87 |
- (void)testUnsupportedWithProxy { |
88 |
STAssertEqualObjects([writer stringWithObject:[NSArray arrayWithObject:[True new]]], @"[true]", nil); |
89 |
} |
90 |
|
91 |
- (void)testUnsupportedWithProxyWithoutWrapper { |
92 |
STAssertNil([writer stringWithObject:[True new]], nil); |
93 |
} |
94 |
|
95 |
- (void)testUnsupportedWithNestedProxy { |
96 |
STAssertEqualObjects([writer stringWithObject:[NSArray arrayWithObject:[Bool new]]], @"[[true,false]]", nil); |
97 |
} |
98 |
|
99 |
- (void)testUnsupportedWithProxyAsCategory { |
100 |
STAssertNotNil([writer stringWithObject:[NSArray arrayWithObject:[NSDate date]]], nil); |
101 |
} |
102 |
|
103 |
- (void)testUnsupportedWithProxyAsCategoryWithoutWrapper { |
104 |
STAssertNotNil([writer stringWithObject:[NSDate date]], nil); |
105 |
} |
106 |
|
107 |
|
108 |
@end |