0028454: Data Exchange, STEP reader - names with special characters cannot be read
[occt.git] / tests / bugs / step / bug28454_1
1 puts "================"
2 puts "0028454: Data Exchange - Names with Special Characters Cannot Be Read from STEP or IGES Files"
3 puts "Target encodings: ISO 8859-1, ISO 8859-2, ISO 8859-3, ISO 8859-4, ISO 8859-5, ISO 8859-6,, ISO 8859-7, ISO 8859-8"
4 puts "Test case:"
5 puts "1) Creates a temporary STEP file-template using WriteStep."
6 puts "2) Reads generated template and replaces @tmp_name@ entity in it with target language characters using Tcl."
7 puts "3) Generates 2 STEP files in UTF-8 and ISO 8859-(N) encodings (converted by Tcl)."
8 puts "4) Reads generated files using StepRead and validates entity name."
9 puts "================"
10 puts ""
11
12 proc fileToString { thePath } {
13   set aFile [open "$thePath" r]
14   set aText [read $aFile [file size "$thePath"]]
15   close $aFile
16   return $aText
17 }
18
19 proc 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
26 proc fileCreateAndCompare { thePathFrom theUtfPathTo theCpPathTo theNameFrom theNameTo theCodePage } {
27   regsub -all -- $theNameFrom [fileToString "$thePathFrom"] "$theNameTo" aContent
28   set aPathTo $theCpPathTo${theCodePage}.stp
29   fileFromString "$theUtfPathTo" "$aContent" "utf-8"
30   fileFromString "$aPathTo" "$aContent" "$theCodePage"
31   
32   param read.step.codepage UTF8
33   ReadStep U "$theUtfPathTo"
34   ReadStep A "$aPathTo"
35   param read.step.codepage "$theCodePage"
36   ReadStep ISO "$aPathTo"
37   
38   if { [GetName U   0:1:1:1] != "$theNameTo" } { puts "Error: unable to read UTF-8  STEP" }
39   if { [GetName ISO 0:1:1:1] != "$theNameTo" } { puts "Error: unable to read $theCodePage STEP" }
40   if { [GetName A   0:1:1:1] == "$theNameTo" } { puts "Error: broken test case" }
41   catch { Close A }
42   catch { Close U }
43   catch { Close ISO }
44 }
45
46 pload XDE OCAF MODELING VISUALIZATION
47 set aTmpNameTmpl "@tmp_name@"
48 set aTmpFileTmpl "${imagedir}/${casename}-tmp.stp"
49 set aTmpFileUtf8 "${imagedir}/${casename}-tmp-utf8.stp"
50 set aTmpFileISO8859N "${imagedir}/${casename}-tmp-"
51
52 # "Test" (english multi-encoding) + "Test" (encoding in the target language)
53
54 # multi-encoding
55 set anEngName [encoding convertfrom utf-8 "\x54\x65\x73\x74"]
56 # ISO 8859-1
57 set iso8859_1 [encoding convertfrom utf-8 "\x50\x72\x6f\x62\xed\x68\xe1"]
58 # ISO 8859-2
59 set iso8859_2 [encoding convertfrom utf-8 "\x50\x72\x6f\x62\xed\x68\xe1"]
60 # ISO 8859-3
61 set iso8859_3 [encoding convertfrom utf-8 "\xd6\x6c\xe7\x65\x6b"]
62 # ISO 8859-4 
63 set iso8859_4 [encoding convertfrom utf-8 "\x6d\xc4\x93\xc4\xa3\x69\x6e\x69\x65\x74"]
64 # ISO 8859-5
65 set iso8859_5 [encoding convertfrom utf-8 "\xD0\xa2\xD0\xB5\xD1\x81\xD1\x82"]
66 # ISO 8859-6
67 set iso8859_6 [encoding convertfrom utf-8 "\xd8\xa7\xd8\xae\xd8\xaa\xd8\xa8\xd8\xa7\xd8\xb1"]
68 # ISO 8859-7
69 set iso8859_7 [encoding convertfrom utf-8 "\xce\xb4\xcf\x80\xce\xa8\xce\xae"]
70 # ISO 8859-8
71 set iso8859_8 [encoding convertfrom utf-8 "\xc2\xb1\xd7\xa4\xd7\x9e\xd7\x9c\xd7\xa9"]
72 # ISO 8859-9
73 set iso8859_9 [encoding convertfrom utf-8 "\xc4\x9f\xc5\x9f\xc4\x9e\xc5\x9e\xc3\x86"]
74
75 box b 1 2 3
76 catch { Close A }
77 catch { Close T }
78 catch { Close U }
79 catch { Close CP }
80
81 XNewDoc   T
82 XAddShape T b 0
83 XSetColor T b 1 0 0
84 SetName   T 0:1:1:1 "$aTmpNameTmpl"
85 GetName   T 0:1:1:1
86 WriteStep T "$aTmpFileTmpl"
87
88 puts "ISO 8859-1"
89 set aName "$anEngName $iso8859_1"
90 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-1"
91
92 puts "ISO 8859-2"
93 set aName "$anEngName $iso8859_2"
94 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-2"
95
96 puts "ISO 8859-3"
97 set aName "$anEngName $iso8859_3"
98 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-3"
99
100 puts "ISO 8859-4"
101 set aName "$anEngName $iso8859_4"
102 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-4"
103
104 puts "ISO 8859-5"
105 set aName "$anEngName $iso8859_5"
106 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-5"
107
108 puts "ISO 8859-6"
109 set aName "$anEngName $iso8859_6"
110 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-6"
111
112 puts "ISO 8859-7"
113 set aName "$anEngName $iso8859_7"
114 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-7"
115
116 puts "ISO 8859-8"
117 set aName "$anEngName $iso8859_8"
118 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-8"
119
120 puts "ISO 8859-9"
121 set aName "$anEngName $iso8859_9"
122 fileCreateAndCompare "$aTmpFileTmpl" "$aTmpFileUtf8" "$aTmpFileISO8859N" "$aTmpNameTmpl" "$aName" "iso8859-9"