set mist 0
if { [info exists command] && [string compare $command "mkoffset"] == 0 } {
    regexp {Mass +: +([-0-9.+eE]+)} [lprops s] full sm
    regexp {Tolerance +MAX=([-0-9.+eE]+) +AVG=([-0-9.+eE]+) +MIN=[-0-9.+eE]+} [tolerance s] full MaxTol_s AvgTol_s
    puts "Length of shape a is equal to $sm"
    set theOff [expr $sm * $off_param ]
    puts [format "Considered Offset value is %s " $theOff]
    if { ![catch { mkoffset result s 1 $theOff } catch_res] } {
	renamevar result_1 result
	if { ![catch { set chsh [checkshape result] } catch_chsh] } {
	    puts $chsh
        } else {
    	    puts "Error : $catch_chsh"
    	    set mist 1
	}
    } 
}

if { [isdraw result] && $mist == 0} {
    if { [info exists command] && [string compare $command "mkoffset"] == 0 } {
	regexp {Mass +: +([-0-9.+eE]+)} [lprops result] full m

	set vertex_list [explode result v]
	set ll_v [llength $vertex_list]

	set edge_list [explode result e]
	set ll_e [llength $edge_list]

	set wire_list [explode result w]
	if { [string compare $wire_list ""] == 0} {
	    set wire_list result
	}
	set ll_w [llength $wire_list]

	if { $ll_v == 0 } {
	    if { $theOff < 0 } {
		puts [format "Warning : The resulting shape is an empty COMPOUND"]
	    } else {
		puts [format "Error : The resulting shape is an empty COMPOUND"]
	    }
	    puts [whatis result]
	    puts [nbshapes result]
	    puts [checksection result]
	} else {
	    puts [format "The resulting shape contains %s wires" $ll_w]
	    foreach wire $wire_list {
		puts "Info for $wire:"
		regexp {Tolerance +MAX=([-0-9.+eE]+) +AVG=([-0-9.+eE]+) +MIN=[-0-9.+eE]+} [tolerance $wire] full MaxTol_res AvgTol_res
		if { $MaxTol_res > $MaxTol_s } {
		    puts "Error : big tolerance of shape $wire"
		}
		regexp {nb +alone +Vertices +: +([-0-9.+eE]+)} [checksection $wire] full num
		if { $num != 0 } {
		    puts [format "Error : $wire is NOT a closed wire"]
		}
		mkplane res_plane $wire
		set chsh_res_plane [checkshape res_plane]
		if { [regexp {Faulty +shapes +in +variables +faulty_([-0-9.+eE]+) +to +faulty_([-0-9.+eE]+)} $chsh_res_plane full from_faulty to_faulty ] } {
		    puts "Shape $wire has self-intersection"
		}
	    }
	}

	if { [string compare $length "empty"] != 0 } {
	    puts "The expected length is $length"
	    #check of change of length is < 1%
	    if { ($length != 0 && [expr 1.*abs($length - $m)/$length] > 0.01) || ($length == 0 && $m != 0) } {
		puts "Error : The length of the resulting shape is $m"
	    }
	} else {
	    if { $m != 0 } {
		puts "Error : The offset is not valid. The length is $m"
	    }
	}
	# check for number of vertexes
	if { [info exists nbsh_v ] } {
	    if { ($ll_v != $nbsh_v) || ($nbsh_v == 0 && $ll_v != 0) } {
		puts "Error : The resulting shape is WRONG because it must contain $nbsh_v vertexes instead of $ll_v"
	    } else {
		puts "The resulting shape contains $ll_v vertexes"
	    }
	}
	# check for number of edges
	if { [info exists nbsh_e ] } {
	    if { ($ll_e != $nbsh_e) || ($nbsh_e == 0 && $ll_e != 0) } {
		puts "Error : The resulting shape is WRONG because it must contain $nbsh_e edges instead of $ll_e"
	    } else {
		puts "The resulting shape contains $ll_e edges"
	    }
	}
	# check for number of wires
	if { [info exists nbsh_w ] } {
	    if { ($ll_w != $nbsh_w) || ($nbsh_w == 0 && $ll_w != 0) } {
		puts "Error : The resulting shape is WRONG because it must contain $nbsh_w wires instead of $ll_w"
	    } else {
		puts "The resulting shape contains $ll_w wires"
	    }
	}
    } else {
	regexp {Mass +: +([-0-9.+eE]+)} [vprops s] full sm
	regexp {Mass +: +([-0-9.+eE]+)} [vprops result] full m
	
	#check if result is valid
	puts [checkshape result]
	if { $m == 0 || $sm == $m } {
	    puts "Error : The offset is not valid. The volume is $m."
	}
	
	#check of face's square value
	foreach ResultFace [ explode result f ]  {
	    regexp {Mass +: +([-0-9.+eE]+)} [sprops $ResultFace] full fmass
	    if { $fmass < 0 } {
		puts "Error : The area of face $ResultFace of the resulting shape is negative."
	    }
	}
	#check for bsection
	if { [info exists GlobFaces] && [llength $GlobFaces] == 0 } {
	    puts [ bsection re result s ]
	    if { [ isdraw re ] } {
		regexp {Mass +: +([-0-9.+eE]+)} [lprops $re] full remass 
		if { $remass != 0 } {
		    puts "Error: bsection of the result and s is not equal to zero."
		}
	    }
	}
	
	if { $volume > 0 } {
	    puts "The expected volume is $volume"
	}
	#check of change of volume is < 1%
	if { ($volume > 0 && [expr 1.*abs($volume - $m)/$volume] > 0.01) || ($volume == 0 && $m != 0 && $sm != $m) } {
	    puts "Error : The volume of the resulting shape is $m"
	}
    }
    if { $m > 0 } {
	clear
	smallview
	donly result
	fit
	xwd $imagedir/${test_image}.png
    } 
} else {
    puts "Error : The offset cannot be built."
}

# to end a test script
puts "TEST COMPLETED"
