root / json-framework-3.2.0 / Tests / JsonCheckerTest.m @ 3ebe9884
History | View | Annotate | Download (3.3 kB)
1 |
/* |
---|---|
2 |
Copyright (C) 2011 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 |
6 |
are met: |
7 |
|
8 |
* Redistributions of source code must retain the above copyright |
9 |
notice, this list of conditions and the following disclaimer. |
10 |
|
11 |
* Redistributions in binary form must reproduce the above copyright |
12 |
notice, this list of conditions and the following disclaimer in the |
13 |
documentation and/or other materials provided with the distribution. |
14 |
|
15 |
* Neither the name of the author nor the names of its contributors |
16 |
may be used to endorse or promote products derived from this |
17 |
software without specific prior written permission. |
18 |
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 |
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 |
|
31 |
*/ |
32 |
|
33 |
|
34 |
#import "JsonTestCase.h" |
35 |
|
36 |
@interface JsonCheckerTest : JsonTestCase |
37 |
@end |
38 |
|
39 |
@implementation JsonCheckerTest |
40 |
|
41 |
- (void)setUp { |
42 |
[super setUp]; |
43 |
parser.maxDepth = 19; |
44 |
} |
45 |
|
46 |
- (void)foreachFilePrefixedBy:(NSString*)prefix inSuite:(NSString*)suite apply:(void(^)(NSString*))block { |
47 |
NSString *file; |
48 |
NSString *rootPath = [[self class] pathForSuite:suite]; |
49 |
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:rootPath]; |
50 |
|
51 |
while ((file = [enumerator nextObject])) { |
52 |
if (![file hasPrefix:prefix]) |
53 |
continue; |
54 |
|
55 |
NSString *path = [rootPath stringByAppendingPathComponent:file]; |
56 |
if ([[NSFileManager defaultManager] isReadableFileAtPath:path]) { |
57 |
block(path); |
58 |
count++; |
59 |
} |
60 |
} |
61 |
} |
62 |
|
63 |
- (void)testPass { |
64 |
[self foreachFilePrefixedBy:@"pass" inSuite:@"Tests/Data/jsonchecker" apply:^(NSString* path) { |
65 |
NSError *error = nil; |
66 |
NSString *input = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; |
67 |
STAssertNotNil(input, @"%@ - %@", path, error); |
68 |
|
69 |
id object = [parser objectWithString:input]; |
70 |
STAssertNotNil(object, path); |
71 |
STAssertNil(parser.error, path); |
72 |
|
73 |
}]; |
74 |
STAssertEquals(count, (NSUInteger)3, nil); |
75 |
} |
76 |
|
77 |
- (void)testFail { |
78 |
[self foreachFilePrefixedBy:@"fail" inSuite:@"Tests/Data/jsonchecker" apply:^(NSString* path) { |
79 |
NSError *error = nil; |
80 |
NSString *input = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; |
81 |
STAssertNotNil(input, @"%@ - %@", path, error); |
82 |
|
83 |
STAssertNil([parser objectWithString:input], @"%@ - %@", input, path); |
84 |
STAssertNotNil(parser.error, @"%@ at %@", input, path); |
85 |
}]; |
86 |
|
87 |
STAssertEquals(count, (NSUInteger)33, nil); |
88 |
} |
89 |
|
90 |
@end |