@@ -92,25 +92,43 @@ public void readWithForcedTimeoutTest() throws Exception
92
92
public void nullCharTests () throws Exception
93
93
{
94
94
// Unicode
95
+ boolean unicodePassed = true ;
95
96
{
96
97
FieldDef recordDef = null ;
97
98
{
98
99
FieldDef [] fieldDefs = new FieldDef [2 ];
99
100
fieldDefs [0 ] = new FieldDef ("uni" , FieldType .STRING , "STRING" , 100 , false , false , HpccSrcType .UTF16LE , new FieldDef [0 ]);
100
- fieldDefs [1 ] = new FieldDef ("fixedUni" , FieldType .STRING , "STRING" , 100 , true , false , HpccSrcType .UTF16LE , new FieldDef [0 ]);
101
+ fieldDefs [1 ] = new FieldDef ("fixedUni" , FieldType .STRING , "STRING" , 200 , true , false , HpccSrcType .UTF16LE , new FieldDef [0 ]);
101
102
102
103
recordDef = new FieldDef ("RootRecord" , FieldType .RECORD , "rec" , 4 , false , false , HpccSrcType .LITTLE_ENDIAN , fieldDefs );
103
104
}
104
105
105
106
List <HPCCRecord > records = new ArrayList <HPCCRecord >();
106
107
int maxUTF16BMPChar = Character .MAX_CODE_POINT ;
107
- for (int i = 0 ; i < maxUTF16BMPChar ; i ++) {
108
+ for (int i = 0 ; i < maxUTF16BMPChar ; i ++)
109
+ {
110
+
108
111
String strMidEOS = "" ;
109
- for (int j = 0 ; j < 98 ; j ++, i ++) {
110
- if (j == 50 ) {
112
+ for (int j = 0 ; j < 98 ; j ++, i ++)
113
+ {
114
+ if (!Character .isValidCodePoint (i ) || !Character .isDefined (i ))
115
+ {
116
+ continue ;
117
+ }
118
+
119
+ char [] chars = Character .toChars (i );
120
+ if (Character .isSurrogate (chars [0 ]))
121
+ {
122
+ continue ;
123
+ }
124
+
125
+ if (j == 50 && strMidEOS .length () > 0 )
126
+ {
111
127
strMidEOS += "\0 " ;
112
128
}
113
- strMidEOS += Character .toString ((char ) i );
129
+
130
+ String charStr = new String (chars );
131
+ strMidEOS += charStr ;
114
132
}
115
133
116
134
Object [] fields = {strMidEOS , strMidEOS };
@@ -123,17 +141,20 @@ public void nullCharTests() throws Exception
123
141
HPCCFile file = new HPCCFile (fileName , connString , hpccUser , hpccPass );
124
142
List <HPCCRecord > readRecords = readFile (file , 10000 , false , false , BinaryRecordReader .TRIM_STRINGS );
125
143
126
- for (int i = 0 ; i < records .size (); i ++) {
144
+ for (int i = 0 ; i < records .size (); i ++)
145
+ {
127
146
HPCCRecord record = records .get (i );
128
147
HPCCRecord readRecord = readRecords .get (i );
129
148
if (readRecord .equals (record ) == false )
130
149
{
131
150
System .out .println ("Record: " + i + " did not match\n " + record + "\n " + readRecord );
151
+ unicodePassed = false ;
132
152
}
133
153
}
134
154
}
135
155
136
156
// SBC / ASCII
157
+ boolean sbcPassed = true ;
137
158
{
138
159
FieldDef recordDef = null ;
139
160
{
@@ -145,13 +166,16 @@ public void nullCharTests() throws Exception
145
166
}
146
167
147
168
List <HPCCRecord > records = new ArrayList <HPCCRecord >();
148
- for (int i = 0 ; i < 255 ; i ++) {
169
+ for (int i = 0 ; i < 255 ; i ++)
170
+ {
149
171
String strMidEOS = "" ;
150
- for (int j = 0 ; j < 9 ; j ++, i ++) {
151
- if (j == 5 ) {
172
+ for (int j = 0 ; j < 9 ; j ++, i ++)
173
+ {
174
+ if (j == 5 )
175
+ {
152
176
strMidEOS += "\0 " ;
153
177
}
154
- strMidEOS += Character .toString (( char ) i );
178
+ strMidEOS += new String ( Character .toChars ( j ) );
155
179
}
156
180
157
181
Object [] fields = {strMidEOS , strMidEOS };
@@ -164,15 +188,20 @@ public void nullCharTests() throws Exception
164
188
HPCCFile file = new HPCCFile (fileName , connString , hpccUser , hpccPass );
165
189
List <HPCCRecord > readRecords = readFile (file , 10000 , false , false , BinaryRecordReader .TRIM_STRINGS );
166
190
167
- for (int i = 0 ; i < records .size (); i ++) {
191
+ for (int i = 0 ; i < records .size (); i ++)
192
+ {
168
193
HPCCRecord record = records .get (i );
169
194
HPCCRecord readRecord = readRecords .get (i );
170
195
if (readRecord .equals (record ) == false )
171
196
{
172
197
System .out .println ("Record: " + i + " did not match\n " + record + "\n " + readRecord );
198
+ sbcPassed = false ;
173
199
}
174
200
}
175
201
}
202
+
203
+ assertTrue ("Unicode EOS character test failed. See mismatches above." , unicodePassed );
204
+ assertTrue ("Single byte EOS character test failed. See mismatches above." , sbcPassed );
176
205
}
177
206
178
207
@ Test
0 commit comments