Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (102 sloc) 6.112 kb
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
1 //
2 // PropertiesTest.m
3 // Baker
4 //
5 // ==========================================================================================
6 //
7 // Copyright (c) 2011, Davide Casali, Marco Colombo, Alessandro Morandi
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without modification, are
11 // permitted provided that the following conditions are met:
12 //
13 // Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the following disclaimer.
15 // Redistributions in binary form must reproduce the above copyright notice, this list of
16 // conditions and the following disclaimer in the documentation and/or other materials
17 // provided with the distribution.
18 // Neither the name of the Baker Framework nor the names of its contributors may be used to
19 // endorse or promote products derived from this software without specific prior written
20 // permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
22 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 // LIABILITY, OR TORT (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 #import "PropertiesTest.h"
33 #import "Properties.h"
34
35
36 @implementation PropertiesTest
37
38 - (void)testGetMultiArgs {
39
40 Properties *properties = [[Properties alloc]init];
41 id property = [properties get:@"one", @"two", @"three", nil];
42 STAssertNil(property, @"Should not find non existing property");
43
44 }
45
46 - (void)testFallbackFrom {
47 NSArray *objects = [NSArray arrayWithObjects:@"blah", nil];
48 NSArray *keys = [NSArray arrayWithObjects:@"string", nil];
49 NSDictionary *fbDict = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
50 NSDictionary *dict = [[NSDictionary alloc] init];
51
52 Properties *properties = [[Properties alloc]init];
53 id property = [properties getFrom:dict withFallback:fbDict withKeys:keys];
54 STAssertEquals(property, @"blah", @"Should return the fallback item");
55 }
56
57 - (void)testGetSimpleTypesFrom {
58 NSArray *objects = [NSArray arrayWithObjects:
59 @"blah",
60 [[NSNumber alloc] initWithInteger:1],
61 [NSNumber numberWithBool:YES],
b24492f @Simbul Pages are now based on the "contents" property in the manifest file.
authored
62 [NSArray arrayWithObjects:@"one", @"two", nil],
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
63 nil];
64 NSArray *keys = [NSArray arrayWithObjects:
65 @"string",
66 @"number",
67 @"boolean",
b24492f @Simbul Pages are now based on the "contents" property in the manifest file.
authored
68 @"array",
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
69 nil];
70 NSDictionary *dict = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
71
72 Properties *properties = [[Properties alloc]init];
73 id property;
74 NSArray *queryKeys;
75
76 queryKeys = [NSArray arrayWithObjects:@"string", nil];
77 property = [properties getFrom:dict withKeys:queryKeys];
78 STAssertEqualObjects(property, @"blah", @"Should return a string");
79
80 queryKeys = [NSArray arrayWithObjects:@"number", nil];
81 property = [properties getFrom:dict withKeys:queryKeys];
82 STAssertEqualObjects(property, [[NSNumber alloc] initWithInteger:1], @"Should return a number");
83
84 queryKeys = [NSArray arrayWithObjects:@"boolean", nil];
85 property = [properties getFrom:dict withKeys:queryKeys];
86 STAssertEquals([property boolValue], YES, @"Should return an int corresponding to a boolean");
b24492f @Simbul Pages are now based on the "contents" property in the manifest file.
authored
87
88 queryKeys = [NSArray arrayWithObjects:@"array", nil];
89 property = [properties getFrom:dict withKeys:queryKeys];
90 STAssertEquals(property, [objects objectAtIndex:3], @"Should return an int corresponding to an array");
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
91 }
92
93 - (void)testDefaults {
94 Properties *properties = [[Properties alloc]init];
95 id property;
96
30b7263 @Simbul Updated example manifest file to the new specification (see #102).
authored
97 property = [properties get:@"orientation", nil];
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
98 STAssertEqualObjects(property, @"both", @"Should return expected default value for orientation");
99
30b7263 @Simbul Updated example manifest file to the new specification (see #102).
authored
100 property = [properties get:@"zoomable", nil];
8fc8d53 @Simbul Fixed tests and added missing tests for default properties.
authored
101 STAssertEquals([property boolValue], NO, @"Should return expected default value for zoomable");
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
102
30b7263 @Simbul Updated example manifest file to the new specification (see #102).
authored
103 property = [properties get:@"-baker-background", nil];
104 STAssertEqualObjects(property, @"#000000", @"Should return expected default value for -baker-background");
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
105
30b7263 @Simbul Updated example manifest file to the new specification (see #102).
authored
106 property = [properties get:@"-baker-vertical-bounce", nil];
8fc8d53 @Simbul Fixed tests and added missing tests for default properties.
authored
107 STAssertEquals([property boolValue], YES, @"Should return expected default value for -baker-vertical-bounce");
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
108
8fc8d53 @Simbul Fixed tests and added missing tests for default properties.
authored
109 property = [properties get:@"-baker-page-numbers-color", nil];
110 STAssertEqualObjects(property, @"#FFFFFF", @"Should return expected default value for -baker-page-numbers-color");
111
112 property = [properties get:@"-baker-page-numbers-alpha", nil];
113 STAssertEqualObjects(property, [NSDecimalNumber decimalNumberWithString:@"0.3"], @"Should return expected default value for -baker-page-numbers-alpha");
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
114
30b7263 @Simbul Updated example manifest file to the new specification (see #102).
authored
115 property = [properties get:@"-baker-media-autoplay", nil];
8fc8d53 @Simbul Fixed tests and added missing tests for default properties.
authored
116 STAssertEquals([property boolValue], YES, @"Should return expected default value for -baker-media-autoplay");
117
118 property = [properties get:@"-baker-index-height", nil];
119 STAssertEquals(property, [NSNull null], @"Should return expected default value for -baker-index-height");
120
121 property = [properties get:@"-baker-index-bounce", nil];
122 STAssertEquals([property boolValue], NO, @"Should return expected default value for -baker-index-bounce");
d875360 @Simbul Added support for property -baker-vertical-pagination to manifest fil…
authored
123
124 property = [properties get:@"-baker-vertical-pagination", nil];
125 STAssertEquals([property boolValue], NO, @"Should return expected default value for -baker-vertical-pagination");
d9ad5e2 @Simbul Added Properties class to manage the JSON manifest.
authored
126 }
127
128 @end
Something went wrong with that request. Please try again.