PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/Tests/Foundation/CPObjectTest.j

http://github.com/cacaodev/cappuccino
Unknown | 110 lines | 82 code | 28 blank | 0 comment | 0 complexity | 011716191426ef08f7092bddf9180508 MD5 | raw file
  1@import <Foundation/CPObject.j>
  2
  3@implementation CPObjectTest : OJTestCase
  4{
  5}
  6
  7- (void)testCPObjectIsSubclassOfClassCPObjectShouldBeTrue
  8{
  9    [self assertTrue:[CPObject isSubclassOfClass:[CPObject class]]];
 10}
 11
 12- (void)testIsSubclassOfClassWithNonSubclassShouldBeFalse
 13{
 14    [self assertFalse:[CPObject isSubclassOfClass:[SuperReceiver class]]];
 15}
 16
 17- (void)testImplementsSelector
 18{
 19    var receiver = [[Receiver alloc] init];
 20
 21    [self assertTrue:[receiver implementsSelector:@selector(implementedInReceiverAndSuper)]];
 22    [self assertTrue:[receiver implementsSelector:@selector(implementedInReceiverOnly)]];
 23
 24    [self assertFalse:[receiver implementsSelector:@selector(implementedInSuperOnly)]];
 25    [self assertFalse:[receiver implementsSelector:@selector(notImplementedInSuperNorReceiver)]];
 26}
 27
 28- (void)testVersion
 29{
 30    // zero by default
 31    [self assert:[CPObject version] equals:0];
 32
 33    // create a random new version and round it to an integer
 34    var newVersion = ROUND(RAND() * 100);
 35
 36    // make sure it's not zero
 37    while (newVersion == 0)
 38        newVersion = ROUND(RAND() * 100);
 39
 40    [CPObject setVersion:newVersion];
 41
 42    // test to make sure the assignment worked
 43    [self assert:[CPObject version] equals:newVersion];
 44}
 45
 46- (void)testMultipleArgumentPerformSelector
 47{
 48    var receiver = [[Receiver alloc] init],
 49
 50        value1 = "a",
 51        value2 = "b",
 52        value3 = "c",
 53        value4 = "d",
 54        selector = @selector(implements:multiple:argument:selector:),
 55
 56        returnValue = [receiver performSelector:selector withObjects:value1, value2, value3, value4],
 57
 58        expectedReturnValue = value1 + value2 + value3 + value4;
 59
 60    [self assertTrue:expectedReturnValue === returnValue];
 61}
 62
 63- (void)testCPDescriptionOfObject
 64{
 65    var jSON = {"name": "Martin", "access":null},
 66        d = CPDescriptionOfObject(jSON);
 67
 68    [self assertTrue:d.indexOf("name:") !== -1 message:"Can't find 'name:' in description of json " + d];
 69    [self assertTrue:d.indexOf("access:") !== -1 message:"Can't find 'access:' in description of json " + d];
 70}
 71
 72- (void)testCPObjectNotEqualToNil
 73{
 74    var anObject = [[CPObject alloc] init];
 75
 76    [self assert:anObject notEqual:nil];
 77}
 78
 79@end
 80
 81@implementation SuperReceiver : CPObject
 82{
 83}
 84
 85- (void)implementedInReceiverAndSuper
 86{
 87}
 88
 89- (void)implementedInSuperOnly
 90{
 91}
 92@end
 93
 94@implementation Receiver : SuperReceiver
 95{
 96}
 97
 98- (void)implementedInReceiverAndSuper
 99{
100}
101
102- (void)implementedInReceiverOnly
103{
104}
105
106- (id)implements:(id)a multiple:(id)b argument:(id)c selector:(id)d
107{
108    return a + b + c + d;
109}
110@end