Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 103 lines (90 sloc) 4.14 kb
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
1 //
2 // GBIvarsProviderTesting.m
3 // appledoc
4 //
5 // Created by Tomaz Kragelj on 26.7.10.
6 // Copyright (C) 2010 Gentle Bytes. All rights reserved.
7 //
8
9 #import "GBIvarsProvider.h"
10
32ab212 @tomaz Switched to GHUnit to be able to simply debug unit tests.
authored
11 @interface GBIvarsProviderTesting : GHTestCase
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
12 @end
13
14 @implementation GBIvarsProviderTesting
15
16 #pragma mark Ivar registration testing
17
18 - (void)testRegisterIvar_shouldAddIvarToList {
19 // setup
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
20 GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
6a04a24 @tomaz Implemented methods and properties parsing.
authored
21 GBIvarData *ivar = [GBIvarData ivarDataWithComponents:[NSArray arrayWithObjects:@"NSUInteger", @"_name", nil]];
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
22 // execute
23 [provider registerIvar:ivar];
24 // verify
25 assertThatBool([provider.ivars containsObject:ivar], equalToBool(YES));
26 assertThatInteger([provider.ivars count], equalToInteger(1));
27 assertThat([provider.ivars objectAtIndex:0], is(ivar));
28 }
29
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
30 - (void)testRegisterIvar_shouldSetParentObject {
31 // setup
32 GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
33 GBIvarData *ivar = [GBIvarData ivarDataWithComponents:[NSArray arrayWithObjects:@"NSUInteger", @"_name", nil]];
34 // execute
35 [provider registerIvar:ivar];
36 // verify
37 assertThat(ivar.parentObject, is(self));
38 }
39
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
40 - (void)testRegisterIvar_shouldIgnoreSameInstance {
41 // setup
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
42 GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
6a04a24 @tomaz Implemented methods and properties parsing.
authored
43 GBIvarData *ivar = [GBIvarData ivarDataWithComponents:[NSArray arrayWithObjects:@"NSUInteger", @"_name", nil]];
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
44 // execute
45 [provider registerIvar:ivar];
46 [provider registerIvar:ivar];
47 // verify
48 assertThatInteger([provider.ivars count], equalToInteger(1));
49 }
50
a926216 @tomaz Implemented ivars data merging.
authored
51 - (void)testRegisterIvar_shouldMergeDifferentInstanceWithSameName {
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
52 // setup
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
53 GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
a926216 @tomaz Implemented ivars data merging.
authored
54 GBIvarData *source = [GBIvarData ivarDataWithComponents:[NSArray arrayWithObjects:@"int", @"_index", nil]];
55 OCMockObject *destination = [OCMockObject niceMockForClass:[GBIvarData class]];
56 [[[destination stub] andReturn:@"_index"] nameOfIvar];
f85eb45 @tomaz Refactored merging methods to override GBModelBase implementation.
authored
57 [[destination expect] mergeDataFromObject:source];
a926216 @tomaz Implemented ivars data merging.
authored
58 [provider registerIvar:(GBIvarData *)destination];
59 // execute
60 [provider registerIvar:source];
61 // verify
62 [destination verify];
63 }
64
65 #pragma mark Merging testing
66
67 - (void)testMergeDataFromIvarsProvider_shouldMergeAllDifferentIvars {
68 // setup
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
69 GBIvarsProvider *original = [[GBIvarsProvider alloc] initWithParentObject:self];
a926216 @tomaz Implemented ivars data merging.
authored
70 [original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
71 [original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i2", nil]];
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
72 GBIvarsProvider *source = [[GBIvarsProvider alloc] initWithParentObject:self];
a926216 @tomaz Implemented ivars data merging.
authored
73 [source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
74 [source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i3", nil]];
75 // execute
76 [original mergeDataFromIvarsProvider:source];
77 // verify - only basic testing here, details at GBIvarDataTesting!
78 NSArray *ivars = [original ivars];
79 assertThatInteger([ivars count], equalToInteger(3));
80 assertThat([[ivars objectAtIndex:0] nameOfIvar], is(@"_i1"));
81 assertThat([[ivars objectAtIndex:1] nameOfIvar], is(@"_i2"));
82 assertThat([[ivars objectAtIndex:2] nameOfIvar], is(@"_i3"));
83 }
84
85 - (void)testMergeDataFromIvarsProvider_shouldPreserveSourceData {
86 // setup
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
87 GBIvarsProvider *original = [[GBIvarsProvider alloc] initWithParentObject:self];
a926216 @tomaz Implemented ivars data merging.
authored
88 [original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
89 [original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i2", nil]];
89f0413 @tomaz Implemented ivar and method parent object handling.
authored
90 GBIvarsProvider *source = [[GBIvarsProvider alloc] initWithParentObject:self];
a926216 @tomaz Implemented ivars data merging.
authored
91 [source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
92 [source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i3", nil]];
93 // execute
94 [original mergeDataFromIvarsProvider:source];
95 // verify - only basic testing here, details at GBIvarDataTesting!
96 NSArray *ivars = [source ivars];
97 assertThatInteger([ivars count], equalToInteger(2));
98 assertThat([[ivars objectAtIndex:0] nameOfIvar], is(@"_i1"));
99 assertThat([[ivars objectAtIndex:1] nameOfIvar], is(@"_i3"));
28a51ce @tomaz Implemented class parsing for class name, superclass name, adopted proto...
authored
100 }
101
102 @end
Something went wrong with that request. Please try again.