tres3ext.pp 2.5 KB

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