Refs #1632. Unit test for CPUndoManagerDidCloseUndoGroupNotification.

This commit is contained in:
Alexander Ljungberg committed 2012-07-26 13:32:01 +01:00
1 parent bf3c22f42c
commit 3e218d6aec
1 file changed
+47 -1
+47 -1
View File
@@ -3,12 +3,16 @@
@implementation CPUndoManagerTest : OJTestCase
{
CPUndoManager undoManager;
CPArray receivedNotifications;
CPUndoManager undoManager;
BOOL itIsDone;
}
- (void)setUp
{
undoManager = [[CPUndoManager alloc] init];
itIsDone = NO;
receivedNotifications = [CPMutableArray array];
}
- (void)testUndoMenuTitleForUndoActionName
@@ -35,4 +39,46 @@
[self assert:[undoManager redoMenuTitleForUndoActionName:"STRING"] equals:@"Redo STRING"];
}
- (void)testNotifications
{
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification:)
name:CPUndoManagerDidCloseUndoGroupNotification
object:undoManager];
[self doIt];
// The default run loop undo grouping won't be closed until the next run loop cycle.
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
CPLog.error("receivedNotifications: %@", receivedNotifications);
[self assert:CPUndoManagerDidCloseUndoGroupNotification equals:[receivedNotifications[0] name]];
[[CPNotificationCenter defaultCenter] removeObserver:self];
}
- (void)receiveNotification:(CPNotification)aNotification
{
[receivedNotifications addObject:aNotification];
}
- (void)doIt
{
[undoManager registerUndoWithTarget:self
selector:@selector(undoIt)
object:nil];
itIsDone = YES;
}
- (void)undoIt
{
[undoManager registerUndoWithTarget:self
selector:@selector(doit)
object:nil];
itIsDone = NO;
}
@end