tastrcmp.pp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. { based on string/tester.c of glibc 2.3.6
  2. * Tester for string functions.
  3. Copyright (C) 1995-2000, 2001, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. }
  18. {$ifdef fpc}
  19. {$mode delphi}
  20. {$endif fpc}
  21. uses
  22. {$ifdef unix}
  23. cwstring,
  24. {$endif unix}
  25. SysUtils;
  26. var
  27. teststr: string;
  28. goterror: boolean;
  29. procedure check(b: boolean; testnr: longint);
  30. begin
  31. if not (b) then
  32. begin
  33. writeln(teststr,' error nr ',testnr);
  34. goterror:=true;
  35. end;
  36. end;
  37. procedure testAnsiCompareText;
  38. begin
  39. teststr:='AnsiCompareText';
  40. check(ansicomparetext('a', 'a') = 0, 1);
  41. check(ansicomparetext('a', 'A') = 0, 2);
  42. check(ansicomparetext('A', 'a') = 0, 3);
  43. check(ansicomparetext('a', 'b') < 0, 4);
  44. check(ansicomparetext('c', 'b') > 0, 5);
  45. check(ansicomparetext('abc', 'AbC') = 0, 6);
  46. check(ansicomparetext('0123456789', '0123456789') = 0, 7);
  47. check(ansicomparetext('', '0123456789') < 0, 8);
  48. check(ansicomparetext('AbC', '') > 0, 9);
  49. check(ansicomparetext('AbC', 'A') > 0, 10);
  50. check(ansicomparetext('AbC', 'Ab') > 0, 11);
  51. check(ansicomparetext('AbC', 'ab') > 0, 12);
  52. check(ansicomparetext('Ab'#0'C', 'ab'#0) > 0, 13);
  53. end;
  54. procedure testAnsiStrIComp;
  55. begin
  56. teststr:='AnsiStrIComp';
  57. check(ansistricomp('a', 'a') = 0, 1);
  58. check(ansistricomp('a', 'A') = 0, 2);
  59. check(ansistricomp('A', 'a') = 0, 3);
  60. check(ansistricomp('a', 'b') < 0, 4);
  61. check(ansistricomp('c', 'b') > 0, 5);
  62. check(ansistricomp('abc', 'AbC') = 0, 6);
  63. check(ansistricomp('0123456789', '0123456789') = 0, 7);
  64. check(ansistricomp('', '0123456789') < 0, 8);
  65. check(ansistricomp('AbC', '') > 0, 9);
  66. check(ansistricomp('AbC', 'A') > 0, 10);
  67. check(ansistricomp('AbC', 'Ab') > 0, 11);
  68. check(ansistricomp('AbC', 'ab') > 0, 12);
  69. check(ansistricomp('Ab'#0'C', 'ab'#0) = 0, 13);
  70. end;
  71. procedure testAnsiStrLComp;
  72. begin
  73. teststr:='AnsiStrLComp';
  74. check (ansistrlcomp ('', '', 0) = 0, 1); { Trivial case. }
  75. check (ansistrlcomp ('a', 'a', 1) = 0, 2); { Identity. }
  76. check (ansistrlcomp ('abc', 'abc', 3) = 0, 3); { Multicharacter. }
  77. check (ansistrlcomp ('abc'#0, 'abcd', 4) < 0, 4); { Length unequal. }
  78. check (ansistrlcomp ('abcd', 'abc'#0, 4) > 0, 5);
  79. check (ansistrlcomp ('abcd', 'abce', 4) < 0, 6); { Honestly unequal. }
  80. check (ansistrlcomp ('abce', 'abcd', 4) > 0, 7);
  81. check (ansistrlcomp ('abce', 'abcd', 3) = 0, 10); { Count limited. }
  82. check (ansistrlcomp ('abce', 'abc', 3) = 0, 11); { Count = length. }
  83. check (ansistrlcomp ('abcd', 'abce', 4) < 0, 12); { Nudging limit. }
  84. check (ansistrlcomp ('abc', 'def', 0) = 0, 13); { Zero count. }
  85. check (ansistrlcomp ('abc'#0'e', 'abc'#0'd', 5) > 0, 14);
  86. end;
  87. procedure testAnsiCompareStr;
  88. begin
  89. teststr:='AnsiCompareStr';
  90. check (ansicomparestr ('', '') = 0, 1); { Trivial case. }
  91. check (ansicomparestr ('a', 'a') = 0, 2); { Identity. }
  92. check (ansicomparestr ('abc', 'abc') = 0, 3); { Multicharacter. }
  93. check (ansicomparestr ('abc', 'abcd') < 0, 4); { Length mismatches. }
  94. check (ansicomparestr ('abcd', 'abc') > 0, 5);
  95. check (ansicomparestr ('abcd', 'abce') < 0, 6); { Honest miscompares. }
  96. check (ansicomparestr ('abce', 'abcd') > 0, 7);
  97. check (ansicomparestr ('abc'#0'e', 'abc'#0'd') > 0, 8);
  98. end;
  99. procedure testAnsiStrComp;
  100. begin
  101. teststr:='AnsiStrComp';
  102. check (ansistrcomp ('', '') = 0, 1); { Trivial case. }
  103. check (ansistrcomp ('a', 'a') = 0, 2); { Identity. }
  104. check (ansistrcomp ('abc', 'abc') = 0, 3); { Multicharacter. }
  105. check (ansistrcomp ('abc', 'abcd') < 0, 4); { Length mismatches. }
  106. check (ansistrcomp ('abcd', 'abc') > 0, 5);
  107. check (ansistrcomp ('abcd', 'abce') < 0, 6); { Honest miscompares. }
  108. check (ansistrcomp ('abce', 'abcd') > 0, 7);
  109. check (ansistrcomp ('abc'#0'e', 'abc'#0'd') = 0, 8);
  110. end;
  111. procedure testAnsiStrLIComp;
  112. begin
  113. teststr:='AnsiStrLIComp';
  114. check(ansistrlicomp('a', 'a', 1) = 0, 1);
  115. check(ansistrlicomp('a', 'A', 1) = 0, 2);
  116. check(ansistrlicomp('A', 'a', 1) = 0, 3);
  117. check(ansistrlicomp('a', 'b', 1) < 0, 4);
  118. check(ansistrlicomp('c', 'b', 1) > 0, 5);
  119. check(ansistrlicomp('abc', 'AbC', 3) = 0, 6);
  120. check(ansistrlicomp('0123456789', '0123456789', 10) = 0, 7);
  121. check(ansistrlicomp(#0'123456789', #0'123456799', 10) < 0, 8);
  122. check(ansistrlicomp(#0'bD', #0'bC', 3) > 0, 9);
  123. check(ansistrlicomp('AbC', 'A'#0#0,3) > 0, 10);
  124. check(ansistrlicomp('AbC', 'Ab'#0, 3) > 0, 11);
  125. check(ansistrlicomp('AbC', 'ab'#0, 3) > 0, 12);
  126. check(ansistrlicomp('0123456789', 'AbC', 0) = 0, 13);
  127. check(ansistrlicomp('AbC', 'abc', 1) = 0, 14);
  128. check(ansistrlicomp('AbC', 'abc', 2) = 0, 15);
  129. check(ansistrlicomp('AbC', 'abc', 3) = 0, 16);
  130. check(ansistrlicomp('AbC', 'abcd', 3) = 0, 17);
  131. check(ansistrlicomp('AbCc', 'abcd', 4) < 0, 18);
  132. check(ansistrlicomp('ADC', 'abcd', 1) = 0, 19);
  133. check(ansistrlicomp('ADC', 'abcd', 2) > 0, 20);
  134. check(ansistrlicomp('abc'#0'e', 'abc'#0'd', 5) > 0, 21);
  135. end;
  136. begin
  137. goterror:=false;
  138. testAnsiCompareText;
  139. testAnsiStrIComp;
  140. testAnsiStrLComp;
  141. testAnsiCompareStr;
  142. testAnsiStrComp;
  143. testAnsiStrLIComp;
  144. if goterror then
  145. halt(1);
  146. end.