comparison clients/editor/scripts/tests/undotest.py @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents
children 8b125ec749d7
comparison
equal deleted inserted replaced
254:10b5f7f36dd4 255:51cc05d862f2
1 import scripts.undomanager as undomanager
2
3 print "Testing undomanager:"
4 umanager = undomanager.UndoManager(branchedMode=False)
5
6 print "--- Testing basic undo/redo ---"
7
8 print "Adding 3 actions:"
9 def undoPrint(msg):
10 print msg
11 def newAction(nr):
12 undo = lambda: undoPrint("Undo: "+str(nr))
13 redo = lambda: undoPrint("Redo: "+str(nr))
14 return undomanager.UndoObject(undo, redo, "Name: "+str(nr), "Description: "+str(nr))
15
16
17 umanager.addAction(newAction("1"))
18 umanager.addAction(newAction("2"))
19 umanager.addAction(newAction("3"))
20
21 print "Undoing 3 actions:"
22 umanager.undo(3);
23
24 print "Redoing 3 actions, individually:"
25 umanager.redo()
26 umanager.redo()
27 umanager.redo()
28
29 print "--- Testing undogroups ---"
30 print "10 actions, 2 undogroups nested within 1 undogroup"
31 umanager.startGroup("ActionGroup 1", "Desc: AG1")
32 umanager.addAction(newAction("1"))
33 umanager.addAction(newAction("2"))
34 umanager.addAction(newAction("3"))
35 umanager.startGroup("ActionGroup 2", "AG2")
36 umanager.addAction(newAction("4"))
37 umanager.addAction(newAction("5"))
38 umanager.addAction(newAction("6"))
39 umanager.endGroup()
40 umanager.startGroup("ActionGroup 2", "AG2")
41 umanager.addAction(newAction("7"))
42 umanager.addAction(newAction("8"))
43 umanager.addAction(newAction("9"))
44 umanager.addAction(newAction("10"))
45 umanager.endGroup()
46 umanager.endGroup()
47
48 print "Undoing group:"
49 umanager.undo()
50
51 print "Redo"
52 umanager.redo()
53
54 print "--- Testing branches (without branch mode) ---"
55 print "Branch mode:", umanager.getBranchMode()
56
57 print "Setting up actions"
58 umanager.addAction(newAction("1-1"))
59 umanager.addAction(newAction("1-2"))
60 umanager.addAction(newAction("1-3"))
61 umanager.undo(3)
62 umanager.addAction(newAction("2-1"))
63 umanager.addAction(newAction("2-2"))
64 umanager.addAction(newAction("2-3"))
65 umanager.undo(3)
66 umanager.addAction(newAction("3-1"))
67 umanager.addAction(newAction("3-2"))
68 umanager.addAction(newAction("3-3"))
69 umanager.undo(3)
70 print "Branches", umanager.getBranches()
71 print "Next branch"
72 umanager.nextBranch()
73 umanager.redo(3)
74 umanager.undo(3)
75 print "Prev branch"
76 umanager.previousBranch()
77 umanager.redo(3)
78
79 print "--- Testing branches (with branch mode) ---"
80 print "Activating branch mode:"
81 umanager.setBranchMode(True)
82 print "Branch mode:", umanager.getBranchMode()
83
84 print "Setting up actions"
85 umanager.addAction(newAction("1-1"))
86 umanager.addAction(newAction("1-2"))
87 umanager.addAction(newAction("1-3"))
88 umanager.undo(3)
89 umanager.addAction(newAction("2-1"))
90 umanager.addAction(newAction("2-2"))
91 umanager.addAction(newAction("2-3"))
92 umanager.undo(3)
93 umanager.addAction(newAction("3-1"))
94 umanager.addAction(newAction("3-2"))
95 umanager.addAction(newAction("3-3"))
96 umanager.undo(3)
97 print "Branches", umanager.getBranches()
98 print "Next branch"
99 umanager.nextBranch()
100 umanager.redo(3)
101 umanager.undo(3)
102 print "Prev branch"
103 umanager.previousBranch()
104 umanager.redo(3)
105
106 import gc
107 print "--- Testing clear() function ---"
108 print "Checking garbage:", gc.collect(), "Uncollectable:", len(gc.garbage)
109 print "Clearing history"
110 umanager.clear()
111 print "Checking garbage:", gc.collect(), "Uncollectable:", len(gc.garbage)
112
113 print "--- Done ---"