@@ -15,6 +15,22 @@ @interface MPWArrayCursor()
15
15
@end
16
16
17
17
@implementation MPWArrayCursor
18
+ {
19
+ long offset;
20
+ }
21
+
22
+ @dynamic offset;
23
+
24
+ -(long )offset
25
+ {
26
+ return offset;
27
+ }
28
+
29
+ -(void )setOffset : (long )newOffset
30
+ {
31
+ offset=newOffset;
32
+ [self .selectionChanges writeObject: self ];
33
+ }
18
34
19
35
+(instancetype )cursorWithArray : (NSMutableArray *)newarray
20
36
{
@@ -86,29 +102,46 @@ + (instancetype)referenceWithIdentifier:(id)anIdentifier inStore:(id)aStore {
86
102
87
103
@implementation MPWArrayCursor (testing)
88
104
89
- +(void ) testCanGetValueAtTheInitialisedOffset
105
+ +(instancetype ) _testCursor
90
106
{
91
- NSArray *testArray=@[ @" a" , @" b" ];
107
+ NSMutableArray *testArray=[[ @[ @" a" , @" b" ] mutableCopy ] autorelease ];
92
108
MPWArrayCursor *cursor1=[self cursorWithArray: testArray];
109
+ return cursor1;
110
+ }
111
+
112
+ +(void )testCanGetValueAtOffset
113
+ {
114
+ MPWArrayCursor *cursor1=[self _testCursor ];
93
115
IDEXPECT ( [cursor1 value ], @" a" , @" offset 0" );
94
116
cursor1.offset =1 ;
95
117
IDEXPECT ( [cursor1 value ], @" b" , @" offset 1" );
96
118
}
97
119
98
- +(void )testCanSetValueAtTheInitialisedOffset
120
+ +(void )testCanSetValueAtOffset
99
121
{
100
- NSMutableArray *testArray=[[@[ @" a" , @" b" ] mutableCopy ] autorelease ];
101
- MPWArrayCursor *cursor1=[self cursorWithArray: testArray];
122
+ MPWArrayCursor *cursor1=[self _testCursor ];
102
123
IDEXPECT ( [cursor1 value ], @" a" , @" offset 0" );
103
124
cursor1.value = @" new value" ;
104
- IDEXPECT ( [testArray firstObject ], @" new value" , @" did set" );
125
+ IDEXPECT ( cursor1.value , @" new value" , @" did set" );
126
+ }
127
+
128
+ +(void )testCanBeNotified
129
+ {
130
+ MPWArrayCursor *cursor1=[self _testCursor ];
131
+ NSMutableArray *notifications=[NSMutableArray array ];
132
+ cursor1.selectionChanges =notifications;
133
+ INTEXPECT (notifications.count ,0 ,@" no notifications" );
134
+ cursor1.offset = 1 ;
135
+ INTEXPECT (notifications.count ,1 ,@" got a notification" );
136
+
105
137
}
106
138
107
139
+(NSArray *)testSelectors
108
140
{
109
141
return @[
110
- @" testCanGetValueAtTheInitialisedOffset" ,
111
- @" testCanSetValueAtTheInitialisedOffset" ,
142
+ @" testCanGetValueAtOffset" ,
143
+ @" testCanSetValueAtOffset" ,
144
+ @" testCanBeNotified" ,
112
145
];
113
146
}
114
147
0 commit comments