|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
|
|
|
|
|
|
-uses SysUtils, FmtBCD;
|
|
|
+uses SysUtils, FmtBCD, Variants;
|
|
|
|
|
|
var
|
|
|
ErrorCount: integer;
|
|
@@ -55,6 +55,57 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure testBCDCompare(bcd1,bcd2: TBCD; res: integer);
|
|
|
+begin
|
|
|
+ if (BCDCompare(bcd1,bcd2) <> res) then
|
|
|
+ begin
|
|
|
+ writeln('BCDCompare failed; bcd1:', bcdtostr(bcd1), ' bcd2:', bcdtostr(bcd2));
|
|
|
+ inc(ErrorCount);
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure testVariantOp(v1, v2: variant);
|
|
|
+var v: variant;
|
|
|
+ i: integer;
|
|
|
+ d: double;
|
|
|
+ s1: shortstring;
|
|
|
+ s2: ansistring;
|
|
|
+ s3: unicodestring;
|
|
|
+begin
|
|
|
+ //arithmetic op. ... invalid variant operation ?
|
|
|
+ v := v1 + v2;
|
|
|
+ v := v * v2;
|
|
|
+ v := v / v2;
|
|
|
+ v := v - v2;
|
|
|
+ if VarIsFmtBCD(v1) and not VarIsFmtBCD(v) then inc(ErrorCount);
|
|
|
+
|
|
|
+ //compare op.
|
|
|
+ if not(v1=v) or (v1<>v) then
|
|
|
+ begin
|
|
|
+ writeln('Original variant: ', vartostr(v1), 'recomputed variant: ', vartostr(v));
|
|
|
+ inc(ErrorCount);
|
|
|
+ end;
|
|
|
+ v := v + 1;
|
|
|
+ if (v1 >= v) or not(v1 < v) then
|
|
|
+ begin
|
|
|
+ writeln('Compare2 failed; v1: ', vartostr(v1), ' v: ', vartostr(v));
|
|
|
+ inc(ErrorCount);
|
|
|
+ end;
|
|
|
+ v := v - 1.1;
|
|
|
+ if (v1 <= v) or not(v1 > v) then
|
|
|
+ begin
|
|
|
+ writeln('Compare3 failed; v1: ', vartostr(v1), ' v: ', vartostr(v));
|
|
|
+ inc(ErrorCount);
|
|
|
+ end;
|
|
|
+
|
|
|
+ //assign op. ... invalid variant typecast ?
|
|
|
+ //i := v;
|
|
|
+ d := v;
|
|
|
+ //s1 := v;
|
|
|
+ s2 := v;
|
|
|
+ //s3 := v;
|
|
|
+end;
|
|
|
+
|
|
|
begin
|
|
|
ErrorCount := 0;
|
|
|
|
|
@@ -110,6 +161,21 @@ begin
|
|
|
testBCDDivide(100, -2, -50);
|
|
|
testBCDDivide(1007, 5, 201.4);
|
|
|
|
|
|
+ // test BCDCompare:
|
|
|
+ testBCDCompare(100, 100, 0);
|
|
|
+ testBCDCompare(-100.1, -100.1, 0);
|
|
|
+ testBCDCompare(-100.1, 100.1, -1);
|
|
|
+ testBCDCompare(-100.1, -100.2, 1);
|
|
|
+ testBCDCompare(100, 100.1, -1);
|
|
|
+
|
|
|
+ // test Variant support:
|
|
|
+ testVariantOp(varFmtBcdCreate(100), varFmtBcdCreate(-100));
|
|
|
+ testVariantOp(double(2.5), varFmtBcdCreate(100)); //double on left side
|
|
|
+ testVariantOp(varFmtBcdCreate(100), integer(-10));
|
|
|
+ testVariantOp(varFmtBcdCreate(-100), shortstring(floattostr(10.2)));
|
|
|
+ testVariantOp(varFmtBcdCreate(-100), ansistring(floattostr(0.2)));
|
|
|
+ testVariantOp(varFmtBcdCreate(-100), unicodestring(floattostr(-0.2)));
|
|
|
+
|
|
|
|
|
|
if ErrorCount<>0 then
|
|
|
begin
|