PageRenderTime 17ms CodeModel.GetById 15ms app.highlight 0ms RepoModel.GetById 2ms app.codeStats 0ms

/Tests/Foundation/CPUndoManagerTest.j

http://github.com/cacaodev/cappuccino
Unknown | 83 lines | 62 code | 21 blank | 0 comment | 0 complexity | f75f3cd7ae55e57e0976126bb22ac105 MD5 | raw file
 1
 2@import <Foundation/CPUndoManager.j>
 3
 4@implementation CPUndoManagerTest : OJTestCase
 5{
 6    CPArray         receivedNotifications;
 7    CPUndoManager   undoManager;
 8    BOOL            itIsDone;
 9}
10
11- (void)setUp
12{
13    undoManager = [[CPUndoManager alloc] init];
14    itIsDone = NO;
15    receivedNotifications = [CPMutableArray array];
16}
17
18- (void)testUndoMenuTitleForUndoActionName
19{
20    [self assert:[undoManager undoMenuTitleForUndoActionName:undefined] equals:@"Undo"];
21    [self assert:[undoManager undoMenuTitleForUndoActionName:nil] equals:@"Undo"];
22    [self assert:[undoManager undoMenuTitleForUndoActionName:""] equals:@"Undo"];
23
24    [self assert:[undoManager undoMenuTitleForUndoActionName:0] equals:@"Undo 0"];
25    [self assert:[undoManager undoMenuTitleForUndoActionName:"0"] equals:@"Undo 0"];
26
27    [self assert:[undoManager undoMenuTitleForUndoActionName:"STRING"] equals:@"Undo STRING"];
28}
29
30- (void)testRedoMenuTitleForUndoActionName
31{
32    [self assert:[undoManager redoMenuTitleForUndoActionName:undefined] equals:@"Redo"];
33    [self assert:[undoManager redoMenuTitleForUndoActionName:nil] equals:@"Redo"];
34    [self assert:[undoManager redoMenuTitleForUndoActionName:""] equals:@"Redo"];
35
36    [self assert:[undoManager redoMenuTitleForUndoActionName:0] equals:@"Redo 0"];
37    [self assert:[undoManager redoMenuTitleForUndoActionName:"0"] equals:@"Redo 0"];
38
39    [self assert:[undoManager redoMenuTitleForUndoActionName:"STRING"] equals:@"Redo STRING"];
40}
41
42- (void)testNotifications
43{
44
45    [[CPNotificationCenter defaultCenter] addObserver:self
46                                             selector:@selector(receiveNotification:)
47                                                 name:CPUndoManagerDidCloseUndoGroupNotification
48                                               object:undoManager];
49
50    [self doIt];
51
52    // The default run loop undo grouping won't be closed until the next run loop cycle.
53    [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
54
55    [self assert:CPUndoManagerDidCloseUndoGroupNotification equals:[receivedNotifications[0] name]];
56
57    [[CPNotificationCenter defaultCenter] removeObserver:self];
58}
59
60- (void)receiveNotification:(CPNotification)aNotification
61{
62    [receivedNotifications addObject:aNotification];
63}
64
65- (void)doIt
66{
67    [undoManager registerUndoWithTarget:self
68                               selector:@selector(undoIt)
69                                 object:nil];
70
71    itIsDone = YES;
72}
73
74- (void)undoIt
75{
76    [undoManager registerUndoWithTarget:self
77                               selector:@selector(doit)
78                                 object:nil];
79
80    itIsDone = NO;
81}
82
83@end