tres3.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. { Test for resource enumeration functions. }
  2. {%TARGET=win32,win64,linux,freebsd,darwin,netbsd,openbsd,solaris}
  3. {$mode objfpc}
  4. uses
  5. sysutils;
  6. {$R tresb.res}
  7. procedure Fail(const Msg: string);
  8. begin
  9. writeln(Msg);
  10. Halt(1);
  11. end;
  12. type
  13. TResInfo = record
  14. name : pchar;
  15. _type : pchar;
  16. langid : word;
  17. found : boolean;
  18. end;
  19. const
  20. rescount = 3;
  21. var
  22. reslst : array[1..rescount] of TResInfo =
  23. (
  24. (name : 'TESTFILE'; _type : 'FILE'; langid : $0409; found : false),
  25. (name : 'TEST'; _type : 'TEXT'; langid : $0409; found : false),
  26. (name : 'TESTFILE'; _type : 'FILE'; langid : $0410; found : false)
  27. );
  28. function CompareDesc(d1, d2 : PChar) : boolean;
  29. begin
  30. if Is_IntResource(d1) then
  31. Result:=PtrUInt(d1)=PtrUInt(d2)
  32. else
  33. Result:=CompareChar0(d1[0],d2[0],MaxInt)=0;
  34. end;
  35. procedure ResFound(ResourceType, ResourceName : PChar; IDLanguage : word);
  36. var i : integer;
  37. begin
  38. for i:=1 to rescount do
  39. begin
  40. if CompareDesc(reslst[i].name,ResourceName) and
  41. CompareDesc(reslst[i]._type,ResourceType) and
  42. (reslst[i].langid=IDLanguage) then
  43. if reslst[i].found then
  44. Fail('Resource found twice!')
  45. else
  46. begin
  47. reslst[i].found:=true;
  48. exit;
  49. end;
  50. end;
  51. Fail('Resource not found!');
  52. end;
  53. function ResLangProc(ModuleHandle : TFPResourceHMODULE; ResourceType, ResourceName : PChar; IDLanguage : word; lParam : PtrInt) : LongBool; stdcall;
  54. begin
  55. writeln(' Lang: ',IntToHex(IDLanguage,4));
  56. Result:=true;
  57. ResFound(ResourceType,ResourceName,IDLanguage);
  58. end;
  59. function ResNameProc(ModuleHandle : TFPResourceHMODULE; ResourceType, ResourceName : PChar; lParam : PtrInt) : LongBool; stdcall;
  60. begin
  61. if Is_IntResource(ResourceName) then
  62. writeln(' Name: ',PtrUint(ResourceName))
  63. else
  64. writeln(' Name: ',ResourceName);
  65. EnumResourceLanguages(ModuleHandle,ResourceType,ResourceName,@ResLangProc,lParam);
  66. Result:=true;
  67. end;
  68. function ResTypeProc(ModuleHandle : TFPResourceHMODULE; ResourceType : PChar; lParam : PtrInt) : LongBool; stdcall;
  69. begin
  70. if Is_IntResource(ResourceType) then
  71. writeln('Type: ',PtrUint(ResourceType))
  72. else
  73. writeln('Type: ',ResourceType);
  74. EnumResourceNames(ModuleHandle,ResourceType,@ResNameProc,lParam);
  75. Result:=true;
  76. end;
  77. procedure CheckFound;
  78. var i : integer;
  79. begin
  80. for i:=1 to rescount do
  81. begin
  82. if not reslst[i].found then
  83. Fail('Resource #'+IntToStr(i)+' was not found!');
  84. end;
  85. end;
  86. procedure DoTest;
  87. begin
  88. EnumResourceTypes(HINSTANCE,@ResTypeProc,0);
  89. end;
  90. begin
  91. writeln('Resources test.');
  92. DoTest;
  93. writeln('Done.');
  94. end.