0030969: Coding Rules - refactor Quantity_Color.cxx color table definition
[occt.git] / tests / caf / bugs / D2
CommitLineData
45d8465e 1puts "==========="
2puts "0027241: Create a complete test case to verify reading of all attribute types from MDTV-Standard document"
3puts "==========="
4puts ""
5
6# Set Create_Doc to 1 to generate the document (using OCCT 6.9.1 or earlier)
7set Create_Doc 0
8
9set test_file_name bug27241_ocaf_all_attributes.std
10
11set test_name "OCC26961"
12set test_int 123
13set test_real 123.456e-7
14set test_int_arr {10 20}
15set test_real_arr {1.1 3.14 5.4e18}
16set test_extstr_arr {"sample string 1" "string 2"}
17set test_bool_arr {0 1}
18set test_ref_arr {"0:1:2:3:2" "0:1:2:3:1"}
19set test_byte_arr {15 25}
20set test_map {1 5 2 10}
21set test_map_sorted {1 2 5 10}
22set test_named_ints {i1 1 i2 2}
23set test_named_reals {r1 1.1 r2 2.2}
24set test_named_strings {s1 string1 s2 string2}
25set test_named_bytes {b1 65 b2 66}
26set test_ref "0:1:1"
27set test_guid "00000000-0000-0000-2222-000000000000"
28set test_comment "Sample document containing various attributes"
29set test_string "Sample string"
30set test_expr "2*pi*r"
31set test_var1 "0:1:2:3:2"
32set test_var2 "0:1:2:3:1"
33set test_point "111 222 333"
34set test_axisPos "10 10 30"
35set test_axisDir "11 22 33"
36set test_plane "15 25 35"
37set test_boxXYZ "10 20 30"
38set test_boxDX 100
39set test_boxDY 200
40set test_boxDZ 300
41set test_geom_t "cir"
42set test_failure 1
43set test_driver "G"
44set test_driver_id "2a96b604-ec8b-11d0-bee7-080009dc3333"
45set test_transp 0.5
aaf8d6a9 46set test_color AQUAMARINE4
45d8465e 47set test_material 22
48set test_positionX 100
49set test_positionY 200
50set test_positionZ 300
51
52proc checkarray {name array expected} {
53 set exp_len [llength $expected]
54 if {$exp_len != [llength $array]} {puts "Error: invalid $name"; return}
55 for {set i 0} {$i < $exp_len} {incr i} {
56 if {[lindex $array $i] != [lindex $expected $i]} {puts "Error: invalid $name"}
57 }
58}
59
60pload TOPTEST
61
62catch {Close D}
63
64# Normal test execution
65if !$Create_Doc {
66
67 # Load document
68 Open [locate_data_file $test_file_name] D
69
70
71 # Simple values
72 if [catch {GetInteger D 0:1:1 i}] {puts "Error: Integer not found"
73 } elseif {[dval i] != $test_int} {puts "Error: invalid Integer"}
74
75 if [catch {GetReal D 0:1:1 r}] {puts "Error: Real not found"
76 } elseif {[dval r] != $test_real} {puts "Error: invalid Real"}
77
78 if [catch {set name [GetName D 0:1:1]}] {puts "Error: Name not found"
79 } elseif {$name != $test_name} {puts "Error: invalid Name"}
80
81 if [catch {set comment [GetComment D 0:1:1]}] {puts "Error: Comment not found"
82 } elseif {$comment != $test_comment} {puts "Error: invalid Comment"}
83
84 if [catch {set string [GetAsciiString D 0:1:1]}] {puts "Error: AsciiString not found"}
85
86
87 # TagSource
88 if [catch {NewTag D 0:1:2}] {puts "Error: TagSource not found"}
89
90
91 # Reference
92 if [catch {set ref [GetReference D 0:1:3]}] {puts "Error: Reference not found"
93 } elseif {[string compare $ref $test_ref] != 0} {puts "Error: invalid Reference"}
94
95
96 # Directory
97 if [catch {AddDirectory D 0:1:2:1}] {puts "Error: Directory not found"}
98
99
100 # UAttribute
101 if [catch {set guid [GetUAttribute D 0:1:2:2 $test_guid]}] {puts "Error: no label for UAttribute"
102 } elseif {$guid == "No UAttribute Attribute on label"} {puts "Error: $guid"
103 } elseif {$guid != $test_guid} {puts "Error: invalid UAttribute"}
104
105
106 # Variable
107 if [regexp "no such attribute" [GetVariable D $test_var2 is_const units]] {puts "Error: Variable not found"
108 } elseif {$is_const != 0 || $units != "mm"} {puts "Error: invalid Variable"}
109
110
111 # Relation
112 if [catch {set rel_dump [DumpRelation D 0:1:2:3]}] {puts "Error: Relation not found"
113 } elseif ![regexp "$test_expr.*$test_var1 $test_var2" $rel_dump] {
114 puts "Error: invalid Relation"}
115
116
117 # TreeNode
118 if [catch {set root_node [RootNode D 0:1:2:4]}] {puts "Error: TreeNode not found"
119 } elseif {$root_node != "0:1:2:4"} {puts "Error: invalid TreeNode"}
120
121
122 # Arrays
123 if [catch {set iarr [GetIntArray D 0:1:1]}] {puts "Error: IntegerArray not found"
124 } else { checkarray "IntegerArray" $iarr $test_int_arr }
125
126 if [catch {set rarr [GetRealArray D 0:1:1]}] {puts "Error: RealArray not found"
127 } else { checkarray "RealArray" $rarr $test_real_arr }
128
129 if [catch {set esarr [GetExtStringArray D 0:1:1]}] {puts "Error: ExtStringArray not found"
130 } else { checkarray "ExtStringArray" $esarr [join $test_extstr_arr " "]}
131
132 if [catch {set boolarr [GetBooleanArray D 0:1:1]}] {puts "Error: BooleanArray not found"
133 } else { checkarray "BooleanArray" $boolarr $test_bool_arr }
134
135 if [catch {set refarr [GetRefArray D 0:1:1]}] {puts "Error: ReferenceArray not found"
136 } else { checkarray "ReferenceArray" $refarr $test_ref_arr }
137
138 if [catch {set bytearr [GetByteArray D 0:1:1]}] {puts "Error: ByteArray not found"
139 } else { checkarray "ByteArray" $bytearr $test_byte_arr }
140
141
142 # Lists
143 if [catch {set ilst [GetIntegerList D 0:1:1]}] {puts "Error: IntegerList not found"
144 } else { checkarray "IntegerList" $ilst $test_int_arr }
145
146 if [catch {set rlst [GetRealList D 0:1:1]}] {puts "Error: RealList not found"
147 } else { checkarray "RealList" $rlst $test_real_arr }
148
149 if [catch {set eslst [GetExtStringList D 0:1:1]}] {puts "Error: ExtStringList not found"
150 } else { checkarray "ExtStringList" $eslst [join $test_extstr_arr " "]}
151
152 if [catch {set blst [GetBooleanList D 0:1:1]}] {puts "Error: BooleanList not found"
153 } else { checkarray "BooleanList" $blst $test_bool_arr }
154
155 if [catch {set reflst [GetReferenceList D 0:1:1]}] {puts "Error: ReferenceList not found"
156 } else { checkarray "ReferenceList" $reflst $test_ref_arr }
157
158
159 # IntPackedMap
160 if [catch {set map [GetIntPackedMap D 0:1:1]}] {puts "Error: IntPackedMap not found"
161 } else { checkarray "IntPackedMap" $map $test_map_sorted }
162
163
164 # NamedData
165 if [catch {GetNDIntegers D 0:1:4}] {puts "Error: NamedData not found"}
166 if [catch {GetNDReals D 0:1:4}] {puts "Error: NamedData not found"}
167 if [catch {GetNDStrings D 0:1:4}] {puts "Error: NamedData not found"}
168 if [catch {GetNDBytes D 0:1:4}] {puts "Error: NamedData not found"}
169 if [catch {GetNDIntArrays D 0:1:4}] {puts "Error: NamedData not found"}
170 if [catch {GetNDRealArrays D 0:1:4}] {puts "Error: NamedData not found"}
171
172
173 # NamedShape
174 eval box Box $test_boxXYZ $test_boxDX $test_boxDY $test_boxDZ
175 if [catch {GetShape D 0:1:6 b}] {puts "Error: NamedShape not found"
1f26f80b 176 } elseif {[bounding b -dump] != [bounding Box -dump]} {puts "Error: invalid NamedShape"
45d8465e 177 } else {
178 checkshape b
179 checkprops b -l [expr $test_boxDX * 8 + $test_boxDY * 8 + $test_boxDZ * 8]
180 checkprops b -s [expr $test_boxDX * $test_boxDY * 2 + $test_boxDY * $test_boxDZ * 2 + $test_boxDX * $test_boxDZ * 2]
181 checkprops b -v [expr $test_boxDX * $test_boxDY * $test_boxDZ]
182 }
183
184
185 # Point, Axis, Plane
186 if [catch {GetPoint D 0:1:5:1 pnt}] {puts "Error: Point not found"}
187 if [catch {GetAxis D 0:1:5:2 axs}] {puts "Error: Axis not found"}
188 if [catch {GetPlane D 0:1:5:3 pln}] {puts "Error: Plane not found"}
189
190
191 # Geometry
192 if [catch {set geom_t [GetGeometryType D 0:1:6]}] {puts "Error: Geometry not found"
193 } elseif {$geom_t != $test_geom_t} { puts "Error: invalid Geometry" }
194
195
196 # Constraint
197 if [catch {set constraint [GetConstraint D 0:1:1]}] {puts "Error: Constraint not found"
198 } elseif {$constraint != "0:1:1 COINCIDENT G_1 (0:1:6) "} { puts "Error: invalid Constraint" }
199
200
201 # PatternStd
202 if [catch {set pattern [DumpPattern D 0:1:1]}] {puts "Error: PatternStd not found"
203 } elseif {$pattern != "0:1:1 signature = 5 Mirror (0:1:6)"} { puts "Error: invalid PatternStd" }
204
205
206 # Function
0e443e13 207 if [catch {GetFunction D 0:1:1 fguid failureNb}] {puts "Error: Function not found"
208 } elseif {$fguid != $test_guid || $failureNb != $test_failure} { puts "Error: invalid Function" }
45d8465e 209
210
211 # AISPresentation
212 AISInitViewer D
213 if [catch {set driver [AISDriver D 0:1:1]}] {puts "Error: AISPresentation not found"
214 } elseif [catch {set transp [AISTransparency D 0:1:1]}] {puts "Error: AISPresentation not found"
215 } elseif [catch {set color [AISColor D 0:1:1]}] {puts "Error: AISPresentation not found"
216 } elseif [catch {set material [AISMaterial D 0:1:1]}] {puts "Error: AISPresentation not found"
217 } elseif {$driver != $test_driver_id} { puts "Error: invalid AISPresentation"
218 } elseif {[lindex [split $transp "\n"] 1] != $test_transp} { puts "Error: invalid AISPresentation"
219 } elseif {[lindex [split $color "\n"] 1] != $test_color} { puts "Error: invalid AISPresentation"
220 } elseif {[lindex [split $material "\n"] 1] != $test_material} { puts "Error: invalid AISPresentation" }
221
222
223 # Position
224 if [catch {GetPosition D 0:1:1 posX posY posZ}] {puts "Error: Position not found"
225 } elseif {$posX != $test_positionX} { puts "Error: invalid Position"
226 } elseif {$posY != $test_positionY} { puts "Error: invalid Position"
227 } elseif {$posZ != $test_positionZ} { puts "Error: invalid Position" }
228
229} else {
230
231 # Creation of the document to be used in normal execution.
232 # Note! This will work only on OCCT versions older than 7.0,
233 # as since 7.0 there is no more storage driver for old persistence.
234
235 puts "Creating document"
236 NewDocument D MDTV-Standard
237
238 # Simple values
239 SetInteger D 0:1:1 $test_int
240 SetReal D 0:1:1 $test_real
241 SetName D 0:1:1 $test_name
242 SetComment D 0:1:1 $test_comment
243 SetAsciiString D 0:1:1 $test_string
244
245 # TagSource
246 SetTagger D 0:1:2
247
248 # Reference
249 SetReference D 0:1:3 $test_ref
250
251 # Directory
252 NewDirectory D 0:1:2:1
253
254 # UAttribute
255 SetUAttribute D 0:1:2:2 $test_guid
256
257 # Variable
258 SetVariable D $test_var2 0 mm
259 SetVariable D $test_var1 1 ""
260
261 # Relation
262 SetRelation D 0:1:2:3 "2*pi*r" $test_var1 $test_var2
263
264 # TreeNode
265 SetNode D 0:1:2:4
266
267 # Arrays
268 eval SetIntArray D 0:1:1 1 1 2 $test_int_arr
269 eval SetRealArray D 0:1:1 1 1 3 $test_real_arr
270 eval SetExtStringArray D 0:1:1 1 1 2 $test_extstr_arr
271 eval SetBooleanArray D 0:1:1 1 1 2 $test_bool_arr
272 eval SetRefArray D 0:1:1 1 2 $test_ref_arr
273 eval SetByteArray D 0:1:1 1 1 2 $test_byte_arr
274
275 # Lists
276 eval SetIntegerList D 0:1:1 $test_int_arr
277 eval SetRealList D 0:1:1 $test_real_arr
278 eval SetExtStringList D 0:1:1 $test_extstr_arr
279 eval SetBooleanList D 0:1:1 $test_bool_arr
280 eval SetReferenceList D 0:1:1 $test_ref_arr
281
282 # IntPackedMap
283 eval SetIntPackedMap D 0:1:1 1 $test_map
284
285 # NamedData
286 eval SetNDataIntegers D 0:1:4 2 $test_named_ints
287 eval SetNDataReals D 0:1:4 2 $test_named_reals
288 eval SetNDataStrings D 0:1:4 2 $test_named_strings
289 eval SetNDataBytes D 0:1:4 2 $test_named_bytes
290 eval SetNDataIntArrays D 0:1:4 ia 2 $test_int_arr
291 eval SetNDataRealArrays D 0:1:4 ra 3 $test_real_arr
292
293 # NamedShape
294 eval box Box $test_boxXYZ $test_boxDX $test_boxDY $test_boxDZ
295 SetShape D 0:1:6 Box
296
297 # Point
298 eval point Point $test_point
299 SetPoint D 0:1:5:1 Point
300
301 # Axis
302 eval line Axis $test_axisPos $test_axisDir
303 SetAxis D 0:1:5:2 Axis
304
305 # Plane
306 eval plane Plane $test_plane
307 SetPlane D 0:1:5:3 Plane
308
309 # Geometry
310 SetGeometry D 0:1:6 $test_geom_t
311
312 # Constraint
313 SetConstraint D 0:1:1 equal 0:1:6
314
315 # PatternStd
316 SetPattern D 0:1:1 5 0:1:6
317
318 # Function
319 SetFunction D 0:1:1 $test_guid $test_failure
320
321 # AISPresentation
322 AISInitViewer D
323 AISSet D 0:1:1 $test_driver
324 AISTransparency D 0:1:1 $test_transp
325 AISColor D 0:1:1 $test_color
326 AISMaterial D 0:1:1 $test_material
327
328 # Position
329 SetPosition D 0:1:1 $test_positionX $test_positionY $test_positionZ
330
331 SaveAs D $imagedir/ocaf_all_attributes.std
332 puts "Document saved to $imagedir/$test_file_name"
333}