View Issue Details

IDProjectCategoryView StatusLast Update
0024688FPCFCLpublic2017-04-22 11:37
ReporterKverdeAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0024688: AssertEquals of FPCUnit is not working with a string ending with # 0
Description// Lazarus 1.0.10 r41613 FPC 2.6.2 x86_64-win64-win32/win64

procedure TTestCase1.Test1;
var
  Str: string;
begin
  Str := '1'#0#0;
  AssertEquals('1', Str); //test should fail, but it is correct
end;
TagsNo tags attached.
Fixed in Revision35878
FPCOldBugId
FPCTarget
Attached Files
  • fpcunit.diff (586 bytes)
    Index: packages/fcl-fpcunit/src/fpcunit.pp
    ===================================================================
    --- packages/fcl-fpcunit/src/fpcunit.pp	(revision 23586)
    +++ packages/fcl-fpcunit/src/fpcunit.pp	(working copy)
    @@ -474,7 +474,7 @@
     
     class procedure TAssert.AssertEquals(const AMessage: string; Expected, Actual: string);
     begin
    -  AssertTrue(AMessage + ComparisonMsg(Expected, Actual), AnsiCompareStr(Expected, Actual) = 0);
    +  AssertTrue(AMessage + ComparisonMsg(Expected, Actual), Expected = Actual); //don't use AnsiCompareStr, pascal strings can have #0
     end;
     
     
    
    fpcunit.diff (586 bytes)

Activities

Bart Broersma

2013-06-29 18:46

reporter   ~0068662

Last edited: 2013-06-29 23:04

View 4 revisions

That's because AnsiCompareStr('1','1'#0#0) returns True.

Maybe it should use
AssertTrue(AMessage + ComparisonMsg(Expected, Actual), (Expected = Actual));

Bart Broersma

2013-11-03 13:40

reporter  

fpcunit.diff (586 bytes)
Index: packages/fcl-fpcunit/src/fpcunit.pp
===================================================================
--- packages/fcl-fpcunit/src/fpcunit.pp	(revision 23586)
+++ packages/fcl-fpcunit/src/fpcunit.pp	(working copy)
@@ -474,7 +474,7 @@
 
 class procedure TAssert.AssertEquals(const AMessage: string; Expected, Actual: string);
 begin
-  AssertTrue(AMessage + ComparisonMsg(Expected, Actual), AnsiCompareStr(Expected, Actual) = 0);
+  AssertTrue(AMessage + ComparisonMsg(Expected, Actual), Expected = Actual); //don't use AnsiCompareStr, pascal strings can have #0
 end;
 
 
fpcunit.diff (586 bytes)

Bart Broersma

2013-11-03 13:41

reporter   ~0071117

Possible patch attached.

Marco van de Voort

2013-11-04 11:41

manager   ~0071135

True, but probably the other tests check sorting order, and there you need "ansi" because it is localized (important for country dependent sorting).

I'm not sure it if makes sense to use ansicomparestr there, but not with equals.

Thaddy de Koning

2013-11-04 17:21

reporter   ~0071139

Last edited: 2013-11-04 17:24

View 3 revisions

This will break most databases since they are invariably written in C dialects.
So for database work you should ignore Pascal's fancy #0 in the middle stuff unless ALL clients are written in FPC or Delphi and the server actually accepts it. (Only sqlite does with string fields)

On the other hand: if it's not database related, this seems a valid proposal.

In general, I would stick to AnsiCompareStr and accept zero's as a terminator but that is mho.
Also: if you declare a string like THAT, there's really more zero's in the universe than you and I can imagine. (Bit stolen from Shaky)

Bart Broersma

2017-04-05 18:33

reporter   ~0099397

Resolve "as won't fix" or "no change required" then?

Denis Kozlov

2017-04-20 18:03

reporter   ~0099710

It may be fine for AnsiCompareStr('1','1'#0#0) to return True.

But TAssert.AssertEquals('1','1'#0#0) should fail.

FPC 3.0.2:
  TAssert.AssertEquals('1','1'#0); => passes
  TAssert.AssertEquals('1','1'#0'2'); => fails

Both should fail, in my opinion.

Michael Van Canneyt

2017-04-21 21:12

administrator   ~0099742

Changed to use Actual=Equal, since the same is used for UnicodeString.
Because of the strange category (Other) I never noticed this bug, or it would have been changed a long time ago...

Issue History

Date Modified Username Field Change
2013-06-29 12:35 Kverde New Issue
2013-06-29 18:46 Bart Broersma Note Added: 0068662
2013-06-29 18:51 Bart Broersma Note Edited: 0068662 View Revisions
2013-06-29 18:51 Bart Broersma Note Edited: 0068662 View Revisions
2013-06-29 19:09 Bart Broersma Project Lazarus => FPC
2013-06-29 23:04 Bart Broersma Note Edited: 0068662 View Revisions
2013-11-03 13:40 Bart Broersma File Added: fpcunit.diff
2013-11-03 13:41 Bart Broersma Note Added: 0071117
2013-11-04 11:41 Marco van de Voort Note Added: 0071135
2013-11-04 17:21 Thaddy de Koning Note Added: 0071139
2013-11-04 17:22 Thaddy de Koning Note Edited: 0071139 View Revisions
2013-11-04 17:24 Thaddy de Koning Note Edited: 0071139 View Revisions
2017-04-05 18:33 Bart Broersma Note Added: 0099397
2017-04-20 18:03 Denis Kozlov Note Added: 0099710
2017-04-21 21:11 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-04-21 21:11 Michael Van Canneyt Status new => assigned
2017-04-21 21:12 Michael Van Canneyt Fixed in Revision => 35878
2017-04-21 21:12 Michael Van Canneyt Note Added: 0099742
2017-04-21 21:12 Michael Van Canneyt Status assigned => resolved
2017-04-21 21:12 Michael Van Canneyt Fixed in Version => 3.1.1
2017-04-21 21:12 Michael Van Canneyt Resolution open => fixed
2017-04-21 21:12 Michael Van Canneyt Target Version => 3.2.0
2017-04-21 21:13 Michael Van Canneyt Category Other => FCL