root / json-framework-3.2.0 / Tests / FormatTest.m @ 3ebe9884
History | View | Annotate | Download (3.2 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 FormatTest : JsonTestCase |
37 |
@end |
38 |
|
39 |
@implementation FormatTest |
40 |
|
41 |
- (void)setUp { |
42 |
[super setUp]; |
43 |
writer.humanReadable = YES; |
44 |
writer.sortKeys = YES; |
45 |
} |
46 |
|
47 |
|
48 |
- (void)testString { |
49 |
[self foreachTestInSuite:@"Tests/Data/format" apply:^(NSString *inpath, NSString *outpath) { |
50 |
NSError *error = nil; |
51 |
NSString *input = [NSString stringWithContentsOfFile:inpath encoding:NSUTF8StringEncoding error:&error]; |
52 |
STAssertNotNil(input, @"%@ - %@", inpath, error); |
53 |
|
54 |
NSString *output = [NSString stringWithContentsOfFile:outpath encoding:NSUTF8StringEncoding error:&error]; |
55 |
STAssertNotNil(output, @"%@ - %@", outpath, error); |
56 |
|
57 |
id object = [parser objectWithString:input]; |
58 |
STAssertNotNil(object, nil); |
59 |
|
60 |
NSString *json = [writer stringWithObject:object]; |
61 |
STAssertNotNil(json, nil); |
62 |
|
63 |
json = [json stringByAppendingString:@"\n"]; |
64 |
STAssertEqualObjects(json, output, nil); |
65 |
}]; |
66 |
|
67 |
STAssertEquals(count, (NSUInteger)8, nil); |
68 |
} |
69 |
|
70 |
- (void)testData { |
71 |
[self foreachTestInSuite:@"Tests/Data/format" apply:^(NSString *inpath, NSString *outpath) { |
72 |
NSError *error = nil; |
73 |
NSData *input = [NSData dataWithContentsOfFile:inpath]; |
74 |
STAssertNotNil(input, @"%@ - %@", inpath, error); |
75 |
|
76 |
id object = [parser objectWithData:input]; |
77 |
STAssertNotNil(object, nil); |
78 |
|
79 |
NSData *json = [writer dataWithObject:object]; |
80 |
STAssertNotNil(json, nil); |
81 |
|
82 |
NSData *output = [NSData dataWithContentsOfFile:outpath]; |
83 |
STAssertNotNil(output, @"%@ - %@", outpath, error); |
84 |
|
85 |
output = [NSData dataWithBytes:output.bytes length:output.length-1]; |
86 |
STAssertEqualObjects(json, output, nil); |
87 |
}]; |
88 |
|
89 |
STAssertEquals(count, (NSUInteger)8, nil); |
90 |
} |
91 |
|
92 |
@end |