1 module actions.start_stop;
2 
3 import fluid;
4 
5 @safe:
6 
7 class StartAndStopAction : TreeAction {
8 
9     int starts;
10     int stops;
11     int iterations;
12     bool continueAfter;
13 
14     override void started() {
15         starts++;
16     }
17 
18     override void stopped() {
19         super.stopped();
20         stops++;
21     }
22 
23     override void beforeTree(Node, Rectangle) {
24         assert(starts > stops);
25         iterations++;
26     }
27 
28     override void afterTree() {
29         if (!continueAfter) {
30             stop;
31         }
32     }
33 
34 }
35 
36 @("Node.queueAction() will fire start and stop hooks")
37 unittest {
38 
39     auto root = vspace();
40     auto action = new StartAndStopAction;
41     root.queueAction(action);
42 
43     root.draw();
44     assert(action.starts == 1);
45     assert(action.stops == 1);
46     assert(action.iterations == 1);
47 
48     action.continueAfter = true;    
49     root.queueAction(action);
50     root.draw();
51     assert(action.starts == 2);
52     assert(action.stops == 1);
53     assert(action.iterations == 2);
54 
55 }
56 
57 @("Node.startAction() will fire start and stop hooks")
58 unittest {
59 
60     auto root = vspace();
61     auto action = new StartAndStopAction;
62     root.startAction(action);
63 
64     root.draw();
65     assert(action.starts == 1);
66     assert(action.stops == 1);
67     assert(action.iterations == 1);
68 
69     action.continueAfter = true;    
70     root.startAction(action);
71     root.draw();
72     assert(action.starts == 2);
73     assert(action.stops == 1);
74     assert(action.iterations == 2);
75 
76 }