program TestStrngUtils; {-$DEFINE STRINGS} // the string routines are tested {$IFDEF STRINGS} {$DEFINE OLDPROCS} // The original procs of the first "StrngUtils" are also tested (added to the library for compatibility reasons) {$ENDIF} {$DEFINE CONVERSIONS} // the conversion routines are tested uses StrngUtils; var Str: string[15]; {absolute $50;} // absolute for the mE StrStr test Str2: string[50]; {absolute $5B;} ErrorStr: string[20]; TmpByte: short; Bte: byte; ErrPos: byte; Wrd: word; DWrd: DWord; Error: boolean; Tint: integer; Shrt: short; Lint: LongInt; Flt: real; TmpInt: integer; IpArray: array[4] of byte; MACArray: array[6] of byte; const ConstStr1 : string[10] = 'abcdefghij'; ConstStr2 : string[4] = 'abcd'; ConstStr3 : string[20] = 'abcdefghijklmnopqrst'; ConstStr4 : string[12] = 'abcdabcdabcd'; ConstLines: string[23] = 'abc'+ #10 + 'defg' + #10 + 'hijkl' + #10 + 'mnopqrst'; procedure AddError(var S: string); begin Error := true; if ErrorStr[0] = 0 then StrCpy(ErrorStr, S); end; begin Error := false; ErrorStr := ''; // StrCmp (mE Strings library ) ---> StrCmp is Ok now! <--- Tint := StrCmp('1234567890', '12345678901'); // StrCmp returns zero <---- error, -49 in v4.80 bèta! OK! if Tint <> -49 then AddError('StrCmp_mE1'); Tint := StrCmp('12345678901', '1234567890'); // StrCmp returns 49 (ok) if Tint <> 49 then AddError('StrCmp_mE2'); Tint := StrCmp('1234567891', '1234567890'); // StrCmp returns 1 (ok) if Tint <> 1 then AddError('StrCmp_mE3'); Tint := StrCmp('1234567890', '1234567891'); // StrCmp returns -1 (ok) if Tint <> -1 then AddError('StrCmp_mE4'); { // StrCmp_ (replacement) Tint := StrCmp_('1234567890', '12345678901'); // StrCmp_ returns -49 (ok) if Tint <> -49 then AddError('StrCmp_1'); Tint := StrCmp_('12345678901', '1234567890'); // StrCmp_ returns 49 (ok) if Tint <> 49 then AddError('StrCmp_2'); Tint := StrCmp_('1234567891', '1234567890'); // StrCmp_ returns 1 (ok) if Tint <> 1 then AddError('StrCmp_3'); Tint := StrCmp_('1234567890', '1234567891'); // StrCmp_ returns -1 (ok) if Tint <> -1 then AddError('StrCmp_4'); } // StrStr (mE strings library} ---> StrStr is Ok now! <--- Str2 := '01234567890'; Str := '1234567890'; Wrd := StrStr(Str, '012345'); // function returns 11 in stead of $FFFF <--- error, $FFFF in v4.80 bèta! OK! if Wrd <> $ffff then AddError('StrStr_mE1'); Str := '123456789'; Wrd := StrStr(Str, '012345'); // function returns $FFFF if Wrd <> $ffff then AddError('StrStr_mE2'); // StrStr_ (replacement} Str2 := '01234567890'; Str := '1234567890'; Wrd := StrStr(Str, '012345'); // function returns $FFFF if Wrd <> $ffff then AddError('StrStr_1'); //Wrd := StrStr_(Str, '012345'); // function returns $FFFF //if Wrd <> $ffff then AddError('StrStr_2'); Str := '123456789'; Wrd := StrStr(Str, '012345'); // function returns $FFFF if Wrd <> $ffff then AddError('StrStr_mE3'); //Wrd := StrStr_(Str, '012345'); // function returns $FFFF //if Wrd <> $ffff then AddError('StrStr_mE4'); Wrd := StrStr(Str, '12345'); // function returns 0 if Wrd <> 0 then AddError('StrStr_mE5'); //Wrd := StrStr_(Str, '12345'); // function returns 0 //if Wrd <> 0 then AddError('StrStr_mE6'); Wrd := StrStr(Str, '34567'); // function returns 2 if Wrd <> 2 then AddError('StrStr_mE7'); //Wrd := StrStr_(Str, '34567'); // function returns 2 //if Wrd <> 2 then AddError('StrStr_3'); Wrd := StrStr(Str, '89'); // function returns 7 if Wrd <> 7 then AddError('StrStr_mE8'); //Wrd := StrStr_(Str, '89'); // function returns 7 //if Wrd <> 7 then AddError('StrStr_4'); Wrd := StrStr(Str, '9'); // function returns 8 if Wrd <> 8 then AddError('StrStr_mE9'); //Wrd := StrStr_(Str, '9'); // function returns 8 //if Wrd <> 8 then AddError('StrStr_5'); Wrd := StrStr(Str, ''); // function returns $FFFF if Wrd <> $ffff then AddError('StrStr_mE10'); //Wrd := StrStr_(Str, ''); // function returns $FFFF //if Wrd <> $ffff then AddError('StrStr_6'); Wrd := StrStr(Str, '1243'); // function returns $FFFF if Wrd <> $ffff then AddError('StrStr_mE11'); //Wrd := StrStr_(Str, '1243'); // function returns $FFFF //if Wrd <> $ffff then AddError('StrStr_7'); Wrd := StrStr(Str, '91'); // function returns $FFFF if Wrd <> $ffff then AddError('StrStr_mE12'); //Wrd := StrStr_(Str, '91'); // function returns $FFFF //if Wrd <> $ffff then AddError('StrStr_8'); Str := 'abc '; Str2 := ' '; rtrim(Str2); // Str should keep its contents! if strcmp('abc ', Str) <> 0 then AddError('RTrim_mE1'); Str2 := 'abc '; Str := ' '; ltrim(Str); // Str2 should keep its contents! if strcmp('abc ', Str2) <> 0 then AddError('LTrim_mE1'); {$IFDEF STRINGS} // ---------- memCpyC ------------- Str := '1234567890'; memcpyC(@Str, @conststr1[3], 4); if strcmp(Str, 'defg567890') <> 0 then AddError('memCpyC1'); // ---------- StrLenC and LengthC ------------- Wrd := StrLenC(@ConstStr1); if Wrd <> 10 then AddError('StrLenC1'); Wrd := StrLenC(@ConstStr1); if Wrd <> 10 then AddError('StrLenC2'); Wrd := LengthC(@ConstStr1); if Wrd <> 10 then AddError('LengthC1'); Wrd := LengthC(@ConstStr1); if Wrd <> 10 then AddError('LengthC2'); // ----------- SetLength ---------- Str := '1234567890'; SetLength(Str, 4); if StrCmp(Str, '1234') <> 0 then AddError('SetLength1'); Str := '1234'; SetLength(Str, 6); if StrCmp(Str, '1234') <> 0 then AddError('SetLength2'); // ----------- StringOfChar ------- Str := '1234567890'; StringOfChar(Str, 'x', 6); if StrCmp(Str, 'xxxxxx') <> 0 then AddError('StringOfChar1'); // ------------ StrCatC ------------- Str := '1234567890'; Str := '12345'; StrCatC(Str, @ConstStr2); if StrCmp(Str, '12345abcd') <> 0 then AddError('StrCatC'); Str := '1234567890'; Str := '12345'; StrCatCX(Str, @ConstStr1, 11); // 11 = length + 1 if StrCmp(Str, '12345abcde') <> 0 then AddError('StrCatCX1'); Str := '1234567890'; Str := '12345'; StrCatCX(Str, @ConstStr1, 9); if StrCmp(Str, '12345abc') <> 0 then AddError('StrCatCX2'); // ---------- StrLCat ------------ Str := '1234567890'; Str := '123'; Str2 := 'defg'; StrLCat(Str, Str2, 2); if StrCmp(Str, '123de') <> 0 then AddError('StrLCat1'); Str := '1234567890'; Str := '123'; Str2 := 'defg'; StrLCat(Str, Str2, 6); if StrCmp(Str, '123defg') <> 0 then AddError('StrLCat2'); // ----------- StrLCatC ----------- Str := '1234567890'; Str := '123'; StrLCatC(Str, @ConstStr1, 2); if StrCmp(Str, '123ab') <> 0 then AddError('StrLCatC1'); Str2 := '123456789012345678901234567890'; Str2 := '123'; StrLCatC(Str2, @ConstStr1, 20); if StrCmp(Str2, '123abcdefghij') <> 0 then AddError('StrLCatC2'); // ----------- StrSplit ------------ Str := '1234567890'; Str2 := '12345abcdef'; StrSplit(Str2, Str, 5); if (StrCmp(Str2, '12345') <> 0) or (StrCmp(Str, 'abcdef') <> 0) then AddError('StrSplit1'); Str := '1234567890'; Str2 := '1234abcde'; StrSplit(Str2, Str, 4); if (StrCmp(Str2, '1234') <> 0) or (StrCmp(Str, 'abcde') <> 0) then AddError('StrSplit2'); // ----------- StrAddCRLF ------------ Str := '1234567890'; Str := '123'; StrAddCRLF(Str); if StrCmp(Str, '123' + #13 +#10) <> 0 then AddError('StrAddCRLF1'); // ----------- StrInsertChr -------- Str := '1234512345'; Str := '12345'; StrInsertChr(Str, 'X', 2); if StrCmp(Str, '12X345') <> 0 then AddError('StrInsertChr1'); Str := '1234512345'; Str := '12345'; StrInsertChr(Str, 'X', 7); if StrCmp(Str, '12345') <> 0 then AddError('StrInsertChr2'); Str := '1234512345'; Str := '12345'; StrInsertChr(Str, 'X', 5); if StrCmp(Str, '12345X') <> 0 then AddError('StrInsertChr3'); Str := '1234567890'; Str := '12345'; StrInsertChrX(Str, 'X', 2, SizeOf(Str)); if StrCmp(Str, '12X345') <> 0 then AddError('StrInsertChrX1'); Str := '1234567890'; Str := '12345'; StrInsertChrX(Str, 'X', 9, SizeOf(Str)); if StrCmp(Str, '12345') <> 0 then AddError('StrInsertChrX2'); Str := '1234567890'; Str := '12345'; StrInsertChrX(Str, 'X', 10, SizeOf(Str)); if StrCmp(Str, '12345') <> 0 then AddError('StrInsertChrX3'); Str := '1234567890'; StrInsertChrX(Str, 'X', 2, 11); // impossible if StrCmp(Str, '1234567890') <> 0 then AddError('StrInsertChrX4'); Str := '123456789'; StrInsertChrX(Str, 'X', 9, SizeOf(Str)); if StrCmp(Str, '123456789X') <> 0 then AddError('StrInsertChrX5'); Str := '1234567890'; StrInsertChrX(Str, 'X', 16, SizeOf(Str)); // impossible if StrCmp(Str, '1234567890') <> 0 then AddError('StrInsertChrX6'); // ---------- StrRemoveChr ------------- Str := '1234567890'; StrRemoveChr(Str, 5); if StrCmp(Str, '123457890') <> 0 then AddError('StrRemoveChr1'); Str := '1234567890'; StrRemoveChr(Str, 0); if StrCmp(Str, '234567890') <> 0 then AddError('StrRemoveChr2'); Str := '1234567890'; StrRemoveChr(Str, 9); if StrCmp(Str, '123456789') <> 0 then AddError('StrRemoveChr3'); // ---------- strCpyC ----------- Str := '1234567890'; StrCpyC(Str, @ConstStr2); if StrCmp(Str, 'abcd') <> 0 then AddError('StrCpyC1'); //StrCpyX_Const Str := '1234567890'; StrCpyCX(Str, @ConstStr3, 11); if StrCmp(Str, 'abcdefghij') <> 0 then AddError('StrCpyCX1'); //StrCpyX_Const Str := '1234567890'; StrCpyCX(Str, @ConstStr3, 9); if StrCmp(Str, 'abcdefgh') <> 0 then AddError('StrCpyCX2'); // ---------- StrnCpyC ------------ Str := '1234567890'; StrnCpyC(Str, @ConstStr3, 5); if StrCmp(Str, 'abcde') <> 0 then AddError('StnCpyC1'); Str := '1234567890'; StrnCpyCX(Str, @ConstStr3, 20, 11); if StrCmp(Str, 'abcdefghij') <> 0 then AddError('StrnCpyCX1'); Str := '1234567890'; StrnCpyCX(Str, @ConstStr3, 20, 9); if StrCmp(Str, 'abcdefgh') <> 0 then AddError('StrnCpyCX2'); // ---------- Copy --------------- Str := '12345'; Str2 := 'abcdef'; Copy(Str, Str2, 1, 2); if StrCmp(Str, 'bc') <> 0 then AddError('Copy1'); Str := '12345'; Str2 := 'abcdef'; Copy(Str, Str2, 2, 6); if StrCmp(Str, 'cdef') <> 0 then AddError('Copy2'); Str := '12345'; Str2 := 'abcdefghijklmnopqrstuvw'; CopyX(Str, Str2, 2, 12, 11); if StrCmp(Str, 'cdefghijkl') <> 0 then AddError('Copy3'); Str := '12345'; Str2 := 'abcdefghijklmnopqrstuvw'; CopyX(Str, Str2, 2, 12, 9); if StrCmp(Str, 'cdefghij') <> 0 then AddError('Copy4'); // ---------- CopyC --------------- Str := '1234567890'; CopyC(Str, @ConstStr1, 2, 3); if StrCmp(Str, 'cde') <> 0 then AddError('CopyC1'); Str := '1234567890'; CopyC(Str, @ConstStr1, 7, 3); if StrCmp(Str, 'hij') <> 0 then AddError('CopyC2'); Str := '1234567890'; CopyC(Str, @ConstStr1, 7, 4); if StrCmp(Str, 'hij') <> 0 then AddError('CopyC3'); // ---------- CopyCL ---------------- Str := '1234567890'; CopyCL(Str, @ConstLines, 0); if StrCmp(Str, 'abc') <> 0 then AddError('CopyCL1'); Str := '1234567890'; CopyCL(Str, @ConstLines, 1); if StrCmp(Str, 'defg') <> 0 then AddError('CopyCL2'); Str := '1234567890'; CopyCL(Str, @ConstLines, 2); if StrCmp(Str, 'hijkl') <> 0 then AddError('CopyCL3'); Str := '1234567890'; CopyCL(Str, @ConstLines, 3); if StrCmp(Str, 'mnopqrst') <> 0 then AddError('CopyCL4'); Str := '1234567890'; CopyCL(Str, @ConstLines, 4); if StrCmp(Str, '') <> 0 then AddError('CopyCL5'); // ---------- StrLCopy ------------ Str := '1234567890'; Str2 := 'abcd'; StrLCopy(Str, Str2, 3); if StrCmp(Str, 'abc') <> 0 then AddError('StrLCopy1'); Str := '1234567890'; Str2 := 'abcd'; StrLCopy(Str, Str2, 4); if StrCmp(Str, 'abcd') <> 0 then AddError('StrLCopy2'); Str := '1234567890'; Str2 := 'abcd'; StrLCopy(Str, Str2, 5); if StrCmp(Str, 'abcd') <> 0 then AddError('StrLCopy3'); Str := '1234567890'; Str2 := 'abcd'; StrLCopy(Str, Str2, 0); if StrCmp(Str, '') <> 0 then AddError('StrLCopy4'); // ----------StrLCopyC --------- Str := '1234567890'; StrLCopyC(Str, @ConstStr2, 3); if StrCmp(Str, 'abc') <> 0 then AddError('StrLCopyC1'); Str := '1234567890'; StrLCopyC(Str, @ConstStr2, 4); if StrCmp(Str, 'abcd') <> 0 then AddError('StrLCopyC2'); Str := '1234567890'; StrLCopyC(Str, @ConstStr2, 5); if StrCmp(Str, 'abcd') <> 0 then AddError('StrLCopyC3'); Str := '1234567890'; StrLCopyC(Str, @ConstStr2, 0); if StrCmp(Str, '') <> 0 then AddError('StrLCopyC4'); // ---------- StrCutChr ----------- Str := 'xxx1234567'; StrCutChr(Str, 'x'); if StrCmp(Str, '1234567') <> 0 then AddError('StrCutChr1'); Str := 'xxx1234567'; StrCutChr(Str, 'y'); if StrCmp(Str, 'xxx1234567') <> 0 then AddError('StrCutChr2'); // ---------- Trim --------------- Str := '1234567890'; Str := ' 12345'; TrimLeft(Str); if StrCmp(Str, '12345') <> 0 then AddError('Trim1'); Str := '1234567890'; Str := '12345'; TrimLeft(Str); if StrCmp(Str, '12345') <> 0 then AddError('Trim2'); Str := '1234567890'; Str := ' 1'; TrimLeft(Str); if StrCmp(Str, '1') <> 0 then AddError('Trim3'); Str := '1234567890'; Str := ' '; TrimLeft(Str); if StrCmp(Str, '') <> 0 then AddError('Trim4'); Str := '1234567890'; Str := '123 '; TrimLeft(Str); if StrCmp(Str, '123 ') <> 0 then AddError('Trim5'); Str := '1234567890'; Str := ''; TrimLeft(Str); if StrCmp(Str, '') <> 0 then AddError('Trim6'); Str := '1234567890'; Str := '12345 '; TrimRight(Str); if StrCmp(Str, '12345') <> 0 then AddError('Trim7'); Str := '1234567890'; Str := '12345'; TrimRight(Str); if StrCmp(Str, '12345') <> 0 then AddError('Trim8'); Str := '1234567890'; Str := ' 12345'; TrimRight(Str); if StrCmp(Str, ' 12345') <> 0 then AddError('Trim9'); Str := '1234567890'; Str := '1 '; TrimRight(Str); if StrCmp(Str, '1') <> 0 then AddError('Trim10'); Str := '1234567890'; Str := ' '; TrimRight(Str); if StrCmp(Str, '') <> 0 then AddError('Trim11'); Str := '1234567890'; Str := ''; TrimRight(Str); if StrCmp(Str, '') <> 0 then AddError('Trim12'); Str := '1234567890'; Str := ' 12345 '; Trim(Str); if StrCmp(Str, '12345') <> 0 then AddError('Trim13'); Str := '1234567890'; Str := ' '; Trim(Str); if StrCmp(Str, '') <> 0 then AddError('Trim14'); Str := '1234567890'; Str := ''; Trim(Str); if StrCmp(Str, '') <> 0 then AddError('Trim15'); // ----------- Case -------------- Str := '1234567890'; Str := 'abc'; Uppercase(Str); if StrCmp(Str, 'ABC') <> 0 then AddError('Uppercase'); Lowercase(Str); if StrCmp(Str, 'abc') <> 0 then AddError('Lowercase'); // ---------- StrChrN ------------- Str := '1234512345'; Wrd := StrChrN(Str, '2', 4); if Wrd <> 6 then AddError('StrChrN1'); Str := '1234512345'; Wrd := StrChrN(Str, '2', 1); if Wrd <> 1 then AddError('StrChrN2'); Str := '1234512345'; Wrd := StrChrN(Str, '2', 0); if Wrd <> 1 then AddError('StrChrN3'); Str := '1234512345'; Wrd := StrChrN(Str, '5', 9); if Wrd <> 9 then AddError('StrChrN4'); Str := '1234512345'; Wrd := StrChrN(Str, 'A', 0); if Wrd <> $FFFF then AddError('StrChrN5'); // ---------- StrNChr ---------- Str := '1234512345'; wrd := StrNChr(Str, '2'); if Wrd <> 2 then AddError('StrNChr1'); Str := '1234512345'; wrd := StrNChr(Str, 'a'); if Wrd <> 0 then AddError('StrNChr1'); // ---------- StrPeplChr ---------- Str := '1234512345'; StrReplChr(Str, '2', 'X'); if StrCmp(Str, '1X3451X345') <> 0 then AddError('StrReplChr1'); // ---------- CompareStr ----------- Str := '1234567890'; Tint := CompareStr(Str, '1234567890'); if Tint <> 0 then AddError('CompareStr1'); Str := '1234567890'; Tint := CompareStr(Str, '12345678901'); if Tint >= 0 then AddError('CompareStr2'); Str := '1234567890'; Tint := CompareStr(Str, '12345678'); if Tint <= 0 then AddError('CompareStr3'); Str := '1234567890'; Tint := CompareStr(Str, '123a567890'); if Tint >= 0 then AddError('CompareStr4'); Str := '1234567890'; Tint := CompareStr(Str, '1232567890'); if Tint <= 0 then AddError('CompareStr5'); // ---------- StrLComp ---------- Str := '1234567890'; Tint := StrLComp(Str, '12', 3); if Tint <= 0 then AddError('StrLComp1'); Str := '1234567890'; Tint := StrLComp(Str, '123abc', 3); if Tint <> 0 then AddError('StrLComp2'); // ---------- StrStrN ---------- Str := '1234512345'; Wrd := StrStrN(Str, '234', 0); if Wrd <> 1 then AddError('StrStrN1'); Str := '1234512345'; Wrd := StrStrN(Str, '234', 2); if Wrd <> 6 then AddError('StrStrN2'); // ----------- Pos ---------------- Str := '1234567890'; Wrd := Pos('123', Str); if Wrd > 0 then AddError('Pos1'); Str := '1234567890'; Wrd := Pos('890', Str); if Wrd <> 7 then AddError('Pos2'); Str := '1234567890'; Wrd := Pos('0123', Str); if Wrd <> $FFFF then AddError('Pos3'); Str := '1234567890'; Wrd := Pos('', Str); if Wrd <> $FFFF then AddError('Pos4'); Str := ''; Wrd := Pos('123', Str); if Wrd <> $FFFF then AddError('Pos5'); Str := ''; Wrd := Pos('', Str); if Wrd <> $FFFF then AddError('Pos6'); // ---------- PosEx ---------- Str := '1234512345'; Wrd := PosEx('345', Str, 1); if Wrd <> 2 then AddError('PosEx1'); Str := '1234512345'; Wrd := PosEx('345', Str, 2); if Wrd <> 2 then AddError('PosEx2'); Str := '1234512345'; Wrd := PosEx('345', Str, 3); if Wrd <> 7 then AddError('PosEx3'); Str := '1234512345'; Wrd := PosEx('345', Str, 7); if Wrd <> 7 then AddError('PosEx4'); Str := '1234512345'; Wrd := PosEx('345', Str, 8); if Wrd <> $FFFF then AddError('PosEx5'); Str := '1234512345'; Wrd := PosEx('', Str, 0); if Wrd <> $FFFF then AddError('PosEx6'); // ---------- PosC ----------------- //ConstStr3 : string[20] = 'abcdefghijklmnopqrst'; Wrd := PosC('def', @ConstStr3); if Wrd <> 3 then AddError('PosC1'); Wrd := PosC('rst', @ConstStr3); if Wrd <> 17 then AddError('PosC2'); Wrd := PosC('stu', @ConstStr3); if Wrd <> $FFFF then AddError('PosC3'); Wrd := PosC('abcdefghijklmnopqrst_extended', @ConstStr3); if Wrd <> $FFFF then AddError('PosC4'); // ---------- PosExC ------------- //ConstStr4 : string[20] = 'abcdabcdabcd'; Wrd := PosExC('bcd', @ConstStr4, 0); if Wrd <> 1 then AddError('PosExC1'); Wrd := PosExC('bcd', @ConstStr4, 1); if Wrd <> 1 then AddError('PosExC2'); Wrd := PosExC('bcd', @ConstStr4, 2); if Wrd <> 5 then AddError('PosExC3'); Wrd := PosExC('bcd', @ConstStr4, 6); if Wrd <> 9 then AddError('PosExC4'); Wrd := PosExC('bcd', @ConstStr4, 10); if Wrd <> $FFFF then AddError('PosExC5'); // ---------- Insert ------------- Str := '1234567890'; Str := '12345'; Str2 := 'abc'; Insert(Str2, Str, 2); if StrCmp(Str, '12abc345') <> 0 then AddError('Insert1'); Str := '1234567890'; Str := '123'; Str2 := 'abc'; Insert(Str2, Str, 3); if StrCmp(Str, '123abc') <> 0 then AddError('Insert2'); Str := '1234567890'; Str := '123'; Str2 := 'abc'; Insert(Str2, Str, 2); if StrCmp(Str, '12abc3') <> 0 then AddError('Insert3'); Str := '1234567890'; Str := '123'; Str2 := 'abc'; Insert(Str2, Str, 3); if StrCmp(Str, '123abc') <> 0 then AddError('Insert4'); Str := '1234567890'; Str := '123'; Str2 := 'abc'; Insert(Str2, Str, 4); if StrCmp(Str, '123') <> 0 then AddError('Insert5'); Str := '1234512345'; Str := '12345'; Str2 := 'abc'; Insert(Str2, Str, 6); if StrCmp(Str, '12345') <> 0 then AddError('Insert6'); Str := '1234512345'; Str := '12345'; Str2 := 'abc'; Insert(Str2, Str, 7); if StrCmp(Str, '12345') <> 0 then AddError('Insert7'); Str := '1234512345'; Str := '12345'; Str2 := 'abc'; InsertX(Str2, Str, 7, SizeOf(Str)); if StrCmp(Str, '12345') <> 0 then AddError('InsertX1'); Str := '1234512345'; Str := '12345'; Str2 := 'abc'; InsertX(Str2, Str, 5, SizeOf(Str)); if StrCmp(Str, '12345abc') <> 0 then AddError('InsertX2'); Str := '1234512345'; Str := '12345'; Str2 := 'abc'; InsertX(Str2, Str, 8, SizeOf(Str)); if StrCmp(Str, '12345') <> 0 then AddError('InsertX3'); Str := '1234512345'; Str := '12345'; Str2 := 'abc'; InsertX(Str2, Str, 10, SizeOf(Str)); if StrCmp(Str, '12345') <> 0 then AddError('InsertX4'); // ---------- Delete ------------- Str := '1234567890'; Delete(Str, 2, 3); if StrCmp(Str, '1267890') <> 0 then AddError('Delete1'); Str := '1234567890'; Delete(Str, 8, 2); if StrCmp(Str, '12345678') <> 0 then AddError('Delete2'); Str := '1234567890'; Delete(Str, 8, 3); if StrCmp(Str, '12345678') <> 0 then AddError('Delete3'); Str := '1234567890'; Delete(Str, 9, 1); if StrCmp(Str, '123456789') <> 0 then AddError('Delete4'); Str := '1234567890'; Delete(Str, 10, 1); if StrCmp(Str, '1234567890') <> 0 then AddError('Delete5'); // ---------- StrReplace -------- Str := '1234512345'; Bte := StrReplace(Str, '23', 'ab', true); if (StrCmp(Str, '1ab451ab45') <> 0) or (Bte <> 2) then AddError('StrReplace1'); Str := '1234512345'; Bte := StrReplace(Str, '23', 'ab', false); if (StrCmp(Str, '1ab4512345') <> 0) or (Bte <> 1) then AddError('StrReplace2'); // ---------- StrAddSpaces -------------- Str2 := '1234567890'; StrAddSpaces(Str2, 15, true); if StrCmp(Str2, ' -1234567890') <> 0 then AddError('StrAddSpaces1'); Str2 := '1234567890'; StrAddSpaces(Str2, 15, false); if StrCmp(Str2, ' 1234567890') <> 0 then AddError('StrAddSpaces2'); // ---------- Stuff -------------- Str := '1234567890'; Str2 := 'abcd'; Stuff(Str2, Str, 3); if StrCmp(Str, '123abcd890') <> 0 then AddError('Stuff1'); Str := '1234567890'; Str2 := 'abcd'; StuffX(Str2, Str, 6, SizeOf(Str)); if StrCmp(Str, '123456abcd') <> 0 then AddError('Stuff2'); Str := '1234567890'; Str2 := 'abcd'; StuffX(Str2, Str, 7, 11); if StrCmp(Str, '1234567890') <> 0 then AddError('Stuff3'); Str := '1234567890'; Str := '12'; Str2 := 'abcd'; StuffX(Str2, Str, 6, 11); if StrCmp(Str, '12 abcd') <> 0 then AddError('Stuff4'); Str := '1234567890'; Str := '12'; Str2 := 'abcd'; StuffX(Str2, Str, 7, 11); if StrCmp(Str, '12') <> 0 then AddError('Stuff5'); // ---------- Pad ---------------- Str := '1234512345'; Str := '12345'; PadLeft(Str, 8); if StrCmp(Str, ' 12345') <> 0 then AddError('Pad1'); Str := '1234567890'; Str := '12345'; PadLeft(Str, 10); if StrCmp(Str, ' 12345') <> 0 then AddError('Pad2'); Str := '1234567890'; Str := '12345'; PadLeftX(Str, 10, SizeOf(Str)); if StrCmp(Str, ' 12345') <> 0 then AddError('Pad3'); Str := '1234567890'; Str := '12345'; PadLeftX(Str, 10, 9); if StrCmp(Str, ' 12345') <> 0 then AddError('Pad4'); Str := '1234567890'; Str := '12345'; PadLeftX(Str, 11, 11); if StrCmp(Str, ' 12345') <> 0 then AddError('Pad5'); Str := '1234512345'; Str := '12345'; PadRight(Str, 7); if StrCmp(Str, '12345 ') <> 0 then AddError('Pad6'); Str := '1234567890'; Str := '12345'; PadRightX(Str, 9, 11); if StrCmp(Str, '12345 ') <> 0 then AddError('Pad7'); Str := '1234567890'; Str := '12345'; PadRightX(Str, 9, 9); if StrCmp(Str, '12345 ') <> 0 then AddError('Pad8'); Str := '1234567890'; Str := '12345'; PadRightX(Str, 11, 11); if StrCmp(Str, '12345 ') <> 0 then AddError('Pad9'); // ---------- ClearString -------- Str := '1234567890'; ClearString(Str, SizeOf(Str)); for Wrd := 0 to SizeOf(Str) - 1 do if Str[Wrd] <> 0 then AddError('ClearString'); // ---------- StrCat ------------- Str := '1234567890'; Str := '12345'; Str2 := 'abcdef'; StrCatX(Str, Str2, 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrCatX1'); Str := '1234567890'; Str := '12345'; Str2 := 'abcdef'; StrCatX(Str, Str2, 9); if StrCmp(Str, '12345abc') <> 0 then AddError('StrCatX2'); Str := '1234567890'; Str := '12345'; Str2 := 'abc'; StrCatX(Str, Str2, 11); if StrCmp(Str, '12345abc') <> 0 then AddError('StrCatX3'); Str := '1234567890'; Str := '12345'; Str2 := 'abcde'; StrCatX(Str, Str2, 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrCatX4'); Str := '1234567890'; Str := '12345'; StrAppendSufX(Str, 'X', 11); if StrCmp(Str, '12345X') <> 0 then AddError('StrAppendSufX1'); Str := '1234567890'; Str := '12345abcd'; StrAppendSufX(Str, 'X', 11); if StrCmp(Str, '12345abcdX') <> 0 then AddError('StrAppendSufX2'); Str := '12345abcde'; StrAppendSufX(Str, 'X', 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrAppendSufX3'); Str := '1234512345'; Str := '12345'; StrAppendPreX(Str, 'X', 11); if StrCmp(Str, 'X12345') <> 0 then AddError('StrAppendPreX1'); Str := '1234512345'; Str := '12345abcd'; StrAppendPreX(Str, 'X', 11); if StrCmp(Str, 'X12345abcd') <> 0 then AddError('StrAppendPreX2'); Str := '12345abcde'; StrAppendPreX(Str, 'X', 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrAppendPreX3'); // ---------- StrChr ------------- Wrd := 0; Wrd := StrChrC(@ConstStr1, 'z'); if Wrd <> $FFFF then AddError('StrChrC1'); Wrd := 0; Wrd := StrChrC(@ConstStr1, 'c'); if Wrd <> 2 then AddError('StrChrC2'); // ---------- StrCpy ------------- Str := '1234567890'; Str2 := 'abcdefghijklmnop'; StrCpyX(Str, Str2, 11); if StrCmp(Str, 'abcdefghij') <> 0 then AddError('StrCpyX1'); Str := '1234567890'; Str2 := 'abcdefghijklmnop'; StrCpyX(Str, Str2, 9); if StrCmp(Str, 'abcdefgh') <> 0 then AddError('StrCpyX2'); // ---------- StrCmpC ------------- Str := 'abcd'; TmpByte := StrCmpC(@ConstStr2, Str); if TmpByte <> 0 then AddError('StrCmpC1'); Str := 'abc'; TmpByte := StrCmpC(@ConstStr2, Str); if TmpByte <= 0 then AddError('StrCmpC2'); Str := 'abcc'; TmpByte := StrCmpC(@ConstStr2, Str); if TmpByte <= 0 then AddError('StrCmpC3'); Str := 'abcde'; TmpByte := StrCmpC(@ConstStr2, Str); if TmpByte >= 0 then AddError('StrCmpC4'); Str := 'abce'; TmpByte := StrCmpC(@ConstStr2, Str); if TmpByte >= 0 then AddError('StrCmpC5'); // ---------- StrCmpNocase ------------- // case insensitive string compare Str := 'abc'; Str2 := 'Abc'; TmpByte := StrCmpNocase(Str, Str2); if TmpByte <> 0 then AddError('StrCmpNocase1'); Str := 'aBC'; Str2 := 'abc'; TmpByte := StrCmpNocase(Str, Str2); if TmpByte <> 0 then AddError('StrCmpNocase2'); Str := 'Cbc'; Str2 := 'bbc'; TmpByte := StrCmpNocase(Str, Str2); if TmpByte <= 0 then AddError('StrCmpNocase3'); Str := 'bbc'; Str2 := 'Cbc'; TmpByte := StrCmpNocase(Str, Str2); if TmpByte >= 0 then AddError('StrCmpNocase4'); // ---------- StrnCmp ------------ Str := 'abcdxy'; TmpByte := StrnCmpC(@ConstStr3, Str, 4); if TmpByte <> 0 then AddError('StrnCmp1'); Str := 'abc'; TmpByte := StrnCmpC(@ConstStr3, Str, 4); if TmpByte <= 0 then AddError('StrnCmp2'); Str := 'abcc'; TmpByte := StrnCmpC(@ConstStr3, Str, 4); if TmpByte <= 0 then AddError('StrnCmp3'); Str := 'abce'; TmpByte := StrnCmpC(@ConstStr3, Str, 4); if TmpByte >= 0 then AddError('StrnCmp4'); {$ENDIF} {$IFDEF CONVERSIONS} // ---------- ByteTo ------------- Byte2Bin($AA, Str); TmpByte := StrCmp(Str, '10101010'); if TmpByte <> 0 then AddError('Byte2Bin1'); Byte2Bin($55, Str); TmpByte := StrCmp(Str, '01010101'); if TmpByte <> 0 then AddError('Byte2Bin2'); Byte2Bin($5A, Str); TmpByte := StrCmp(Str, '01011010'); if TmpByte <> 0 then AddError('Byte2Bin3'); Byte2Bin($A5, Str); TmpByte := StrCmp(Str, '10100101'); if TmpByte <> 0 then AddError('Byte2Bin4'); // -- Bte := 15; Byte2Str(Bte, Str); if StrCmp(Str, '15') <> 0 then AddError('Byte2Str1'); Bte := 15; Byte2StrN(Bte, str2, 10); if StrCmp(Str2, ' 15') <> 0 then AddError('Byte2StrN1'); Str := '1234567890'; Bte := 15; ByteToStrWithZeros(Bte, Str); // ToStr TmpByte := StrCmp(Str, '015'); if TmpByte <> 0 then AddError('ByteToStrWithZeros1'); Str := '1234567890'; Bte := 15; Byte2StrWithZeros(Bte, Str); // 2Str TmpByte := StrCmp(Str, '015'); if TmpByte <> 0 then AddError('Byte2StrWithZeros1'); bte := 0; Byte2Str(bte, Str); TmpByte := StrCmp(Str, '0'); if TmpByte <> 0 then AddError('ByteToStr0'); Byte2StrN(bte, Str, 2); TmpByte := StrCmp(Str, ' 0'); if TmpByte <> 0 then AddError('ByteToStrN0'); Byte2StrWithZeros(Bte, Str); TmpByte := StrCmp(Str, '000'); if TmpByte <> 0 then AddError('ByteToStrWZ0'); // ---------- ShortTo ------------- Shrt := -15; Short2Str(Shrt, Str); TmpByte := StrCmp(Str, '-15'); if TmpByte <> 0 then AddError('Short2Str1'); Shrt := 20; Short2Str(Shrt, Str); TmpByte := StrCmp(Str, '20'); if TmpByte <> 0 then AddError('Short2Str2'); Shrt := -15; Short2StrN(Shrt, Str, 6); TmpByte := StrCmp(Str, ' -15'); if TmpByte <> 0 then AddError('Short2StrN1'); Shrt := 20; Short2StrN(Shrt, Str, 6); TmpByte := StrCmp(Str, ' 20'); if TmpByte <> 0 then AddError('Short2StrN2'); Str := '1234567890'; Shrt := -15; Short2StrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '-015'); if TmpByte <> 0 then AddError('Short2StrWithZeros1'); Str := '1234567890'; Shrt := 20; Short2StrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '0020'); if TmpByte <> 0 then AddError('Short2StrWithZeros2'); Str := '1234567890'; Shrt := -128; Short2StrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '-128'); if TmpByte <> 0 then AddError('Short2StrWithZeros3'); Str := '1234567890'; Shrt := 127; Short2StrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '0127'); if TmpByte <> 0 then AddError('Short2StrWithZeros4'); //- Str := '1234567890'; Shrt := -15; ShortToStrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '-015'); if TmpByte <> 0 then AddError('ShortToStrWithZeros1'); Str := '1234567890'; Shrt := 20; ShortToStrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '0020'); if TmpByte <> 0 then AddError('ShortToStrWithZeros2'); Str := '1234567890'; Shrt := -128; ShortToStrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '-128'); if TmpByte <> 0 then AddError('ShortToStrWithZeros3'); Str := '1234567890'; Shrt := 127; ShortToStrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '0127'); if TmpByte <> 0 then AddError('ShortToStrWithZeros4'); Shrt := 0; Short2Str(Shrt, Str); TmpByte := StrCmp(Str, '0'); if TmpByte <> 0 then AddError('ShortToStr0'); Short2StrN(Shrt, Str, 3); TmpByte := StrCmp(Str, ' 0'); if TmpByte <> 0 then AddError('ShortToStrN0'); Short2StrWithZeros(Shrt, Str); TmpByte := StrCmp(Str, '0000'); if TmpByte <> 0 then AddError('ShortToStrWZ0'); // ---------- WordTo ------------- Wrd := 2000; Word2Str(Wrd, Str); TmpByte := StrCmp(Str, '2000'); if TmpByte <> 0 then AddError('Word2Str1'); Wrd := 2000; Word2StrN(Wrd, Str, 7); TmpByte := StrCmp(Str, ' 2000'); if TmpByte <> 0 then AddError('Word2StrN1'); Str := '1234567890'; Wrd := 1234; Word2StrWithZeros(Wrd, Str); // 2 str TmpByte := StrCmp(Str, '01234'); if TmpByte <> 0 then AddError('Word2StrWithZeros1'); Str := '1234567890'; Wrd := 1234; WordToStrWithZeros(Wrd, Str); // To Str TmpByte := StrCmp(Str, '01234'); if TmpByte <> 0 then AddError('WordToStrWithZeros1'); Wrd := 0; Word2Str(Wrd, Str); TmpByte := StrCmp(Str, '0'); if TmpByte <> 0 then AddError('WordToStr0'); Word2StrN(Wrd, Str, 3); TmpByte := StrCmp(Str, ' 0'); if TmpByte <> 0 then AddError('WordToStrN0'); Word2StrWithZeros(Wrd, Str); TmpByte := StrCmp(Str, '00000'); if TmpByte <> 0 then AddError('WordToStrWZ0'); //-- Word2Bin($AAAA, Str2); TmpByte := StrCmp(Str2, '1010101010101010'); if TmpByte <> 0 then AddError('Word2Bin1'); Word2Bin($5555, Str2); TmpByte := StrCmp(Str2, '0101010101010101'); if TmpByte <> 0 then AddError('Word2Bin2'); Word2Bin($5A5A, Str2); TmpByte := StrCmp(Str2, '0101101001011010'); if TmpByte <> 0 then AddError('Word2Bin3'); Word2Bin($A5A5, Str2); TmpByte := StrCmp(Str2, '1010010110100101'); if TmpByte <> 0 then AddError('Word2Bin4'); // ---------- IntTo ------------- Str := '1234567890'; Tint := 2000; Int2Str(Tint, Str); TmpByte := StrCmp(Str, '2000'); if TmpByte <> 0 then AddError('Int2Str1'); Str := '1234567890'; Tint := -2000; Int2Str(Tint, Str); TmpByte := StrCmp(Str, '-2000'); if TmpByte <> 0 then AddError('Int2Str2'); Str := '1234567890'; Tint := 2000; Int2StrN(Tint, Str, 7); TmpByte := StrCmp(Str, ' 2000'); if TmpByte <> 0 then AddError('Int2StrN1'); Str := '1234567890'; Tint := -2000; Int2StrN(Tint, Str, 7); TmpByte := StrCmp(Str, ' -2000'); if TmpByte <> 0 then AddError('Int2StrN2'); Str := '1234567890'; Tint := -1234; Int2StrWithZeros(Tint, Str); TmpByte := StrCmp(Str, '-01234'); if TmpByte <> 0 then AddError('Int2StrWithZeros1'); Str := '1234567890'; Tint := 1234; Int2StrWithZeros(Tint, Str); TmpByte := StrCmp(Str, '001234'); if TmpByte <> 0 then AddError('Int2StrWithZeros2'); Str := '1234567890'; Tint := -32768; Int2StrWithZeros(Tint, Str); TmpByte := StrCmp(Str, '-32768'); if TmpByte <> 0 then AddError('Int2StrWithZeros3'); Str := '1234567890'; Tint := 32767; Int2StrWithZeros(Tint, Str); TmpByte := StrCmp(Str, '032767'); if TmpByte <> 0 then AddError('Int2StrWithZeros4'); Tint := 0; Int2Str(Tint, Str); TmpByte := StrCmp(Str, '0'); if TmpByte <> 0 then AddError('Int2Str0'); Int2StrN(Tint, Str, 3); TmpByte := StrCmp(Str, ' 0'); if TmpByte <> 0 then AddError('Int2StrN0'); Int2StrWithZeros(Tint, Str); TmpByte := StrCmp(Str, '000000'); if TmpByte <> 0 then AddError('Int2StrWZ0'); // ---------- LongIntTo -------- Str := '1234567890'; Lint := 200000; Long2Str(Lint, Str); TmpByte := StrCmp(Str, '200000'); if TmpByte <> 0 then AddError('Long2Str1'); Str := '1234567890'; Lint := -200000; Long2Str(Lint, Str); TmpByte := StrCmp(Str, '-200000'); if TmpByte <> 0 then AddError('Long2Str2'); Str := '1234567890'; Lint := 200000; Long2StrN(Lint, Str, 9); TmpByte := StrCmp(Str, ' 200000'); if TmpByte <> 0 then AddError('Long2StrN1'); Str := '1234567890'; Lint := -200000; Long2StrN(Lint, Str, 9); TmpByte := StrCmp(Str, ' -200000'); if TmpByte <> 0 then AddError('Long2StrN2'); Str2 := '12345678901234567890'; Lint := -200000; Long2StrWithZeros(Lint, Str2); TmpByte := StrCmp(Str2, '-0000200000'); if TmpByte <> 0 then AddError('Long2StrWithZeros1'); Str2 := '12345678901234567890'; Lint := 200000; Long2StrWithZeros(Lint, Str2); TmpByte := StrCmp(Str2, '00000200000'); if TmpByte <> 0 then AddError('Long2StrWithZeros2'); Lint := 0; Long2Str(Lint, Str2); TmpByte := StrCmp(Str2, '0'); if TmpByte <> 0 then AddError('Long2Str0'); Long2StrN(Lint, Str2, 3); TmpByte := StrCmp(Str2, ' 0'); if TmpByte <> 0 then AddError('Long2StrN0'); Long2StrWithZeros(Lint, Str2); TmpByte := StrCmp(Str2, '00000000000'); if TmpByte <> 0 then AddError('Long2StrWZ0'); // ---------- DwordTo ---------- DWord2Bin($AAAAAAAA, Str2); TmpByte := StrCmp(Str2, '10101010101010101010101010101010'); if TmpByte <> 0 then AddError('DWord2Bin1'); DWord2Bin($55555555, Str2); TmpByte := StrCmp(Str2, '01010101010101010101010101010101'); if TmpByte <> 0 then AddError('DWord2Bin2'); DWord2Bin($5A5A5A5A, Str2); TmpByte := StrCmp(Str2, '01011010010110100101101001011010'); if TmpByte <> 0 then AddError('DWord2Bin3'); DWord2Bin($A5A5A5A5, Str2); TmpByte := StrCmp(Str2, '10100101101001011010010110100101'); if TmpByte <> 0 then AddError('DWord2Bin4'); dWord2hex($A5A5A5A5, Str); TmpByte := StrCmp(Str, 'A5A5A5A5'); if TmpByte <> 0 then AddError('DWord2Hex1'); dWordTohex($A5A5A5A5, Str); TmpByte := StrCmp(Str, 'A5A5A5A5'); if TmpByte <> 0 then AddError('DWordToHex1'); // To // -- DWrd := 100000; DWord2Str(DWrd, Str); TmpByte := StrCmp(Str, '100000'); if TmpByte <> 0 then AddError('DWord2Str1'); DWrd := 100000; DWordToStr(DWrd, Str); // ToStr TmpByte := StrCmp(Str, ' 100000'); if TmpByte <> 0 then AddError('DWordToStr1'); DWrd := 100000; DWord2StrN(DWrd, Str, 7); TmpByte := StrCmp(Str, ' 100000'); if TmpByte <> 0 then AddError('DWord2StrN1'); DWrd := 100000; DWord2StrWithZeros(DWrd, Str2); TmpByte := StrCmp(Str2, '0000100000'); if TmpByte <> 0 then AddError('DWord2StrWithZeros1'); DWrd := 100000; DWordToStrWithZeros(DWrd, Str2); // ToStr TmpByte := StrCmp(Str2, '0000100000'); if TmpByte <> 0 then AddError('DWordToStrWithZeros1'); DWrd := 0; DWord2Str(DWrd, Str2); TmpByte := StrCmp(Str2, '0'); if TmpByte <> 0 then AddError('DWord2Str0'); DWordToStr(DWrd, Str2); // ToStr TmpByte := StrCmp(Str2, ' 0'); if TmpByte <> 0 then AddError('DWordToStr0'); DWord2StrN(DWrd, Str2, 7); TmpByte := StrCmp(Str2, ' 0'); if TmpByte <> 0 then AddError('DWord2StrN0'); DWord2StrWithZeros(DWrd, Str2); TmpByte := StrCmp(Str2, '0000000000'); if TmpByte <> 0 then AddError('DWord2StrWZ0'); DWordToStrWithZeros(DWrd, Str2); // ToStr TmpByte := StrCmp(Str2, '0000000000'); if TmpByte <> 0 then AddError('DWordToStrWZ0'); // ---------- FloatToStr -------------- standard function Flt := 3999999999.0; FloatToStr(Flt, Str2); Flt := 0.000001234; FloatToStr(Flt, Str2); Flt := 123.45; FloatToStr(Flt, Str2); Flt := 1111111111.0; FloatToStr(Flt, Str2); Flt := -1234567890.0; FloatToStr(Flt, Str2); Flt := 1.1234567890123456; FloatToStr(Flt, Str2); Flt := 0.1234567890123456; FloatToStr(Flt, Str2); Flt := 0.01234567890123456; FloatToStr(Flt, Str2); Flt := 0.00001234567890123456; FloatToStr(Flt, Str2); // ---------- Float2Str --------------- Flt := 1.1234567890123456; Float2Str(Flt, Str2, 2); TmpByte := StrCmp(Str2, '1.12'); if TmpByte <> 0 then AddError('Float2Str1'); Flt := 123.456789; Float2Str(Flt, Str2, 2); TmpByte := StrCmp(Str2, '123.46'); if TmpByte <> 0 then AddError('Float2Str2'); Flt := 0.000001234; Float2Str(Flt, Str2, 2); TmpByte := StrCmp(Str2, '0.00'); if TmpByte <> 0 then AddError('Float2Str3'); Flt := 123.56789; Float2Str(Flt, Str2, 0); TmpByte := StrCmp(Str2, '124'); if TmpByte <> 0 then AddError('Float2Str4'); Flt := -123.456789; Float2Str(Flt, Str2, 3); TmpByte := StrCmp(Str2, '-123.457'); if TmpByte <> 0 then AddError('Float2Str5'); Flt := -123.0; Float2Str(Flt, Str2, 3); TmpByte := StrCmp(Str2, '-123.000'); // -122.100 Janni? if TmpByte <> 0 then AddError('Float2Str6'); Flt := -123.0; Float2Str(Flt, Str2, 0); TmpByte := StrCmp(Str2, '-123'); if TmpByte <> 0 then AddError('Float2Str7'); // ---------- Real2Str --------------- Flt := 1.1234567890123456; Real2Str(Flt, Str2, 0, 2); TmpByte := StrCmp(Str2, '1.12'); if TmpByte <> 0 then AddError('Real2Str1'); Flt := 123.456789; Real2Str(Flt, Str2, 2, 2); TmpByte := StrCmp(Str2, '123.46'); if TmpByte <> 0 then AddError('Real2Str2'); Flt := 123.456789; Real2Str(Flt, Str2, 5, 2); TmpByte := StrCmp(Str2, ' 123.46'); if TmpByte <> 0 then AddError('Real2Str3'); Flt := 123.456789; Real2Str(Flt, Str2, 5, 0); TmpByte := StrCmp(Str2, ' 123'); if TmpByte <> 0 then AddError('Real2Str4'); Flt := 0.000001234; Real2Str(Flt, Str2, 3, 2); TmpByte := StrCmp(Str2, ' 0.00'); if TmpByte <> 0 then AddError('Real2Str5'); Flt := -1.1234567890123456; Real2Str(Flt, Str2, 0, 2); TmpByte := StrCmp(Str2, '-1.12'); if TmpByte <> 0 then AddError('Real2Str6'); Flt := -123.456789; Real2Str(Flt, Str2, 2, 2); TmpByte := StrCmp(Str2, '-123.46'); if TmpByte <> 0 then AddError('Real2Str7'); Flt := -123.456789; Real2Str(Flt, Str2, 5, 2); TmpByte := StrCmp(Str2, ' -123.46'); if TmpByte <> 0 then AddError('Real2Str8'); Flt := -123.456789; Real2Str(Flt, Str2, 5, 0); TmpByte := StrCmp(Str2, ' -123'); if TmpByte <> 0 then AddError('Real2Str9'); Flt := -0.12001234; Real2Str(Flt, Str2, 3, 3); TmpByte := StrCmp(Str2, ' -0.120'); if TmpByte <> 0 then AddError('Real2Str10'); Flt := -123.0; Real2Str(Flt, Str2, 6, 3); TmpByte := StrCmp(Str2, ' -123.000'); if TmpByte <> 0 then AddError('Real2Str11'); // ---------- HexTo ----------------- Str := 'ab'; Bte := Hex2Byte(Str); if Bte <> 171 then AddError('Hex2Byte1'); { Str := 'b'; Bte := Hex2Byte(Str); if Bte <> 11 then AddError('Hex2Byte2'); } Str := '0b'; Bte := Hex2Byte(Str); if Bte <> 11 then AddError('Hex2Byte3'); Str := 'abcd'; Wrd := Hex2Word(Str); if Wrd <> 43981 then AddError('Hex2Word1'); { Str := 'abc'; Wrd := Hex2Word(Str); if Wrd <> 2748 then AddError('Hex2Word2'); } Str := '12abcd34'; Dwrd := Hex2dWord(Str); if dwrd <> 313249076 then AddError('Hex2dWord1'); Str := '12abcd'; Dwrd := Hex2dWord(Str); if dwrd <> 1223629 then AddError('Hex2dWord2'); // ----------- StrU and StrS -------- DWrd := 25; StrU(Dwrd, Str2, 15); TmpByte := StrCmp(Str2, ' 25'); if TmpByte <> 0 then AddError('StrU1'); DWrd := 250125034; StrU(Dwrd, Str2, 5); TmpByte := StrCmp(Str2, '250125034'); if TmpByte <> 0 then AddError('StrU2'); Lint := -25; StrS(Lint, Str2, 15); TmpByte := StrCmp(Str2, ' -25'); if TmpByte <> 0 then AddError('StrS1'); // ----------- string to number ------------ Str := '145'; Wrd := Val(Str, ErrPos); if (Wrd <> 145) or (ErrPos > 0) then AddError('Val1'); Str := '-145'; Tint := Val(Str, ErrPos); if (Tint <> -145) or (ErrPos > 0) then AddError('Val2'); Str := '+155'; Wrd := Val(Str, ErrPos); if (Wrd <> 155) or (ErrPos > 0) then AddError('Val3'); Str := ' + 165'; Wrd := Val(Str, ErrPos); if (Wrd <> 165) or (ErrPos > 0) then AddError('Val4'); Str := ' -175'; Tint := Val(Str, ErrPos); if (Tint <> -175) or (ErrPos > 0) then AddError('Val5'); Str := '+14r5'; Wrd := Val(Str, ErrPos); if (Wrd <> 5) and (ErrPos <> 0) then AddError('Val6'); Str := '+14345x'; Wrd := Val(Str, ErrPos); if (Wrd <> 0) and (ErrPos <> 6) then AddError('Val7'); Str := '123'; Bte := Str2Byte(Str); if Bte <> 123 then AddError('Str2Byte1'); Str := '1234'; Wrd := Str2Word(Str); if Wrd <> 1234 then AddError('Str2Word1'); Str := '123'; Shrt := Str2Short(Str); if Shrt <> 123 then AddError('Str2Short1'); Str := '-123'; Shrt := Str2Short(Str); if Shrt <> -123 then AddError('Str2Short2'); Str := '+123'; Shrt := Str2Short(Str); if Shrt <> 123 then AddError('Str2Short3'); Str := '12345'; Tint := Str2Int(Str); // here result = 32767 if Tint <> 12345 then AddError('Str2Int1'); Str := '12b345'; Tint := Str2Int(Str); if Tint <> 345 then AddError('Str2Int1a'); Str := '+12345'; Tint := Str2Int(Str); if Tint <> 12345 then AddError('Str2Int2'); Str := '-12345'; Tint := Str2Int(Str); if Tint <> -12345 then AddError('Str2Int3'); Str := '1234567'; DWrd := Str2DWord(Str); if DWrd <> 1234567 then AddError('Str2dWord1'); Str := '1234567'; Lint := Str2Long(Str); if Lint <> 1234567 then AddError('Str2Long1'); Str := '-1234567'; Lint := Str2Long(Str); if Lint <> -1234567 then AddError('Str2Long2'); Str := '+1234567'; Lint := Str2Long(Str); if Lint <> 1234567 then AddError('Str2Long3'); Str := ' +123.456'; Flt := Str2Float(Str); if (Flt < 123.455) or (Flt > 123.457) then AddError('Str2Float1'); Str := '-123.456'; Flt := Str2Float(Str); if (Flt > -123.455) or (Flt < -123.457) then AddError('Str2Float2'); Str := '123.0'; Flt := Str2Float(Str); if (Flt < 122.999) or (Flt > 123.001) then AddError('Str2Float3'); Str := '-123.0'; Flt := Str2Float(Str); if (Flt < -123.001) or (Flt > -122.999) then AddError('Str2Float4'); Str := '0.456'; Flt := Str2Float(Str); if (Flt < 0.455) or (Flt > 0.457) then AddError('Str2Float5'); Str := '-0.456'; Flt := Str2Float(Str); if (Flt > -0.455) or (Flt < -0.457) then AddError('Str2Float6'); // ----------- other conversions ------------ Str2 := '12345678901234567890'; IpArray[0] := 122; IpArray[1] := 255; IpArray[2] := 127; IpArray[3] := 240; Ip2Str(IpArray, Str2); if StrCmp(Str2, '122.255.127.240') <> 0 then AddError('Ip2Str1'); Str2 := '12345678901234567890'; IpArray[0] := 12; IpArray[1] := 25; IpArray[2] := 27; IpArray[3] := 40; Ip2Str(IpArray, Str2); if StrCmp(Str2, '12.25.27.40') <> 0 then AddError('Ip2Str2'); Str2 := '12345678901234567890'; MACArray[0] := $78; MACArray[1] := $82; MACArray[2] := $5; MACArray[3] := $22; MACArray[4] := $7; MACArray[5] := $dd; MAC2Str(MACArray, Str2); if StrCmp(Str2, '7882052207DD') <> 0 then AddError('MAC2Str1'); Str2 := 'AABBCCDDEEFF'; Str2Mac(Str2, MACArray); if (MacArray[0] <> $AA) or (MacArray[1] <> $BB) or (MacArray[2] <> $CC) or (MacArray[3] <> $DD) or (MacArray[4] <> $EE) or (MacArray[5] <> $FF) then AddError('Str2Mac1'); Str2 := '19.168.123.55'; Str2Ip(Str2, IpArray); if (IpArray[0] <> 19) or (IpArray[1] <> 168) or (IpArray[2] <> 123) or (IpArray[3] <> 55) then AddError('Str2Ip1'); {$ENDIF} {$IFDEF OLDPROCS} {$IFDEF STRINGS} // ---------- StrLenConst and LengthConst ------------- Wrd := StrLen_Const(@ConstStr1); if Wrd <> 10 then AddError('StrLenC1'); Wrd := StrLen_Const(@ConstStr1); if Wrd <> 10 then AddError('StrLenC2'); Wrd := Length_Const(@ConstStr1); if Wrd <> 10 then AddError('LengthC1'); Wrd := Length_Const(@ConstStr1); if Wrd <> 10 then AddError('LengthC2'); // ------------ StrCatC ------------- Str := '1234567890'; Str := '12345'; StrCat_Const(Str, @ConstStr2); if StrCmp(Str, '12345abcd') <> 0 then AddError('StrCatC'); Str := '1234567890'; Str := '12345'; StrCatX_Const(Str, @ConstStr1, 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrCatCX1'); Str := '1234567890'; Str := '12345'; StrCatX_Const(Str, @ConstStr1, 9); if StrCmp(Str, '12345abc') <> 0 then AddError('StrCatCX2'); Str := '1234567890'; Str := '12345'; StrCatX_Const(Str, @ConstStr1, 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrCatCX3'); Str := '1234567890'; Str := '12345'; StrCatX_Const(Str, @ConstStr1, 9); if StrCmp(Str, '12345abc') <> 0 then AddError('StrCatCX4'); // ---------- StrCatCharX ---------------- Str := '1234567890'; Str := '12345'; StrCatCharX(Str, 'X', 11); if StrCmp(Str, '12345X') <> 0 then AddError('StrAppendSufX1'); Str := '1234567890'; Str := '12345abcd'; StrCatCharX(Str, 'X', 11); if StrCmp(Str, '12345abcdX') <> 0 then AddError('StrAppendSufX2'); Str := '12345abcde'; StrCatCharX(Str, 'X', 11); if StrCmp(Str, '12345abcde') <> 0 then AddError('StrAppendSufX3'); // ---------- strCpyC ----------- Str := '1234567890'; StrCpy_Const(Str, @ConstStr2); if StrCmp(Str, 'abcd') <> 0 then AddError('StrCpyC1'); //StrCpyX_Const Str := '1234567890'; StrCpyX_Const(Str, @ConstStr3, 11); if StrCmp(Str, 'abcdefghij') <> 0 then AddError('StrCpyCX1'); //StrCpyX_Const Str := '1234567890'; StrCpyX_Const(Str, @ConstStr3, 9); if StrCmp(Str, 'abcdefgh') <> 0 then AddError('StrCpyCX2'); // ---------- StrnCpyC ------------ Str := '1234567890'; StrnCpy_Const(Str, @ConstStr3, 5); if StrCmp(Str, 'abcde') <> 0 then AddError('StnCpyC1'); Str := '1234567890'; StrnCpyX_Const(Str, @ConstStr3, 20, 11); if StrCmp(Str, 'abcdefghij') <> 0 then AddError('StrnCpyCX1'); Str := '1234567890'; StrnCpyX_Const(Str, @ConstStr3, 20, 9); if StrCmp(Str, 'abcdefgh') <> 0 then AddError('StrnCpyCX2'); // ---------- StrChr ------------- Wrd := 0; Wrd := StrChr_Const(@ConstStr1, 'z'); if Wrd <> $FFFF then AddError('StrChrC1'); Wrd := 0; Wrd := StrChr_Const(@ConstStr1, 'c'); if Wrd <> 2 then AddError('StrChrC2'); // ---------- StrCmpC ------------- Str := 'abcd'; TmpByte := StrCmp_Const(@ConstStr2, Str); if TmpByte <> 0 then AddError('StrCmpC1'); Str := 'abc'; TmpByte := StrCmp_Const(@ConstStr2, Str); if TmpByte <= 0 then AddError('StrCmpC2'); Str := 'abcc'; TmpByte := StrCmp_Const(@ConstStr2, Str); if TmpByte <= 0 then AddError('StrCmpC3'); Str := 'abcde'; TmpByte := StrCmp_Const(@ConstStr2, Str); if TmpByte >= 0 then AddError('StrCmpC4'); Str := 'abce'; TmpByte := StrCmp_Const(@ConstStr2, Str); if TmpByte >= 0 then AddError('StrCmpC5'); // ---------- StrCmpNocase ------------- // case insensitive string compare Str := 'abc'; Str2 := 'Abc'; TmpByte := StrCmp_CI(Str, Str2); if TmpByte <> 0 then AddError('StrCmpNocase1'); Str := 'aBC'; Str2 := 'abc'; TmpByte := StrCmp_CI(Str, Str2); if TmpByte <> 0 then AddError('StrCmpNocase2'); Str := 'Cbc'; Str2 := 'bbc'; TmpByte := StrCmp_CI(Str, Str2); if TmpByte <= 0 then AddError('StrCmpNocase3'); Str := 'bbc'; Str2 := 'Cbc'; TmpByte := StrCmp_CI(Str, Str2); if TmpByte >= 0 then AddError('StrCmpNocase4'); // ---------- StrnCmp ------------ Str := 'abcdxy'; TmpByte := StrnCmp_Const(@ConstStr3, Str, 4); if TmpByte <> 0 then AddError('StrnCmp1'); Str := 'abc'; TmpByte := StrnCmp_Const(@ConstStr3, Str, 4); if TmpByte <= 0 then AddError('StrnCmp2'); Str := 'abcc'; TmpByte := StrnCmp_Const(@ConstStr3, Str, 4); if TmpByte <= 0 then AddError('StrnCmp3'); Str := 'abce'; TmpByte := StrnCmp_Const(@ConstStr3, Str, 4); if TmpByte >= 0 then AddError('StrnCmp4'); {$ENDIF} {$IFDEF CONVERSIONS} // ---------- WordTo ------------- Str := '1234567890'; Wrd := 1234; WordToStrWithZeros(Wrd, Str); // To Str TmpByte := StrCmp(Str, '01234'); if TmpByte <> 0 then AddError('WordToStrWithZeros1'); // ---------- DwordTo ---------- dWordTohexStr($A5A5A5A5, Str); TmpByte := StrCmp(Str, 'A5A5A5A5'); if TmpByte <> 0 then AddError('DWordToHex1'); // To // ------------ BCDByteToStr ----------- Bte := $31; BcdByteToStr(Bte, Str); if StrCmp(Str, '31') <> 0 then AddError('BcdByteToStr'); // ------------- WordToHexStr ----------- Wrd := $1234; WordToHexStr(Wrd, Str); if StrCmp(Str, '1234') <> 0 then AddError('WordToHexStr'); // ------------- DWordToHexStr ---------- dWordTohexStr($A5A5A5A5, Str); TmpByte := StrCmp(Str, 'A5A5A5A5'); if TmpByte <> 0 then AddError('DWordToHex'); // ---------------- ToBin --------------- ByteToBinStr($AA, Str); TmpByte := StrCmp(Str, '10101010'); if TmpByte <> 0 then AddError('Byte2Bin1'); ByteToBinStr($55, Str); TmpByte := StrCmp(Str, '01010101'); if TmpByte <> 0 then AddError('Byte2Bin2'); ByteToBinStr($5A, Str); TmpByte := StrCmp(Str, '01011010'); if TmpByte <> 0 then AddError('Byte2Bin3'); ByteToBinStr($A5, Str); TmpByte := StrCmp(Str, '10100101'); if TmpByte <> 0 then AddError('Byte2Bin4'); WordToBinStr($AAAA, Str2); TmpByte := StrCmp(Str2, '1010101010101010'); if TmpByte <> 0 then AddError('Word2Bin1'); WordToBinStr($5555, Str2); TmpByte := StrCmp(Str2, '0101010101010101'); if TmpByte <> 0 then AddError('Word2Bin2'); WordToBinStr($5A5A, Str2); TmpByte := StrCmp(Str2, '0101101001011010'); if TmpByte <> 0 then AddError('Word2Bin3'); WordToBinStr($A5A5, Str2); TmpByte := StrCmp(Str2, '1010010110100101'); if TmpByte <> 0 then AddError('Word2Bin4'); DWordToBinStr($AAAAAAAA, Str2); TmpByte := StrCmp(Str2, '10101010101010101010101010101010'); if TmpByte <> 0 then AddError('DWord2Bin1'); DWordToBinStr($55555555, Str2); TmpByte := StrCmp(Str2, '01010101010101010101010101010101'); if TmpByte <> 0 then AddError('DWord2Bin2'); DWordToBinStr($5A5A5A5A, Str2); TmpByte := StrCmp(Str2, '01011010010110100101101001011010'); if TmpByte <> 0 then AddError('DWord2Bin3'); DWordToBinStr($A5A5A5A5, Str2); TmpByte := StrCmp(Str2, '10100101101001011010010110100101'); if TmpByte <> 0 then AddError('DWord2Bin4'); {$ENDIF} {$ENDIF} // ---------- Check for Error ------ if Error then Str := 'Error' else Str := 'All Ok'; end.