0030694: Data Exchange - support non-standard GB2312-encoded STEP files
[occt.git] / tests / bugs / step / bug30694
CommitLineData
e3249d8e 1puts "================"
2puts "0030694: Data Exchange - support non-standard GB2312-encoded STEP files"
3puts ""
4puts "Test case:"
5puts "1) Creates a temporary STEP file-template using WriteStep."
6puts "2) Reads generated template and replaces @tmp_name@ entity in it with Simplified Chinese characters using Tcl."
7puts "3) Generates 2 STEP files in UTF-8 and GB2312 encodings (converted by Tcl)."
8puts "4) Reads generated files using StepRead and validates entity name."
9puts "================"
10puts ""
11
12proc fileToString { thePath } {
13 set aFile [open "$thePath" r]
14 set aText [read $aFile [file size "$thePath"]]
15 close $aFile
16 return $aText
17}
18
19proc fileFromString { thePath theContent theCodePage } {
20 set aFile [open "$thePath" w]
21 fconfigure $aFile -translation lf -encoding "$theCodePage"
22 puts $aFile $theContent
23 close $aFile
24}
25
26pload XDE OCAF MODELING VISUALIZATION
27set aTmpNameTmpl "@tmp_name@"
28set aTmpFileTmpl "${imagedir}/${casename}-tmp.stp"
29set aTmpFileUtf8 "${imagedir}/${casename}-tmp-utf8.stp"
30set aTmpFileGb "${imagedir}/${casename}-tmp-gb.stp"
31# 国标
32set aName [encoding convertfrom unicode "\xFD\x56\x07\x68"]
33box b 1 2 3
34catch { Close A }
35catch { Close T }
36catch { Close U }
37catch { Close G }
38XNewDoc T
39XAddShape T b 0
40XSetColor T b 1 0 0
41SetName T 0:1:1:1 "$aTmpNameTmpl"
42GetName T 0:1:1:1
43WriteStep T "$aTmpFileTmpl"
44
45regsub -all -- $aTmpNameTmpl [fileToString "$aTmpFileTmpl"] "$aName" aContent
46fileFromString "$aTmpFileUtf8" "$aContent" "utf-8"
47fileFromString "$aTmpFileGb" "$aContent" "gb2312"
48
49param read.stepcaf.codepage UTF8
50ReadStep U "$aTmpFileUtf8"
51ReadStep A "$aTmpFileGb"
52param read.stepcaf.codepage GB
53ReadStep G "$aTmpFileGb"
54
55if { [GetName U 0:1:1:1] != "$aName" } { puts "Error: unable to read UTF-8 STEP" }
56if { [GetName G 0:1:1:1] != "$aName" } { puts "Error: unable to read gb2312 STEP" }
57if { [GetName A 0:1:1:1] == "$aName" } { puts "Error: broken test case" }