twide4.pp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {$ifdef fpc}
  2. {$mode objfpc}
  3. {$endif fpc}
  4. uses
  5. {$ifdef unix}
  6. cthreads, cwstring,
  7. {$endif}
  8. Classes, SysUtils;
  9. type
  10. tc = class(tthread)
  11. orgstr: ansistring;
  12. cnvstr: widestring;
  13. constructor create(const s: ansistring; const w: widestring);
  14. procedure execute; override;
  15. end;
  16. const
  17. // string with an invalid utf-8 code sequence
  18. str1 = #$c1#$34'Życie'#$c1#$34' jest jak papier '#$c1#$34'toaletowy'#$c1#$34' : długie, szare i '#$c1#$34'do'#$c1#$34' dupy';
  19. str2 = 'Życie '#$c1#$34'jest'#$c1#$34' jak papier toaletowy : '#$c1#$34'długie'#$c1#$34', szare i do '#$c1#$34'dupy'#$c1#$34'222222222222222222222222222222222222222222222222';
  20. str3 = 'Życie jest '#$c1#$34'jak'#$c1#$34' papier 333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 toaletowy : długie, '#$c1#$34'szare'#$c1#$34' i do dupy';
  21. str4 = 'Życie jest 4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 jak '#$c1#$34'papier'#$c1#$34' toaletowy : długie, szare '#$c1#$34'i'#$c1#$34' do dupy';
  22. count = 20000;
  23. var
  24. wstr: widestring;
  25. // cnvstr: ansistring;
  26. error: boolean;
  27. constructor tc.create(const s: ansistring; const w: widestring);
  28. begin
  29. orgstr:=s;
  30. cnvstr:=w;
  31. inherited create(true);
  32. end;
  33. procedure tc.execute;
  34. var
  35. i: longint;
  36. w: widestring;
  37. begin
  38. for i := 1 to count do
  39. begin
  40. w:=orgstr;
  41. if (w<>cnvstr) then
  42. error:=true;
  43. end;
  44. end;
  45. var
  46. a: array[1..4] of tc;
  47. w1,w2,w3,w4: widestring;
  48. cnvstr: ansistring;
  49. begin
  50. error:=false;
  51. cnvstr:=str1;
  52. w1:=cnvstr;
  53. cnvstr:=str2;
  54. w2:=cnvstr;
  55. cnvstr:=str3;
  56. w3:=cnvstr;
  57. cnvstr:=str4;
  58. w4:=cnvstr;
  59. writeln(w1);
  60. writeln(w2);
  61. writeln(w3);
  62. writeln(w4);
  63. a[1]:=tc.create(str1,w1);
  64. a[2]:=tc.create(str2,w2);
  65. a[3]:=tc.create(str3,w3);
  66. a[4]:=tc.create(str4,w4);
  67. a[1].resume;
  68. a[2].resume;
  69. a[3].resume;
  70. a[4].resume;
  71. a[1].waitfor;
  72. a[2].waitfor;
  73. a[3].waitfor;
  74. a[4].waitfor;
  75. a[1].free;
  76. a[2].free;
  77. a[3].free;
  78. a[4].free;
  79. if error then
  80. halt(1);
  81. end.