Browse Source

* Patch from Laco to enhance test for bug #24096

git-svn-id: trunk@24129 -
michael 12 years ago
parent
commit
95e6be9853
1 changed files with 50 additions and 0 deletions
  1. 50 0
      tests/test/units/fmtbcd/tfmtbcd.pp

+ 50 - 0
tests/test/units/fmtbcd/tfmtbcd.pp

@@ -44,6 +44,17 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure testFormatBCD(const Format: string; BCD: TBCD; Output: string);
+var s: string;
+begin
+  s := FormatBCD(Format, BCD);
+  if s <> Output then
+  begin
+    writeln('FormatBCD ''', Format, ''': ', s, ' Expected: ', Output);
+    inc(ErrorCount);
+  end;
+end;
+
 procedure testBCDPrecScale(const s: string; const prec,scale: integer);
 procedure testBCDPrecScale(const s: string; const prec,scale: integer);
 var bcd: TBCD;
 var bcd: TBCD;
 begin
 begin
@@ -122,6 +133,7 @@ begin
   testBCDToStrF(bcdtostrf(bcd, ffFixed, 30, 4), '123456789123456789,1235'); //no thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffFixed, 30, 4), '123456789123456789,1235'); //no thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffNumber, 30, 5), '123 456 789 123 456 789,12345'); //with thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffNumber, 30, 5), '123 456 789 123 456 789,12345'); //with thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffCurrency, 30, 2), '123 456 789 123 456 789,12 $'); //with thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffCurrency, 30, 2), '123 456 789 123 456 789,12 $'); //with thousand separators
+  testBCDToStrF(bcdtostrf(bcd, ffExponent, 9, 2), '1,23456789E+17');
 
 
   FS.DecimalSeparator:='.';
   FS.DecimalSeparator:='.';
   FS.ThousandSeparator:=',';
   FS.ThousandSeparator:=',';
@@ -130,8 +142,46 @@ begin
   bcd:=strtobcd('123456789123456789.12345');
   bcd:=strtobcd('123456789123456789.12345');
   testBCDToStrF(bcdtostr(bcd), '123456789123456789.12345');
   testBCDToStrF(bcdtostr(bcd), '123456789123456789.12345');
   testBCDToStrF(bcdtostrf(bcd, ffFixed, 30, 3), '123456789123456789.123'); //no thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffFixed, 30, 3), '123456789123456789.123'); //no thousand separators
+  testBCDToStrF(bcdtostrf(bcd, ffFixed, 30, 0), '123456789123456789');
   testBCDToStrF(bcdtostrf(bcd, ffNumber, 30, 6), '123,456,789,123,456,789.123450'); //with thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffNumber, 30, 6), '123,456,789,123,456,789.123450'); //with thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffCurrency, 30, 5), '$123,456,789,123,456,789.12345'); //with thousand separators
   testBCDToStrF(bcdtostrf(bcd, ffCurrency, 30, 5), '$123,456,789,123,456,789.12345'); //with thousand separators
+  testBCDToStrF(bcdtostrf(bcd, ffExponent, 8, 3), '1.2345679E+017');
+  bcd:=strtobcd('123456789');
+  testBCDToStrF(bcdtostrf(bcd, ffFixed, 10, 0), '123456789');
+  testBCDToStrF(bcdtostrf(bcd, ffExponent, 8, 3), '1.2345679E+008');
+  bcd:=strtobcd('9.99'); // test rounding
+  testBCDToStrF(bcdtostrf(bcd, ffFixed, 10, 1), '10.0');
+  testBCDToStrF(bcdtostrf(bcd, ffFixed, 10, 0), '10');
+  testBCDToStrF(bcdtostrf(bcd, ffExponent, 8, 3), '9.9900000E+000');
+  bcd:=strtobcd('0.09');
+  testBCDToStrF(bcdtostrf(bcd, ffFixed, 10, 1), '0.1');
+  testBCDToStrF(bcdtostrf(bcd, ffFixed, 10, 0), '0');
+  testBCDToStrF(bcdtostrf(bcd, ffExponent, 8, 3), '9.0000000E-002');
+
+  // test FormatBCD:
+  bcd:=strtobcd('123456789123456789.12345');
+  testFormatBCD('',bcd, '123456789123456789.12345');
+  testFormatBCD('0',bcd, '123456789123456789');
+  testFormatBCD('0.',bcd, '123456789123456789');
+  testFormatBCD('0.0',bcd, '123456789123456789.1');
+  testFormatBCD('#.0000',bcd, '123456789123456789.1235');
+  testFormatBCD('#.000000',bcd, '123456789123456789.123450');
+  testFormatBCD('# ###.000',bcd, '123456789123456 789.123');
+  testFormatBCD('#-#-###.0000',bcd, '12345678912345-6-789.1235');
+  testFormatBCD('#,#,###.0000',bcd, '123,456,789,123,456,789.1235');
+  testFormatBCD('#,#.0000##',bcd, '123,456,789,123,456,789.12345');
+  bcd:=strtobcd('-123.455');
+  testFormatBCD('0.0',bcd, '-123.5');
+  testFormatBCD('00000.0',bcd, '-00123.5');
+  testFormatBCD('#####.#',bcd, '-123.5');
+  testFormatBCD('.0000',bcd, '-123.4550');
+  testFormatBCD('+0.0',bcd, '+-123.5'); // sign is part of number
+  testFormatBCD('0.00" $"',bcd, '-123.46 $');
+  testFormatBCD('0.0;(neg)0.00',bcd, '(neg)123.46');
+  bcd:=strtobcd('0');
+  testFormatBCD('0;;0',bcd, '0');
+  testFormatBCD('0;;#',bcd, '');
+  testFormatBCD('0;;0.00',bcd, '0.00');
 
 
   // test StrToBCD:
   // test StrToBCD:
   testBCDPrecScale(' 1.0000000000000000E-0003 ', 3, 3);
   testBCDPrecScale(' 1.0000000000000000E-0003 ', 3, 3);