root/trunk/Tests/JVChatWindowControllerTests.m

Revision 3302, 11.7 kB (checked in by timothy, 2 years ago)

Fixes a build problem

Line 
1 #import <Cocoa/Cocoa.h>
2 #import <SenTestingKit/SenTestingKit.h>
3 #import <AGRegex/AGRegex.h>
4 #import <ChatCore/ChatCore.h>
5
6 #import "JVChatWindowController.h"
7 #import "JVDirectChatPanel.h"
8
9 @interface JVTestChatViewController : NSObject <JVChatViewController> {
10         JVChatWindowController *_windowController;
11         unsigned _newMessages;
12 }
13 @end
14
15 @implementation JVTestChatViewController
16 - (MVChatConnection *) connection {
17         return nil;
18 }
19
20 - (JVChatWindowController *) windowController {
21         return _windowController;
22 }
23
24 - (void) setWindowController:(JVChatWindowController *) controller {
25         _windowController = controller;
26 }
27
28 - (NSView *) view {
29         return [[[NSView alloc] init] autorelease];
30 }
31
32 - (NSResponder *) firstResponder {
33         return [self view];
34 }
35
36 - (NSToolbar *) toolbar {
37         return nil;
38 }
39
40 - (NSString *) windowTitle {
41         return @"Test";
42 }
43
44 - (NSString *) identifier {
45         return @"testView";
46 }
47
48 - (id <JVChatListItem>) parent {
49         return nil;
50 }
51
52 - (NSImage *) icon {
53         [NSImage imageNamed:@"room"];
54 }
55
56 - (NSString *) title {
57         return @"Test";
58 }
59
60 - (unsigned) newMessagesWaiting {
61         return _newMessages;
62 }
63
64 - (void) setNewMessagesWaiting:(unsigned) new {
65         _newMessages = new;
66 }
67 @end
68
69 @interface JVChatWindowControllerTests : SenTestCase {
70         JVChatWindowController *windowController;
71 }
72 @end
73
74 @implementation JVChatWindowControllerTests
75 - (void) setUp {
76         windowController = [[JVChatWindowController alloc] init];
77         STAssertNotNil( windowController, nil );
78 }
79
80 - (void) tearDown {
81         [windowController release];
82         windowController = nil;
83 }
84
85 - (void) testAddChatViewController {
86         id panel = [[JVTestChatViewController alloc] init];
87         STAssertNotNil( panel, nil );
88
89         id panelTwo = [[JVTestChatViewController alloc] init];
90         STAssertNotNil( panelTwo, nil );
91
92         // there should no active panel
93         STAssertNil( [windowController activeChatViewController], nil );
94         STAssertNil( [windowController selectedListItem], nil );
95
96         [windowController showWindow:nil];
97
98         // there should still be no active panel
99         STAssertNil( [windowController activeChatViewController], nil );
100         STAssertNil( [windowController selectedListItem], nil );
101
102         [windowController addChatViewController:panel];
103
104         // panel should be the active panel
105         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
106         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
107         STAssertTrue( [[windowController allChatViewControllers] count] == 1, nil );
108
109         [windowController addChatViewController:panelTwo];
110
111         // panel should still be the active panel after adding panelTwo
112         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
113         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
114         STAssertTrue( [[windowController allChatViewControllers] count] == 2, nil );
115
116         // check duplicate add
117         STAssertThrows( [windowController addChatViewController:panelTwo], nil );
118
119         // nothing should have changed
120         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
121         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
122         STAssertTrue( [[windowController allChatViewControllers] count] == 2, nil );
123
124         // check nil add
125         STAssertThrows( [windowController addChatViewController:nil], nil );
126
127         // nothing should have changed
128         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
129         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
130         STAssertTrue( [[windowController allChatViewControllers] count] == 2, nil );
131
132         [panel release];
133         [panelTwo release];
134 }
135
136 - (void) testInsertChatViewController {
137         [windowController showWindow:nil];
138
139         id panel = [[JVTestChatViewController alloc] init];
140         STAssertNotNil( panel, nil );
141
142         id panelTwo = [[JVTestChatViewController alloc] init];
143         STAssertNotNil( panelTwo, nil );
144
145         id panelThree = [[JVTestChatViewController alloc] init];
146         STAssertNotNil( panelThree, nil );
147
148         id panelFour = [[JVTestChatViewController alloc] init];
149         STAssertNotNil( panelFour, nil );
150
151         [windowController insertChatViewController:panel atIndex:0];
152
153         // panel should be the active panel
154         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
155         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
156         STAssertTrue( [[windowController allChatViewControllers] count] == 1, nil );
157
158         [windowController insertChatViewController:panelTwo atIndex:1];
159
160         // panel should still be the active panel
161         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
162         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
163         STAssertTrue( [[windowController allChatViewControllers] count] == 2, nil );
164
165         [windowController insertChatViewController:panelThree atIndex:0];
166
167         // panel should still be the active panel
168         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
169         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
170         STAssertTrue( [[windowController allChatViewControllers] count] == 3, nil );
171
172         // check index out of bounds
173         STAssertThrows( [windowController insertChatViewController:panelFour atIndex:4], nil );
174
175         // nothing should have changed
176         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
177         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
178         STAssertTrue( [[windowController allChatViewControllers] count] == 3, nil );
179
180         // check duplicate insert
181         STAssertThrows( [windowController insertChatViewController:panelThree atIndex:0], nil );
182
183         // nothing should have changed
184         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
185         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
186         STAssertTrue( [[windowController allChatViewControllers] count] == 3, nil );
187
188         // check nil insert
189         STAssertThrows( [windowController insertChatViewController:nil atIndex:0], nil );
190
191         // nothing should have changed
192         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
193         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
194         STAssertTrue( [[windowController allChatViewControllers] count] == 3, nil );
195
196         [panel release];
197         [panelTwo release];
198         [panelThree release];
199         [panelFour release];
200 }
201
202 - (void) testRemoveChatViewController {
203         [windowController showWindow:nil];
204
205         id panel = [[JVTestChatViewController alloc] init];
206         STAssertNotNil( panel, nil );
207
208         id panelTwo = [[JVTestChatViewController alloc] init];
209         STAssertNotNil( panelTwo, nil );
210
211         id panelThree = [[JVTestChatViewController alloc] init];
212         STAssertNotNil( panelThree, nil );
213
214         [windowController insertChatViewController:panel atIndex:0];
215         [windowController insertChatViewController:panelTwo atIndex:1];
216         [windowController insertChatViewController:panelThree atIndex:2];
217
218         // panel should be the active panel
219         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
220         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
221         STAssertTrue( [[windowController allChatViewControllers] count] == 3, nil );
222
223         [windowController removeChatViewController:panel];
224
225         // panelTwo should now be the active panel
226         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
227         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
228         STAssertTrue( [[windowController allChatViewControllers] count] == 2, nil );
229
230         [windowController removeChatViewController:panelThree];
231
232         // panelTwo should still be the active panel
233         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
234         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
235         STAssertTrue( [[windowController allChatViewControllers] count] == 1, nil );
236
237         // check nil remove
238         STAssertThrows( [windowController removeChatViewController:nil], nil );
239
240         // nothing should have changed
241         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
242         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
243         STAssertTrue( [[windowController allChatViewControllers] count] == 1, nil );
244
245         // check duplicate remove
246         STAssertThrows( [windowController removeChatViewController:panelThree], nil );
247
248         // nothing should have changed
249         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
250         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
251         STAssertTrue( [[windowController allChatViewControllers] count] == 1, nil );
252
253         [windowController removeAllChatViewControllers];
254
255         // there should be no active panel
256         STAssertNil( [windowController activeChatViewController], nil );
257         STAssertNil( [windowController activeChatViewController], nil );
258         STAssertTrue( [[windowController allChatViewControllers] count] == 0, nil );
259
260         [panel release];
261         [panelTwo release];
262         [panelThree release];
263 }
264
265 - (void) testSelectChatViewController {
266         [windowController showWindow:nil];
267
268         id panel = [[JVTestChatViewController alloc] init];
269         STAssertNotNil( panel, nil );
270
271         id panelTwo = [[JVTestChatViewController alloc] init];
272         STAssertNotNil( panelTwo, nil );
273
274         id panelThree = [[JVTestChatViewController alloc] init];
275         STAssertNotNil( panelThree, nil );
276
277         [windowController insertChatViewController:panel atIndex:0];
278         [windowController insertChatViewController:panelTwo atIndex:1];
279         [windowController insertChatViewController:panelThree atIndex:2];
280
281         // panel should be the active panel
282         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
283         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
284         STAssertTrue( [[windowController allChatViewControllers] count] == 3, nil );
285
286         [windowController showChatViewController:panelTwo];
287
288         // panelTwo should now be the active panel
289         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
290         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
291
292         [windowController selectNextPanel:nil];
293
294         // panelThree should now be the active panel
295         STAssertTrue( [panelThree isEqual:[windowController activeChatViewController]], nil );
296         STAssertTrue( [panelThree isEqual:[windowController selectedListItem]], nil );
297
298         [windowController selectPreviousPanel:nil];
299
300         // panelTwo should now be the active panel
301         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
302         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
303
304         [windowController showChatViewController:panel];
305
306         // panel should now be the active panel
307         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
308         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
309
310         [windowController selectPreviousPanel:nil];
311
312         // panelThree should now be the active panel (it should loop to the end)
313         STAssertTrue( [panelThree isEqual:[windowController activeChatViewController]], nil );
314         STAssertTrue( [panelThree isEqual:[windowController selectedListItem]], nil );
315
316         [windowController selectNextPanel:nil];
317
318         // panel should now be the active panel (it should loop to the beginning)
319         STAssertTrue( [panel isEqual:[windowController activeChatViewController]], nil );
320         STAssertTrue( [panel isEqual:[windowController selectedListItem]], nil );
321
322         [panelThree setNewMessagesWaiting:1];
323         [windowController selectNextActivePanel:nil];
324
325         // panelThree should now be the active panel
326         STAssertTrue( [panelThree isEqual:[windowController activeChatViewController]], nil );
327         STAssertTrue( [panelThree isEqual:[windowController selectedListItem]], nil );
328
329         [panelThree setNewMessagesWaiting:0];
330         [panelTwo setNewMessagesWaiting:2];
331         [windowController selectPreviousActivePanel:nil];
332
333         // panelTwo should now be the active panel
334         STAssertTrue( [panelTwo isEqual:[windowController activeChatViewController]], nil );
335         STAssertTrue( [panelTwo isEqual:[windowController selectedListItem]], nil );
336
337         [panel release];
338         [panelTwo release];
339         [panelThree release];
340 }
341 @end
Note: See TracBrowser for help on using the browser.