/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. @import <Foundation/CPUndoManager.j>
  2. @implementation CPUndoManagerTest : OJTestCase
  3. {
  4. CPArray receivedNotifications;
  5. CPUndoManager undoManager;
  6. BOOL itIsDone;
  7. }
  8. - (void)setUp
  9. {
  10. undoManager = [[CPUndoManager alloc] init];
  11. itIsDone = NO;
  12. receivedNotifications = [CPMutableArray array];
  13. }
  14. - (void)testUndoMenuTitleForUndoActionName
  15. {
  16. [self assert:[undoManager undoMenuTitleForUndoActionName:undefined] equals:@"Undo"];
  17. [self assert:[undoManager undoMenuTitleForUndoActionName:nil] equals:@"Undo"];
  18. [self assert:[undoManager undoMenuTitleForUndoActionName:""] equals:@"Undo"];
  19. [self assert:[undoManager undoMenuTitleForUndoActionName:0] equals:@"Undo 0"];
  20. [self assert:[undoManager undoMenuTitleForUndoActionName:"0"] equals:@"Undo 0"];
  21. [self assert:[undoManager undoMenuTitleForUndoActionName:"STRING"] equals:@"Undo STRING"];
  22. }
  23. - (void)testRedoMenuTitleForUndoActionName
  24. {
  25. [self assert:[undoManager redoMenuTitleForUndoActionName:undefined] equals:@"Redo"];
  26. [self assert:[undoManager redoMenuTitleForUndoActionName:nil] equals:@"Redo"];
  27. [self assert:[undoManager redoMenuTitleForUndoActionName:""] equals:@"Redo"];
  28. [self assert:[undoManager redoMenuTitleForUndoActionName:0] equals:@"Redo 0"];
  29. [self assert:[undoManager redoMenuTitleForUndoActionName:"0"] equals:@"Redo 0"];
  30. [self assert:[undoManager redoMenuTitleForUndoActionName:"STRING"] equals:@"Redo STRING"];
  31. }
  32. - (void)testNotifications
  33. {
  34. [[CPNotificationCenter defaultCenter] addObserver:self
  35. selector:@selector(receiveNotification:)
  36. name:CPUndoManagerDidCloseUndoGroupNotification
  37. object:undoManager];
  38. [self doIt];
  39. // The default run loop undo grouping won't be closed until the next run loop cycle.
  40. [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
  41. [self assert:CPUndoManagerDidCloseUndoGroupNotification equals:[receivedNotifications[0] name]];
  42. [[CPNotificationCenter defaultCenter] removeObserver:self];
  43. }
  44. - (void)receiveNotification:(CPNotification)aNotification
  45. {
  46. [receivedNotifications addObject:aNotification];
  47. }
  48. - (void)doIt
  49. {
  50. [undoManager registerUndoWithTarget:self
  51. selector:@selector(undoIt)
  52. object:nil];
  53. itIsDone = YES;
  54. }
  55. - (void)undoIt
  56. {
  57. [undoManager registerUndoWithTarget:self
  58. selector:@selector(doit)
  59. object:nil];
  60. itIsDone = NO;
  61. }
  62. @end