1 # Copyright (c) 2013-2014 OPEN CASCADE SAS
3 # This file is part of Open CASCADE Technology software library.
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License version 2.1 as published
7 # by the Free Software Foundation, with special exception defined in the file
8 # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 # distribution for complete text of the license and disclaimer of any warranty.
11 # Alternatively, this file may be used under the terms of Open CASCADE
12 # commercial license or contractual agreement.
14 ############################################################################
15 # This file defines scripts for verification of OCCT tests.
16 # It provides top-level commands starting with 'check'.
17 # Type 'help check*' to get their synopsys.
18 # See OCCT Tests User Guide for description of the test system.
20 # Note: procedures with names starting with underscore are for internal use
21 # inside the test system.
22 ############################################################################
26 Use: checkcolor x y red green blue
27 x y - pixel coordinates
28 red green blue - expected pixel color (values from 0 to 1)
29 Function check color with tolerance (5x5 area)
31 # Procedure to check color using command vreadpixel with tolerance
32 proc checkcolor { coord_x coord_y rd_get gr_get bl_get } {
33 puts "Coordinate x = $coord_x"
34 puts "Coordinate y = $coord_y"
35 puts "RED color of RGB is $rd_get"
36 puts "GREEN color of RGB is $gr_get"
37 puts "BLUE color of RGB is $bl_get"
39 if { $coord_x <= 1 || $coord_y <= 1 } {
40 puts "Error : minimal coordinate is x = 2, y = 2. But we have x = $coord_x y = $coord_y"
45 catch { [set color "[vreadpixel ${coord_x} ${coord_y} rgb]"] }
47 puts "Error : Pixel coordinates (${position_x}; ${position_y}) are out of view"
49 set rd [lindex $color 0]
50 set gr [lindex $color 1]
51 set bl [lindex $color 2]
52 set rd_int [expr int($rd * 1.e+05)]
53 set gr_int [expr int($gr * 1.e+05)]
54 set bl_int [expr int($bl * 1.e+05)]
55 set rd_ch [expr int($rd_get * 1.e+05)]
56 set gr_ch [expr int($gr_get * 1.e+05)]
57 set bl_ch [expr int($bl_get * 1.e+05)]
60 set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch]
65 set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch]
70 set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch]
76 if { $tol_rd > 0.2 } {
77 puts "Warning : RED light of additive color model RGB is invalid"
80 if { $tol_gr > 0.2 } {
81 puts "Warning : GREEN light of additive color model RGB is invalid"
84 if { $tol_bl > 0.2 } {
85 puts "Warning : BLUE light of additive color model RGB is invalid"
90 puts "Warning : Colors of default coordinate are not equal"
94 if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } {
95 set info [_checkpoint $coord_x $coord_y $rd_ch $gr_ch $bl_ch]
96 set stat [lindex $info end]
98 puts "Error : Colors are not equal in default coordinate and in the near coordinates too"
101 puts "Point with valid color was found"
109 # Procedure to check color in the point near default coordinate
110 proc _checkpoint {coord_x coord_y rd_ch gr_ch bl_ch} {
111 set x_start [expr ${coord_x} - 2]
112 set y_start [expr ${coord_y} - 2]
115 while { $mistake != 1 && $i <= 5 } {
117 while { $mistake != 1 && $j <= 5 } {
118 set position_x [expr ${x_start} + $j]
119 set position_y [expr ${y_start} + $i]
124 catch { [set color "[vreadpixel ${position_x} ${position_y} rgb]"] }
125 if {"$color" == ""} {
126 puts "Warning : Pixel coordinates (${position_x}; ${position_y}) are out of view"
130 set rd [lindex $color 0]
131 set gr [lindex $color 1]
132 set bl [lindex $color 2]
133 set rd_int [expr int($rd * 1.e+05)]
134 set gr_int [expr int($gr * 1.e+05)]
135 set bl_int [expr int($bl * 1.e+05)]
138 set tol_rd [expr abs($rd_ch - $rd_int)/$rd_ch]
143 set tol_gr [expr abs($gr_ch - $gr_int)/$gr_ch]
148 set tol_bl [expr abs($bl_ch - $bl_int)/$bl_ch]
153 if { $tol_rd > 0.2 || $tol_gr > 0.2 || $tol_bl > 0.2 } {
154 puts "Warning : Point with true color was not found near default coordinates"
166 # auxiliary: check argument
167 proc _check_arg {check_name check_result {get_value 0}} {
168 upvar ${check_result} ${check_result}
172 if { $arg == ${check_name} } {
175 if { $narg < [llength $args] && ! [regexp {^-} [lindex $args $narg]] } {
176 set ${check_result} "[lindex $args $narg]"
178 error "Option ${check_result} requires argument"
181 set ${check_result} 1
189 Compare number of sub-shapes in "shape" with given reference data
191 Use: checknbshapes shape [options...]
202 -t: compare the number of sub-shapes in "shape" counting
203 the same sub-shapes with different location as different sub-shapes.
204 -m msg: print "msg" in case of error
205 -ref [nbshapes a]: compare the number of sub-shapes in "shape" and in "a".
206 -vertex N, -edge N and other options are stil working.
208 proc checknbshapes {shape args} {
209 puts "checknbshapes ${shape} ${args}"
210 upvar ${shape} ${shape}
223 set count_locations 0
226 for {set narg 0} {$narg < [llength $args]} {incr narg} {
227 set arg [lindex $args $narg]
228 if {[_check_arg "-vertex" nbVERTEX 1] ||
229 [_check_arg "-edge" nbEDGE 1] ||
230 [_check_arg "-wire" nbWIRE 1] ||
231 [_check_arg "-face" nbFACE 1] ||
232 [_check_arg "-shell" nbSHELL 1] ||
233 [_check_arg "-solid" nbSOLID 1] ||
234 [_check_arg "-compsolid" nbCOMPSOLID 1] ||
235 [_check_arg "-compound" nbCOMPOUND 1] ||
236 [_check_arg "-shape" nbSHAPE 1] ||
237 [_check_arg "-t" count_locations] ||
238 [_check_arg "-m" message 1] ||
239 [_check_arg "-ref" ref_info 1]
244 if { [regexp {^-} $arg] } {
245 error "Error: unsupported option \"$arg\""
247 error "Error: cannot interpret argument $narg ($arg)"
250 if { ${count_locations} == 0 } {
251 set nb_info [nbshapes ${shape}]
253 set nb_info [nbshapes ${shape} -t]
256 set EntityList {VERTEX EDGE WIRE FACE SHELL SOLID COMPSOLID COMPOUND SHAPE}
258 foreach Entity ${EntityList} {
259 set expr_string "${Entity} +: +(\[-0-9.+eE\]+)"
261 # get number of elements from ${shape}
262 if { [regexp "${expr_string}" ${nb_info} full nb_entity2] } {
263 lappend to_compare ${nb_entity2}
265 error "Error : command \"nbshapes ${shape}\" gives an empty result"
267 # get number of elements from options -vertex -edge and so on
268 set nb_entity1 [set nb${Entity}]
269 if { ${nb_entity1} != -1 } {
270 lappend to_compare ${nb_entity1}
272 # get number of elements from option -ref
273 if { [regexp "${expr_string}" ${ref_info} full nb_entity_ref] } {
274 lappend to_compare ${nb_entity_ref}
276 # skip comparing if no reference data was given
277 if {[llength $to_compare] == 1} {
280 # compare all values, if they are equal, length of sorted list "to_compare"
281 # (with key -unique) should be equal to 1
282 set to_compare [lsort -dictionary -unique $to_compare]
283 if { [llength $to_compare] != 1 } {
284 puts "Error : ${message} is WRONG because number of ${Entity} entities in shape \"${shape}\" is ${nb_entity2}"
286 puts "OK : ${message} is GOOD because number of ${Entity} entities is equal to number of expected ${Entity} entities"
291 # Procedure to check equality of two reals with tolerance (relative and absolute)
293 Compare value with expected
294 Use: checkreal name value expected tol_abs tol_rel
296 proc checkreal {name value expected tol_abs tol_rel} {
297 if { abs ($value - $expected) > $tol_abs + $tol_rel * abs ($expected) } {
298 puts "Error: $name = $value is not equal to expected $expected"
300 puts "Check of $name OK: value = $value, expected = $expected"
305 help checkfreebounds {
306 Compare number of free edges with ref_value
308 Use: checkfreebounds shape ref_value [options...]
310 -tol N: used tolerance (default -0.01)
311 -type N: used type, possible values are "closed" and "opened" (default "closed")
313 proc checkfreebounds {shape ref_value args} {
314 puts "checkfreebounds ${shape} ${ref_value} ${args}"
315 upvar ${shape} ${shape}
320 for {set narg 0} {$narg < [llength $args]} {incr narg} {
321 set arg [lindex $args $narg]
322 if {[_check_arg "-tol" tol 1] ||
323 [_check_arg "-type" type 1]
328 if { [regexp {^-} $arg] } {
329 error "Error: unsupported option \"$arg\""
331 error "Error: cannot interpret argument $narg ($arg)"
334 if {"$type" != "closed" && "$type" != "opened"} {
335 error "Error : wrong -type key \"${type}\""
338 freebounds ${shape} ${tol}
339 set free_edges [llength [explode ${shape}_[string range $type 0 0] e]]
341 if { ${ref_value} == -1 } {
342 puts "Error : Number of free edges is UNSTABLE"
346 if { ${free_edges} != ${ref_value} } {
347 puts "Error : Number of free edges is not equal to reference data"
349 puts "OK : Number of free edges is ${free_edges}"
354 Compare max tolerance of shape with ref_value.
355 Argument "source_shapes" is a list of used for sewing shapes.
356 It can be empty to skip comparison of tolerance with source shapes.
358 Use: checkmaxtol shape ref_value [source_shapes={}] [options...]
360 -min_tol: minimum tolerance for comparison
361 -multi_tol: tolerance multiplier
363 proc checkmaxtol {shape ref_value {source_shapes {}} args} {
364 puts "checkmaxtol ${shape} ${ref_value} ${source_shapes} ${args}"
365 upvar ${shape} ${shape}
370 for {set narg 0} {$narg < [llength $args]} {incr narg} {
371 set arg [lindex $args $narg]
372 if {[_check_arg "-min_tol" min_tol 1] ||
373 [_check_arg "-multi_tol" tol_multiplier 1]
378 if { [regexp {^-} $arg] } {
379 error "Error: unsupported option \"$arg\""
381 error "Error: cannot interpret argument $narg ($arg)"
384 # get max tol of shape
385 regexp {max tol = ([-0-9.+eE]+)} [tolmax ${shape}] full max_tol
387 checkreal "Max tolerance" $max_tol $ref_value 0.0001 0.01
388 if {[llength $source_shapes]} {
389 # find max tol of source shapes
390 foreach source_shape $source_shapes {
391 upvar ${source_shape} ${source_shape}
392 regexp {max tol = ([-0-9.+eE]+)} [tolmax $source_shape] full _src_max_tol
393 if { ${_src_max_tol} > ${min_tol} } {
394 set min_tol ${_src_max_tol}
397 if {${tol_multiplier}} {
398 set min_tol [expr ${tol_multiplier} * ${_src_max_tol}]
400 # compare max tol of source shapes with max tol of sewing_result
401 if { ${max_tol} > ${min_tol} } {
402 puts "Error: tolerance of \"${shape}\" (${max_tol}) is greater than max tolerance of source shapes (${min_tol})"
408 Compare faults number of given shapes.
410 Use: checkfaults shape source_shape [ref_value=0]
412 proc checkfaults {shape source_shape {ref_value 0}} {
413 puts "checkfaults ${shape} ${source_shape} ${ref_value}"
415 upvar $source_shape $source_shape
416 set cs_a [checkshape $source_shape]
418 if {[regexp {Faulty shapes in variables faulty_([0-9]*) to faulty_([0-9]*)} $cs_a full nb_a_begin nb_a_end]} {
419 set nb_a [expr $nb_a_end - $nb_a_begin +1]
421 set cs_r [checkshape $shape]
423 if {[regexp {Faulty shapes in variables faulty_([0-9]*) to faulty_([0-9]*)} $cs_r full nb_r_begin nb_r_end]} {
424 set nb_r [expr $nb_r_end - $nb_r_begin +1]
426 puts "Number of faults for the initial shape is $nb_a."
427 puts "Number of faults for the resulting shape is $nb_r."
429 if { ${ref_value} == -1 } {
430 puts "Error : Number of faults is UNSTABLE"
434 if { $nb_r > $nb_a } {
435 puts "Error : Number of faults is $nb_r"