2 if { [array get Draw_Groups "TOPOLOGY Check commands"] == "" } {
5 # set env(CSF_DrawPluginQADefaults) $env(CASROOT)/src/DrawResources/.
7 # pload -DrawPluginQA QAcommands
10 # to prevent loops limit to 16 minutes
13 # On Windows with VC, in typical configuration gl2ps is built with Release
14 # mode only which will fail in Debug mode; add TODO for that case in order
15 # to handle it once for all tests that can use vexport command
16 if { [regexp {Debug mode} [dversion]] } {
17 puts "TODO ?#23540 windows: Error: export of image.*failed"
18 puts "TODO ?#23540 windows: Error: The file has been exported.*different size \[(\]0 "
21 if { [info exists imagedir] == 0 } {
24 if { [info exists test_image] == 0 } {
28 # Procedure to check equality of two reals with tolerance (relative and absolute)
29 help checkreal {name value expected tol_abs tol_rel}
30 proc checkreal {name value expected tol_abs tol_rel} {
31 if { abs ($value - $expected) > $tol_abs + $tol_rel * abs ($expected) } {
32 puts "Error: $name = $value is not equal to expected $expected"
34 puts "Check of $name OK: value = $value, expected = $expected"
39 # Procedure to check equality of two reals with tolerance (relative and absolute)
40 help checkarea {shape area_expected tol_abs tol_rel}
41 proc checkarea {shape area_expected tol_abs tol_rel} {
42 # compute area with half of the relative tolerance
43 # to be used in comparison; 0.001 is added to avoid zero value
44 set prop [uplevel sprops $shape [expr 0.5 * abs($tol_rel) + 0.001]]
47 if { ! [regexp {Mass\s*:\s*([0-9.e+-]+)} $prop res area] } {
48 puts "Error: cannot get area of the shape $shape"
52 # compare with expected value
53 checkreal "area of $shape" $area $area_expected $tol_abs $tol_rel
56 # Procedure to check color in the point near default coordinate
58 proc checkpoint {coord_x coord_y rd_ch gr_ch bl_ch} {
59 set x_start [expr ${coord_x} - 2]
60 set y_start [expr ${coord_y} - 2]
63 while { $mistake != 1 && $i <= 5 } {
65 while { $mistake != 1 && $j <= 5 } {
66 set position_x [expr ${x_start} + $j]
67 set position_y [expr ${y_start} + $i]
71 if { [info exists color2d] } {
72 set color [ QAAISGetPixelColor2d ${position_x} ${position_y} ]
74 set color [ QAGetPixelColor ${position_x} ${position_y} ]
76 regexp {RED +: +([-0-9.+eE]+)} $color full rd
77 regexp {GREEN +: +([-0-9.+eE]+)} $color full gr
78 regexp {BLUE +: +([-0-9.+eE]+)} $color full bl
79 set rd_int [expr int($rd * 1.e+05)]
80 set gr_int [expr int($gr * 1.e+05)]
81 set bl_int [expr int($bl * 1.e+05)]
84 set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch]
89 set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch]
94 set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch]
99 if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } {
100 puts "Warning : Point with true color was not found near default coordinates"
112 # Procedure to check color using command QAgetPixelColor with tolerance
113 proc checkcolor { coord_x coord_y rd_get gr_get bl_get } {
114 puts "Coordinate x = $coord_x"
115 puts "Coordinate y = $coord_y"
116 puts "RED color of RGB is $rd_get"
117 puts "GREEN color of RGB is $gr_get"
118 puts "BLUE color of RGB is $bl_get"
120 if { $coord_x <= 1 || $coord_y <= 1 } {
121 puts "Error : minimal coordinate is x = 2, y = 2. But we have x = $coord_x y = $coord_y"
125 if { [info exists color2d] } {
126 set color [ QAAISGetPixelColor2d ${coord_x} ${coord_y} ]
128 set color [ QAGetPixelColor ${coord_x} ${coord_y} ]
131 regexp {RED +: +([-0-9.+eE]+)} $color full rd
132 regexp {GREEN +: +([-0-9.+eE]+)} $color full gr
133 regexp {BLUE +: +([-0-9.+eE]+)} $color full bl
134 set rd_int [expr int($rd * 1.e+05)]
135 set gr_int [expr int($gr * 1.e+05)]
136 set bl_int [expr int($bl * 1.e+05)]
137 set rd_ch [expr int($rd_get * 1.e+05)]
138 set gr_ch [expr int($gr_get * 1.e+05)]
139 set bl_ch [expr int($bl_get * 1.e+05)]
142 set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch]
147 set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch]
152 set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch]
157 if { $tol_rd > 0.2 } {
158 puts "Warning : RED light of additive color model RGB is invalid"
161 if { $tol_gr > 0.2 } {
162 puts "Warning : GREEN light of additive color model RGB is invalid"
165 if { $tol_bl > 0.2 } {
166 puts "Warning : BLUE light of additive color model RGB is invalid"
170 if { $status != 0 } {
171 puts "Warning : Colors of default coordinate are not equal"
175 if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } {
176 set info [checkpoint $coord_x $coord_y $rd_ch $gr_ch $bl_ch]
177 set stat [lindex $info end]
178 if { ${stat} != 1 } {
179 puts "Error : Colors are not equal in default coordinate and in the near coordinates too"
182 puts "Point with valid color was found"
191 # Procedure to check if sequence of values in listval follows linear trend
192 # adding the same delta on each step.
194 # The function does statistical estimation of the mean variation of the
195 # values of the sequence, and dispersion, and returns true only if both
196 # dispersion and deviation of the mean from expected delta are within
197 # specified tolerance.
199 # If mean variation differs from expected delta on more than two dispersions,
200 # the check fails and procedure raises error with specified message.
202 # Otherwise the procedure returns false meaning that more iterations are needed.
203 # Note that false is returned in any case if length of listval is less than 3.
205 # See example of use to check memory leaks in bugs/caf/bug23489
207 proc checktrend {listval delta tolerance message} {
208 set nbval [llength $listval]
213 # calculate mean value
215 set prev [lindex $listval 0]
216 foreach val [lrange $listval 1 end] {
217 set mean [expr $mean + ($val - $prev)]
220 set mean [expr $mean / ($nbval - 1)]
222 # calculate dispersion
224 set prev [lindex $listval 0]
225 foreach val [lrange $listval 1 end] {
226 set d [expr ($val - $prev) - $mean]
227 set sigma [expr $sigma + $d * $d]
230 set sigma [expr sqrt ($sigma / ($nbval - 2))]
232 puts "Checking trend: nb = $nbval, mean delta = $mean, sigma = $sigma"
234 # check if deviation is definitely too big
235 if { abs ($mean - $delta) > $tolerance + 2. * $sigma } {
236 puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta"
240 # check if deviation is clearly within a range
241 return [expr abs ($mean - $delta) <= $sigma && $sigma <= $tolerance]
244 # Check if area of triangles is valid
245 proc CheckTriArea {shape {eps 0}} {
246 upvar #0 $shape result
247 set area [triarea result $eps]
248 set t_area [lindex $area 0]
249 set g_area [expr abs([lindex $area 1])]
250 puts "area by triangles: $t_area"
251 puts "area by geometry: $g_area"
252 expr ($t_area - $g_area) / $g_area * 100
255 # Check if list of xdistcs-command is valid
256 proc checkList {List Tolerance D_good Limit_Tol} {
257 set L1 [llength ${List}]
260 set N [expr (${L1} - ${L2})/${L3} + 1]
262 for {set i 1} {${i} <= ${N}} {incr i} {
263 set j1 [expr ${L2} + (${i}-1)*${L3}]
264 set j2 [expr ${j1} + 2]
265 set T [lindex ${List} ${j1}]
266 set D [lindex ${List} ${j2}]
267 #puts "i=${i} j1=${j1} j2=${j2} T=${T} D=${D}"
268 if { [expr abs(${D} - ${D_good})] > ${Tolerance} } {
269 puts "Error : T=${T} D=${D}"
272 if { ${Tolerance} > ${Limit_Tol} } {
273 if { [expr abs(${D} - ${D_good})] > ${Limit_Tol}
274 && [expr abs(${D} - ${D_good})] <= ${Tolerance} } {
275 puts "Attention (critical value of tolerance) : T=${T} D=${D}"
281 # Procedure to check result of nbshapes command
282 proc checknbshapes { res nbshapes_expected_s count_locations message} {
285 if { ${count_locations} == 0 } {
286 set nb_info [nbshapes shape]
288 set nb_info [nbshapes shape -t]
291 set EntityList {VERTEX EDGE WIRE FACE SHELL SOLID COMPSOLID COMPOUND SHAPE}
293 foreach Entity ${EntityList} {
294 set expr_string "${Entity} +: +(\[-0-9.+eE\]+)"
295 if { [regexp "${expr_string}" ${nbshapes_expected_s} full nb_entity1] > 0 } {
296 if { [regexp "${expr_string}" ${nb_info} full nb_entity2] > 0 } {
297 if { ${nb_entity2} != ${nb_entity1} } {
298 puts "Error : ${message} is WRONG because number of ${Entity} entities is ${nb_entity2} while ${nb_entity1} is expected"
300 puts "OK : ${message} is GOOD because number of ${Entity} entities is equal to number of expected ${Entity} entities"