mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-12 23:09:40 +02:00
143 lines
4.5 KiB
ObjectPascal
143 lines
4.5 KiB
ObjectPascal
unit utstrcmp;
|
|
{ based on string/tester.c of glibc 2.3.6
|
|
|
|
* Tester for string functions.
|
|
Copyright (C) 1995-2000, 2001, 2003 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library 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. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA. */
|
|
}
|
|
|
|
{$ifdef fpc}
|
|
{$mode delphi}
|
|
{$endif fpc}
|
|
|
|
interface
|
|
|
|
uses
|
|
{$ifdef unix}
|
|
{$ifdef darwin}iosxwstr{$else}cwstring{$endif},
|
|
{$endif unix}
|
|
SysUtils;
|
|
|
|
implementation
|
|
|
|
uses punit, utrtl;
|
|
|
|
Var
|
|
GotError : Boolean;
|
|
|
|
procedure check(b: boolean; testnr: longint);
|
|
|
|
begin
|
|
if Not GotError then
|
|
begin
|
|
GotError:=B;
|
|
AssertTrue('Error nr '+IntToStr(testNr),B);
|
|
end;
|
|
end;
|
|
|
|
Function teststricomp : String;
|
|
begin
|
|
GotError:=False;
|
|
Result:='';
|
|
check(stricomp('a', 'a') = 0, 1);
|
|
check(stricomp('a', 'A') = 0, 2);
|
|
check(stricomp('A', 'a') = 0, 3);
|
|
check(stricomp('a', 'b') < 0, 4);
|
|
check(stricomp('c', 'b') > 0, 5);
|
|
check(stricomp('abc', 'AbC') = 0, 6);
|
|
check(stricomp('0123456789', '0123456789') = 0, 7);
|
|
check(stricomp('', '0123456789') < 0, 8);
|
|
check(stricomp('AbC', '') > 0, 9);
|
|
check(stricomp('AbC', 'A') > 0, 10);
|
|
check(stricomp('AbC', 'Ab') > 0, 11);
|
|
check(stricomp('AbC', 'ab') > 0, 12);
|
|
check(stricomp('Ab'#0'C', 'ab'#0) = 0, 13);
|
|
end;
|
|
|
|
|
|
Function teststrlcomp : string;
|
|
|
|
begin
|
|
GotError:=False;
|
|
Result:='';
|
|
check (strlcomp ('', '', 0) = 0, 1); { Trivial case. }
|
|
check (strlcomp ('a', 'a', 1) = 0, 2); { Identity. }
|
|
check (strlcomp ('abc', 'abc', 3) = 0, 3); { Multicharacter. }
|
|
check (strlcomp ('abc'#0, 'abcd', 4) < 0, 4); { Length unequal. }
|
|
check (strlcomp ('abcd', 'abc'#0, 4) > 0, 5);
|
|
check (strlcomp ('abcd', 'abce', 4) < 0, 6); { Honestly unequal. }
|
|
check (strlcomp ('abce', 'abcd', 4) > 0, 7);
|
|
check (strlcomp ('abce', 'abcd', 3) = 0, 10); { Count limited. }
|
|
check (strlcomp ('abce', 'abc', 3) = 0, 11); { Count = length. }
|
|
check (strlcomp ('abcd', 'abce', 4) < 0, 12); { Nudging limit. }
|
|
check (strlcomp ('abc', 'def', 0) = 0, 13); { Zero count. }
|
|
check (strlcomp ('abc'#0'e', 'abc'#0'd', 5) = 0, 14);
|
|
end;
|
|
|
|
|
|
Function teststrcomp : String;
|
|
begin
|
|
GotError:=False;
|
|
Result:='';
|
|
check (strcomp ('', '') = 0, 1); { Trivial case. }
|
|
check (strcomp ('a', 'a') = 0, 2); { Identity. }
|
|
check (strcomp ('abc', 'abc') = 0, 3); { Multicharacter. }
|
|
check (strcomp ('abc', 'abcd') < 0, 4); { Length mismatches. }
|
|
check (strcomp ('abcd', 'abc') > 0, 5);
|
|
check (strcomp ('abcd', 'abce') < 0, 6); { Honest miscompares. }
|
|
check (strcomp ('abce', 'abcd') > 0, 7);
|
|
check (strcomp ('abc'#0'e', 'abc'#0'd') = 0, 8);
|
|
end;
|
|
|
|
|
|
function teststrlicomp : string;
|
|
|
|
begin
|
|
GotError:=False;
|
|
Result:='';
|
|
check(strlicomp('a', 'a', 1) = 0, 1);
|
|
check(strlicomp('a', 'A', 1) = 0, 2);
|
|
check(strlicomp('A', 'a', 1) = 0, 3);
|
|
check(strlicomp('a', 'b', 1) < 0, 4);
|
|
check(strlicomp('c', 'b', 1) > 0, 5);
|
|
check(strlicomp('abc', 'AbC', 3) = 0, 6);
|
|
check(strlicomp('0123456789', '0123456789', 10) = 0, 7);
|
|
check(strlicomp(#0'123456789', #0'123456799', 10) = 0, 8);
|
|
check(strlicomp(#0'bD', #0'bC', 3) = 0, 9);
|
|
check(strlicomp('AbC', 'A'#0#0,3) > 0, 10);
|
|
check(strlicomp('AbC', 'Ab'#0, 3) > 0, 11);
|
|
check(strlicomp('AbC', 'ab'#0, 3) > 0, 12);
|
|
check(strlicomp('0123456789', 'AbC', 0) = 0, 13);
|
|
check(strlicomp('AbC', 'abc', 1) = 0, 14);
|
|
check(strlicomp('AbC', 'abc', 2) = 0, 15);
|
|
check(strlicomp('AbC', 'abc', 3) = 0, 16);
|
|
check(strlicomp('AbC', 'abcd', 3) = 0, 17);
|
|
check(strlicomp('AbCc', 'abcd', 4) < 0, 18);
|
|
check(strlicomp('ADC', 'abcd', 1) = 0, 19);
|
|
check(strlicomp('ADC', 'abcd', 2) > 0, 20);
|
|
check(strlicomp('abc'#0'e', 'abc'#0'd', 5) = 0, 21);
|
|
end;
|
|
|
|
|
|
begin
|
|
SysutilsTest('TestStrIComp',@teststricomp);
|
|
SysutilsTest('TestStrLComp',@teststrlcomp);
|
|
SysutilsTest('TestStrComp',@teststrcomp);
|
|
SysutilsTest('TestStrLIComp',@teststrlicomp);
|
|
end.
|