dbab9c53 |
1 | puts "===========" |
2 | puts "0031748: Application Framework - Efficient OCAF transactions in OCCT" |
3 | puts "===========" |
4 | |
5 | # This test checks behavior of attributes in different combinations of transactions: |
6 | # creation/modification/deletion of attributes inside and outside of transaction and after |
7 | # that on Undo/Redo. |
8 | |
9 | NewDocument D |
10 | UndoLimit D 100 |
11 | |
12 | # enumeration of actions: first come actions where no attribute needed on the label, after none, after - attribute must be on the label |
13 | set act_create 0 |
14 | set act_createforget 1 |
15 | set act_createmodify 2 |
16 | set act_none 3 |
17 | set act_modify 4 |
18 | set act_modifyforget 5 |
19 | set act_forget 6 |
20 | set act_forgetcreate 7 |
21 | # the number of possible actions that can be done on attribute |
22 | set actions 8 |
23 | # some action undome in transaction |
24 | set act_undone 100 |
25 | |
26 | set act_afternone [expr $act_none+1] |
27 | |
7b5e532f |
28 | # returns 1 if after this action there exists attribute on the label |
dbab9c53 |
29 | proc produces_attribute1 {action} { |
30 | global act_create act_modify act_forgetcreate act_createmodify |
31 | if {$action==$act_create || $action==$act_createmodify || $action==$act_modify || $action==$act_forgetcreate} { |
32 | return 1 |
33 | } |
34 | return 0 |
35 | } |
36 | |
7b5e532f |
37 | # returns 1 if after two actions there exists attribute on the label |
dbab9c53 |
38 | proc produces_attribute2 {action1 action2} { |
39 | global act_create act_modify act_modifyforget act_forget act_createforget act_none act_forgetcreate act_undone |
40 | |
41 | if {$action1 == $act_undone && $action2 == $act_modify} { |
42 | return 0 |
43 | } |
44 | if {$action1 == $act_undone && $action2 == $act_forgetcreate} { |
45 | return 0 |
46 | } |
47 | if {[produces_attribute1 $action2]} { |
48 | return 1 |
49 | } |
50 | if {$action2!=$act_forget && $action2!=$act_createforget && $action2!=$act_modifyforget && [produces_attribute1 $action1]} { |
51 | return 1 |
52 | } |
53 | return 0 |
54 | } |
55 | |
7b5e532f |
56 | # returns value of the attribute produced by two actions |
dbab9c53 |
57 | proc produces_value {action1 action2} { |
58 | global act_modify act_createmodify act_none act_forgetcreate |
59 | if {$action2==$act_modify} { |
60 | if {$action1==$act_createmodify} { |
61 | return 3 |
62 | } |
63 | return 2 |
64 | } |
65 | if {$action2==$act_createmodify} { |
66 | return 2 |
67 | } |
68 | if {$action1==$act_createmodify && $action2!=$act_forgetcreate} { |
69 | return 2 |
70 | } |
71 | if {$action1==$act_none && $action1==$act_createmodify} { |
72 | return 2 |
73 | } |
74 | return 1 |
75 | } |
76 | |
77 | proc attribute_name attr_id { |
78 | if $attr_id==0 { |
79 | return Integer |
80 | } |
81 | return Real |
82 | } |
83 | |
84 | proc do_action {label attr action} { |
85 | global D |
86 | set attrName [attribute_name $attr] |
87 | switch $action { # first there are atcions that leave attribute, then - none, then - that remove it |
88 | 0 { # sets a new attribute |
89 | Set$attrName D $label 1 |
90 | } |
91 | 1 { # creates and immediately forgets a new attribute |
92 | Set$attrName D $label 1 |
93 | if $attr==0 { # forget integer |
94 | ForgetAtt D $label 2a96b606-ec8b-11d0-bee7-080009dc3333 |
95 | } else { # forget real |
96 | ForgetAtt D $label 2a96b60f-ec8b-11d0-bee7-080009dc3333 |
97 | } |
98 | } |
99 | 2 { # sets and modifies attribute |
100 | Set$attrName D $label 1 |
101 | Set$attrName D $label 2 |
102 | } |
103 | 3 { # nothing to do |
104 | } |
105 | 4 { # modifies (increments) an attribute value if it is already exists on this label |
106 | set value [Get$attrName D $label] |
107 | Set$attrName D $label [expr $value+1] |
108 | } |
109 | 5 { # modifies and immediately forgets an attribute |
110 | set value [Get$attrName D $label] |
111 | Set$attrName D $label [expr $value+1] |
112 | if $attr==0 { # forget integer |
113 | ForgetAtt D $label 2a96b606-ec8b-11d0-bee7-080009dc3333 |
114 | } else { # forget real |
115 | ForgetAtt D $label 2a96b60f-ec8b-11d0-bee7-080009dc3333 |
116 | } |
117 | } |
118 | 6 { # forgets the attribute |
119 | if $attr==0 { # forget integer |
120 | ForgetAtt D $label 2a96b606-ec8b-11d0-bee7-080009dc3333 |
121 | } else { # forget real |
122 | ForgetAtt D $label 2a96b60f-ec8b-11d0-bee7-080009dc3333 |
123 | } |
124 | } |
125 | 7 { # forgets and immediately creates an attribute |
126 | if $attr==0 { # forget integer |
127 | ForgetAtt D $label 2a96b606-ec8b-11d0-bee7-080009dc3333 |
128 | } else { # forget real |
129 | ForgetAtt D $label 2a96b60f-ec8b-11d0-bee7-080009dc3333 |
130 | } |
131 | Set$attrName D $label 1 |
132 | } |
133 | } |
134 | } |
135 | |
136 | proc check_attribute {action1 action2 lab attr} { |
137 | global D |
138 | set attrName [attribute_name $attr] |
139 | if [produces_attribute2 $action1 $action2] { |
140 | set value [Get$attrName D $lab] |
141 | set expected_value [produces_value $action1 $action2] |
142 | if $value!=$expected_value { |
143 | puts "Error : attribute $attrName value $value does not match the expected $expected_value at the label $lab" |
144 | } |
145 | } else { |
146 | set attributes [Attributes D $lab] |
147 | if {[lsearch $attributes TDataStd_$attrName]>=0} { |
148 | puts "Error : attribute $attrName exists but it should not at the label $lab" |
149 | } |
150 | } |
151 | } |
152 | |
153 | # special check for attributes if transaction->no transaction is performed and |
154 | # Undo->Redo done: modified attributes become modified, but removed attributes in the no-transaction |
155 | # do not removed after Redo |
156 | proc check_attribute_notransaction {action1 action_notr lab attr} { |
157 | global D |
158 | set attrName [attribute_name $attr] |
159 | if [produces_attribute2 $action1 $action_notr] { |
160 | set value [Get$attrName D $lab] |
161 | set expected_value [produces_value $action1 $action_notr] |
162 | if $value!=$expected_value { |
163 | puts "Error : attribute $attrName value $value does not match the expected $expected_value at the label $lab" |
164 | } |
165 | } else { |
166 | if [produces_attribute1 $action_notr]==0 { |
167 | set attributes [Attributes D $lab] |
168 | if {[lsearch $attributes TDataStd_$attrName]>=0} { |
169 | puts "Error : attribute $attrName exists but it should not at the label $lab" |
170 | } |
171 | } |
172 | } |
173 | } |
174 | |
175 | |
176 | set lab_index 1 |
177 | set num_variants 0 |
178 | # cycles by variables t<operation number>a<attribute number> = action id |
179 | for {set t1a1 0} {$t1a1 < $act_afternone} {incr t1a1} { |
180 | for {set t1a2 0} {$t1a2 < $act_afternone} {incr t1a2} { |
181 | set t2a1_min 0 |
182 | set t2a1_max $actions |
183 | if [produces_attribute1 $t1a1] {set t2a1_min $act_none} {set t2a1_max $act_afternone} |
184 | for {set t2a1 $t2a1_min} {$t2a1 < $t2a1_max} {incr t2a1} { |
185 | set t2a2_min 0 |
186 | set t2a2_max $actions |
187 | if [produces_attribute1 $t1a2] {set t2a2_min $act_none} {set t2a2_max $act_afternone} |
188 | for {set t2a2 $t2a2_min} {$t2a2 < $t2a2_max} {incr t2a2} { |
189 | set lab [Label D 0:$lab_index] |
190 | ForgetAll D $lab |
191 | incr lab_index |
192 | incr num_variants |
193 | # for the first operation no transaction opened and closed |
194 | do_action $lab 0 $t1a1 |
195 | do_action $lab 1 $t1a2 |
196 | # after do operation in transaction |
197 | NewCommand D |
198 | do_action $lab 0 $t2a1 |
199 | do_action $lab 1 $t2a2 |
200 | CommitCommand D |
201 | # check all attributes are correctly located in the tree |
202 | check_attribute $t1a1 $t2a1 $lab 0 |
203 | check_attribute $t1a2 $t2a2 $lab 1 |
204 | # check attributes state after undo and then - redo (but if all actions are None, there is no transaction, don't do it) |
205 | if {[expr $t2a1!=$act_none && $t2a1!=$act_createforget] || [expr $t2a2!=$act_none && $t2a2!=$act_createforget]} { |
206 | Undo D |
207 | check_attribute $act_none $t1a1 $lab 0 |
208 | check_attribute $act_none $t1a2 $lab 1 |
209 | Redo D |
210 | check_attribute $t1a1 $t2a1 $lab 0 |
211 | check_attribute $t1a2 $t2a2 $lab 1 |
212 | } |
213 | } |
214 | } |
215 | } |
216 | } |
217 | puts "Checked $num_variants variants in cycles no transaction->transaction" |
218 | |
219 | set num_variants 0 |
220 | # cycles by variables t<operation number>a<attribute number> = action id |
221 | for {set t1a1 0} {$t1a1 < $act_afternone} {incr t1a1} { |
222 | for {set t1a2 0} {$t1a2 < $act_afternone} {incr t1a2} { |
223 | set t2a1_min 0 |
224 | set t2a1_max $actions |
225 | if [produces_attribute1 $t1a1] {set t2a1_min $act_none} {set t2a1_max $act_afternone} |
226 | for {set t2a1 $t2a1_min} {$t2a1 < $t2a1_max} {incr t2a1} { |
227 | set t2a2_min 0 |
228 | set t2a2_max $actions |
229 | if [produces_attribute1 $t1a2] {set t2a2_min $act_none} {set t2a2_max $act_afternone} |
230 | for {set t2a2 $t2a2_min} {$t2a2 < $t2a2_max} {incr t2a2} { |
231 | set lab [Label D 0:$lab_index] |
232 | incr lab_index |
233 | incr num_variants |
234 | # for the first operation open transaction |
235 | NewCommand D |
236 | do_action $lab 0 $t1a1 |
237 | do_action $lab 1 $t1a2 |
238 | CommitCommand D |
239 | # then no transaction is opened |
240 | do_action $lab 0 $t2a1 |
241 | do_action $lab 1 $t2a2 |
242 | # check all attributes are correctly located in the tree |
243 | check_attribute $t1a1 $t2a1 $lab 0 |
244 | check_attribute $t1a2 $t2a2 $lab 1 |
245 | # check attributes state after undo and then - redo (but if all actions are None, there is no transaction, don't do it) |
246 | if {[expr $t2a1!=$act_none && $t2a1!=$act_createforget] || [expr $t2a2!=$act_none && $t2a2!=$act_createforget]} { |
247 | Undo D |
248 | if {$t1a1 == $act_createforget || $t1a1 == $act_none} { |
249 | set first_tr $t1a1 |
250 | } else { |
251 | set first_tr $act_undone |
252 | } |
253 | check_attribute $first_tr $t2a1 $lab 0 |
254 | if {$t1a2 == $act_createforget || $t1a2 == $act_none} { |
255 | set first_tr $t1a2 |
256 | } else { |
257 | set first_tr $act_undone |
258 | } |
259 | check_attribute $first_tr $t2a2 $lab 1 |
260 | Redo D |
261 | check_attribute_notransaction $t1a1 $t2a1 $lab 0 |
262 | check_attribute_notransaction $t1a2 $t2a2 $lab 1 |
263 | } |
264 | } |
265 | } |
266 | } |
267 | } |
268 | puts "Checked $num_variants variants in cycles transaction->no transaction" |