gsetrefcounttest.pp 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {$mode objfpc}
  2. unit gsetrefcounttest;
  3. interface
  4. uses fpcunit, testregistry, gset, gutil;
  5. type
  6. arr = class
  7. a:longint;
  8. end;
  9. lll=class
  10. class function c(a,b: arr):boolean;
  11. end;
  12. type setlli=specialize RBSet<arr,lll>;
  13. type TGSetRefCountTest = class(TTestCase)
  14. Published
  15. procedure SetTest;
  16. public
  17. procedure Setup;override;
  18. private
  19. data:setlli;
  20. end;
  21. implementation
  22. class function lll.c(a,b: arr):boolean;
  23. begin
  24. c:=a.a<b.a;
  25. end;
  26. procedure TGSetRefCountTest.SetTest;
  27. var x:arr; i:longint;
  28. it:setlli.pnode;
  29. begin
  30. for i:=0 to 20000 do begin
  31. x:=arr.create;
  32. x.a:=i;
  33. {code should crash on this insert}
  34. data.insert(x);
  35. end;
  36. it:=data.min;
  37. while it<>nil do begin
  38. writeln(it^.data.a);
  39. it:=data.next(it);
  40. end;
  41. end;
  42. procedure TGSetRefCountTest.Setup;
  43. begin
  44. data:=setlli.create;
  45. end;
  46. initialization
  47. RegisterTest(TGSetRefCountTest);
  48. end.