From 3e218d6aec395faef0ec0565b0b255765ef9d0bd Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 26 Jul 2012 13:32:01 +0100 Subject: [PATCH] Refs #1632. Unit test for `CPUndoManagerDidCloseUndoGroupNotification`. --- Tests/Foundation/CPUndoManagerTest.j | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/Tests/Foundation/CPUndoManagerTest.j b/Tests/Foundation/CPUndoManagerTest.j index 857794eba..67ef6308c 100644 --- a/Tests/Foundation/CPUndoManagerTest.j +++ b/Tests/Foundation/CPUndoManagerTest.j @@ -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