1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
{ Unicode Collation Algorithm test routines for generated data.
Copyright (c) 2012 by Inoussa OUEDRAOGO
The source code is distributed under the Library GNU
General Public License with the following modification:
- object files and libraries linked into an application may be
distributed without source code.
If you didn't receive a copy of the file COPYING, contact:
Free Software Foundation
675 Mass Ave
Cambridge, MA 02139
USA
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
unit uca_test;
{$mode objfpc}{$H+}
interface
uses
SysUtils,
helper;
procedure uca_CheckProp_1(
ABook : TUCA_DataBook;
APropBook : PUCA_PropBook
);
procedure uca_CheckProp_x(
ABook : TUCA_DataBook;
APropBook : PUCA_PropBook
);
procedure uca_CheckProp_1y(
const ABook : TUCA_DataBook;
const APropBook : PUCA_PropBook;
const AFirstTable : PucaBmpFirstTable;
const ASecondTable : PucaBmpSecondTable
);
procedure uca_CheckProp_2y(
const ABook : TUCA_DataBook;
const APropBook : PUCA_PropBook;
const AFirstTable : PucaOBmpFirstTable;
const ASecondTable : PucaOBmpSecondTable
);
implementation
function IndexOf(const ACodePoint : Cardinal; APropBook : PUCA_PropBook): Integer;
var
i : Integer;
begin
for i := 0 to Length(APropBook^.Index) - 1 do begin
if (ACodePoint = APropBook^.Index[i].CodePoint) then
exit(i);
end;
Result := -1;
end;
function CompareWeigth(AExpect : PUCA_LineRec; AActual : PUCA_PropItemRec) : Boolean;
var
i, k : Integer;
p : PUCA_PropWeights;
pw : array of TUCA_PropWeights;
begin
Result := False;
if (Length(AExpect^.Weights) <> AActual^.WeightLength) then
exit;
//p := PUCA_PropWeights(PtrUInt(AActual) + SizeOf(TUCA_PropItemRec));
SetLength(pw,AActual^.WeightLength);
p := @pw[0];
AActual^.GetWeightArray(p);
for i := 0 to Length(AExpect^.Weights) - 1 do begin
//if (BoolToByte(AExpect^.Weights[i].Variable) <> p^.Variable) then
//exit;
for k := 0 to 3 - 1 do begin
if (AExpect^.Weights[i].Weights[k] <> p^.Weights[k]) then
exit;
end;
Inc(p);
end;
Result := True;
end;
procedure uca_CheckProp_1(
ABook : TUCA_DataBook;
APropBook : PUCA_PropBook
);
var
i, c, k : Integer;
line : PUCA_LineRec;
uc : Cardinal;
p : PUCA_PropItemRec;
begin
WriteLn('uca_CheckProp_1 Start ... ');
line := @ABook.Lines[0];
c := Length(ABook.Lines);
for i := 0 to c - 1 do begin
if line^.Stored and (Length(line^.CodePoints) = 1) then begin
uc := line^.CodePoints[0];
k := IndexOf(uc,APropBook);
if (k = -1) then begin
WriteLn('Property not found for Code Point : ' + Format('%x',[uc]));
end else begin
p := PUCA_PropItemRec(PtrUInt(APropBook^.Items)+APropBook^.Index[k].Position);
if not CompareWeigth(line,p) then
WriteLn('CompareWeigth fail for Code Point : ' + Format('%x',[uc]));
end;
end;
Inc(line);
end;
WriteLn('uca_CheckProp_1 End');
end;
function FindWord(
const AWord : array of Cardinal;
const APropBook : PUCA_PropItemRec
) : PUCA_PropItemRec;
var
cc : Cardinal;
p : PUCA_PropItemRec;
i, k, kc : Integer;
ok : Boolean;
begin
Result := nil;
p := APropBook;
for i := 1 to Length(AWord) - 1 do begin
ok := False;
kc := p^.ChildCount - 1;
p := PUCA_PropItemRec(PtrUInt(p) + p^.GetSelfOnlySize());
for k := 0 to kc do begin
if (AWord[i] = p^.CodePoint) then begin
ok := True;
Break;
end;
p := PUCA_PropItemRec(PtrUInt(p) + p^.Size);
end;
if not ok then
exit;
end;
Result := p;
end;
function DumpCodePoints(const AValues : array of Cardinal) : string;
var
i : Integer;
begin
Result := '';
for i := 0 to Length(AValues) - 1 do
Result := Format('%s %x',[Result,AValues[i]]);
Result := Trim(Result);
end;
procedure uca_CheckProp_x(
ABook : TUCA_DataBook;
APropBook : PUCA_PropBook
);
var
i, c, k : Integer;
line : PUCA_LineRec;
uc : Cardinal;
p, q : PUCA_PropItemRec;
begin
WriteLn('uca_CheckProp_x Start ... ');
line := @ABook.Lines[0];
c := Length(ABook.Lines);
for i := 0 to c - 1 do begin
if line^.Stored and (Length(line^.CodePoints) > 1) then begin
//WriteLn(' Code Point sequence : ' + DumpCodePoints(line^.CodePoints));
uc := line^.CodePoints[0];
k := IndexOf(uc,APropBook);
if (k = -1) then begin
WriteLn(' Property not found for Code Point : ' + Format('%x',[uc]));
end else begin
q := PUCA_PropItemRec(PtrUInt(APropBook^.Items)+APropBook^.Index[k].Position);
p := FindWord(line^.CodePoints,q);
if (p = nil) then
WriteLn(' Data not found for Code Point sequence : ' + DumpCodePoints(line^.CodePoints))
else if not CompareWeigth(line,p) then
WriteLn(' CompareWeigth fail for Code Point sequence : ' + DumpCodePoints(line^.CodePoints));
end;
end;
Inc(line);
end;
WriteLn('uca_CheckProp_x End');
end;
function GetPropPosition(
const ABMPCodePoint : Word;
const AFirstTable : PucaBmpFirstTable;
const ASecondTable : PucaBmpSecondTable
) : Integer; inline;overload;
begin
Result:=
ASecondTable^[AFirstTable^[WordRec(ABMPCodePoint).Hi]][WordRec(ABMPCodePoint).Lo] - 1
end;
procedure uca_CheckProp_1y(
const ABook : TUCA_DataBook;
const APropBook : PUCA_PropBook;
const AFirstTable : PucaBmpFirstTable;
const ASecondTable : PucaBmpSecondTable
);
var
i, c, k : Integer;
line : PUCA_LineRec;
uc : Cardinal;
p : PUCA_PropItemRec;
ucw : Word;
begin
WriteLn('uca_CheckProp_1y Start (BMP) ... ');
line := @ABook.Lines[0];
c := Length(ABook.Lines);
for i := 0 to c - 1 do begin
if line^.Stored and (Length(line^.CodePoints) = 1) then begin
uc := line^.CodePoints[0];
if (uc <= High(Word)) then begin
ucw := uc;
k := GetPropPosition(ucw,AFirstTable,ASecondTable);
if (k = -1) then begin
WriteLn('Property not found for Code Point : ' + Format('%x',[uc]));
end else begin
p := PUCA_PropItemRec(PtrUInt(APropBook^.Items)+k);
if not CompareWeigth(line,p) then
WriteLn('CompareWeigth fail for Code Point : ' + Format('%x',[uc]));
end;
end;
end;
Inc(line);
end;
WriteLn('uca_CheckProp_1y End');
end;
procedure uca_CheckProp_2y(
const ABook : TUCA_DataBook;
const APropBook : PUCA_PropBook;
const AFirstTable : PucaOBmpFirstTable;
const ASecondTable : PucaOBmpSecondTable
);
var
i, c, k : Integer;
line : PUCA_LineRec;
uc : Cardinal;
p : PUCA_PropItemRec;
uchs, ucls : Word;
begin
WriteLn('uca_CheckProp_2y Start (>BMP) ... ');
line := @ABook.Lines[0];
c := Length(ABook.Lines);
for i := 0 to c - 1 do begin
if line^.Stored and (Length(line^.CodePoints) = 1) then begin
uc := line^.CodePoints[0];
if (uc > High(Word)) then begin
FromUCS4(uc,uchs,ucls);
k := GetPropPosition(uchs,ucls,AFirstTable,ASecondTable);
if (k = -1) then begin
WriteLn('Property not found for Code Point : ' + Format('%x',[uc]));
end else begin
p := PUCA_PropItemRec(PtrUInt(APropBook^.Items)+k);
if not CompareWeigth(line,p) then
WriteLn('CompareWeigth fail for Code Point : ' + Format('%x',[uc]));
end;
end;
end;
Inc(line);
end;
WriteLn('uca_CheckProp_2y End');
end;
end.
|