Differences From Artifact [87d14c79b3]:
- File tests/OFObjectTests.m — part of check-in [374e1a1bfa] at 2021-01-02 22:04:26 on branch trunk — Update copyright (user: js, size: 7680) [annotate] [blame] [check-ins using] [more...]
To Artifact [84ff5d698c]:
- File
tests/OFObjectTests.m
— part of check-in
[14f1e22d79]
at
2021-05-08 23:22:59
on branch trunk
— tests: Align more with ObjFW style
ObjFW's style changed over the years, but the tests were never adjusted
to it. (user: js, size: 8271) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
19 20 21 22 23 24 25 | #if (defined(OF_DRAGONFLYBSD) && defined(__LP64__)) || defined(OF_NINTENDO_3DS) # define TOO_BIG (SIZE_MAX / 3) #else # define TOO_BIG (SIZE_MAX - 128) #endif | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #if (defined(OF_DRAGONFLYBSD) && defined(__LP64__)) || defined(OF_NINTENDO_3DS) # define TOO_BIG (SIZE_MAX / 3) #else # define TOO_BIG (SIZE_MAX - 128) #endif static OFString *const module = @"OFObject"; @interface MyObject: OFObject { id _objectValue; Class _classValue; bool _boolValue; char _charValue; short _shortValue; int _intValue; |
︙ | ︙ | |||
57 58 59 60 61 62 63 | @property (nonatomic) unsigned int unsignedIntValue; @property (nonatomic) unsigned long unsignedLongValue; @property (nonatomic) unsigned long long unsignedLongLongValue; @property (nonatomic) float floatValue; @property (nonatomic) double doubleValue; @end | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | @property (nonatomic) unsigned int unsignedIntValue; @property (nonatomic) unsigned long unsignedLongValue; @property (nonatomic) unsigned long long unsignedLongLongValue; @property (nonatomic) float floatValue; @property (nonatomic) double doubleValue; @end @implementation MyObject @synthesize objectValue = _objectValue, classValue = _classValue; @synthesize boolValue = _boolValue, charValue = _charValue; @synthesize shortValue = _shortValue, intValue = _intValue; @synthesize longValue = _longValue, longLongValue = _longLongValue; @synthesize unsignedCharValue = _unsignedCharValue; @synthesize unsignedShortValue = _unsignedShortValue; @synthesize unsignedIntValue = _unsignedIntValue; |
︙ | ︙ | |||
81 82 83 84 85 86 87 | } @end @implementation TestsAppDelegate (OFObjectTests) - (void)objectTests { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | | < | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | > | > | | > | | | | | | | | | | | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | } @end @implementation TestsAppDelegate (OFObjectTests) - (void)objectTests { void *pool = objc_autoreleasePoolPush(); OFObject *object; MyObject *myObject; TEST(@"+[description]", [[OFObject description] isEqual: @"OFObject"] && [[MyObject description] isEqual: @"MyObject"]) object = [[[OFObject alloc] init] autorelease]; myObject = [[[MyObject alloc] init] autorelease]; TEST(@"-[description]", [object.description isEqual: @"<OFObject>"] && [myObject.description isEqual: @"<MyObject>"]) myObject.objectValue = @"Hello"; myObject.classValue = myObject.class; TEST(@"-[valueForKey:]", [[myObject valueForKey: @"objectValue"] isEqual: @"Hello"] && [[myObject valueForKey: @"classValue"] isEqual: myObject.class] && [[myObject valueForKey: @"class"] isEqual: myObject.class]) EXPECT_EXCEPTION(@"-[valueForKey:] with undefined key", OFUndefinedKeyException, [myObject valueForKey: @"undefined"]) TEST(@"-[setValue:forKey:]", R([myObject setValue: @"World" forKey: @"objectValue"]) && R([myObject setValue: [OFObject class] forKey: @"classValue"]) && [myObject.objectValue isEqual: @"World"] && [myObject.classValue isEqual: [OFObject class]]) EXPECT_EXCEPTION(@"-[setValue:forKey:] with undefined key", OFUndefinedKeyException, [myObject setValue: @"x" forKey: @"undefined"]) myObject.boolValue = 1; myObject.charValue = 2; myObject.shortValue = 3; myObject.intValue = 4; myObject.longValue = 5; myObject.longLongValue = 6; myObject.unsignedCharValue = 7; myObject.unsignedShortValue = 8; myObject.unsignedIntValue = 9; myObject.unsignedLongValue = 10; myObject.unsignedLongLongValue = 11; myObject.floatValue = 12; myObject.doubleValue = 13; TEST(@"Auto-wrapping of -[valueForKey:]", [[myObject valueForKey: @"boolValue"] isEqual: [OFNumber numberWithBool: 1]] && [[myObject valueForKey: @"charValue"] isEqual: [OFNumber numberWithChar: 2]] && [[myObject valueForKey: @"shortValue"] isEqual: [OFNumber numberWithShort: 3]] && [[myObject valueForKey: @"intValue"] isEqual: [OFNumber numberWithInt: 4]] && [[myObject valueForKey: @"longValue"] isEqual: [OFNumber numberWithLong: 5]] && [[myObject valueForKey: @"longLongValue"] isEqual: [OFNumber numberWithLongLong: 6]] && [[myObject valueForKey: @"unsignedCharValue"] isEqual: [OFNumber numberWithUnsignedChar: 7]] && [[myObject valueForKey: @"unsignedShortValue"] isEqual: [OFNumber numberWithUnsignedShort: 8]] && [[myObject valueForKey: @"unsignedIntValue"] isEqual: [OFNumber numberWithUnsignedInt: 9]] && [[myObject valueForKey: @"unsignedLongValue"] isEqual: [OFNumber numberWithUnsignedLong: 10]] && [[myObject valueForKey: @"unsignedLongLongValue"] isEqual: [OFNumber numberWithUnsignedLongLong: 11]] && [[myObject valueForKey: @"floatValue"] isEqual: [OFNumber numberWithFloat: 12]] && [[myObject valueForKey: @"doubleValue"] isEqual: [OFNumber numberWithDouble: 13]]) TEST(@"Auto-wrapping of -[setValue:forKey:]", R([myObject setValue: [OFNumber numberWithBool: 0] forKey: @"boolValue"]) && R([myObject setValue: [OFNumber numberWithChar: 10] forKey: @"charValue"]) && R([myObject setValue: [OFNumber numberWithShort: 20] forKey: @"shortValue"]) && R([myObject setValue: [OFNumber numberWithInt: 30] forKey: @"intValue"]) && R([myObject setValue: [OFNumber numberWithLong: 40] forKey: @"longValue"]) && R([myObject setValue: [OFNumber numberWithLongLong: 50] forKey: @"longLongValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedChar: 60] forKey: @"unsignedCharValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedShort: 70] forKey: @"unsignedShortValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedInt: 80] forKey: @"unsignedIntValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedLong: 90] forKey: @"unsignedLongValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedLongLong: 100] forKey: @"unsignedLongLongValue"]) && R([myObject setValue: [OFNumber numberWithFloat: 110] forKey: @"floatValue"]) && R([myObject setValue: [OFNumber numberWithDouble: 120] forKey: @"doubleValue"]) && myObject.isBoolValue == 0 && myObject.charValue == 10 && myObject.shortValue == 20 && myObject.intValue == 30 && myObject.longValue == 40 && myObject.longLongValue == 50 && myObject.unsignedCharValue == 60 && myObject.unsignedShortValue == 70 && myObject.unsignedIntValue == 80 && myObject.unsignedLongValue == 90 && myObject.unsignedLongLongValue == 100 && myObject.floatValue == 110 && myObject.doubleValue == 120) EXPECT_EXCEPTION(@"Catch -[setValue:forKey:] with nil key for scalar", OFInvalidArgumentException, [myObject setValue: (id _Nonnull)nil forKey: @"intValue"]) TEST(@"-[valueForKeyPath:]", (myObject = [[[MyObject alloc] init] autorelease]) && (myObject.objectValue = [[[MyObject alloc] init] autorelease]) && R([myObject.objectValue setObjectValue: [[[MyObject alloc] init] autorelease]]) && R([[myObject.objectValue objectValue] setDoubleValue: 0.5]) && [[myObject valueForKeyPath: @"objectValue.objectValue.doubleValue"] doubleValue] == 0.5) TEST(@"[-setValue:forKeyPath:]", R([myObject setValue: [OFNumber numberWithDouble: 0.75] forKeyPath: @"objectValue.objectValue.doubleValue"]) && [[myObject.objectValue objectValue] doubleValue] == 0.75) objc_autoreleasePoolPop(pool); } @end |