Browse Source

+ test for windows which tests if an .rc file can be really compiled into an .res file

git-svn-id: trunk@27042 -
florian 11 years ago
parent
commit
c9f7c7d88c
3 changed files with 65 additions and 0 deletions
  1. 2 0
      .gitattributes
  2. 61 0
      tests/test/units/system/tres5.pp
  3. 2 0
      tests/test/units/system/tres5.rc

+ 2 - 0
.gitattributes

@@ -12334,6 +12334,8 @@ tests/test/units/system/tres3.pp svneol=native#text/plain
 tests/test/units/system/tres3ext.pp svneol=native#text/plain
 tests/test/units/system/tres3ext.pp svneol=native#text/plain
 tests/test/units/system/tres4.pp svneol=native#text/plain
 tests/test/units/system/tres4.pp svneol=native#text/plain
 tests/test/units/system/tres4.res -text
 tests/test/units/system/tres4.res -text
+tests/test/units/system/tres5.pp svneol=native#text/plain
+tests/test/units/system/tres5.rc svneol=native#text/plain
 tests/test/units/system/tresb.rc svneol=native#text/plain
 tests/test/units/system/tresb.rc svneol=native#text/plain
 tests/test/units/system/tresb.res -text
 tests/test/units/system/tresb.res -text
 tests/test/units/system/tresext.pp svneol=native#text/plain
 tests/test/units/system/tresext.pp svneol=native#text/plain

+ 61 - 0
tests/test/units/system/tres5.pp

@@ -0,0 +1,61 @@
+{ Test for resources support from .rc files. }
+
+{%TARGET=win32,win64}
+
+{$mode objfpc}
+
+uses sysutils;
+
+{$R tres5.rc}
+
+procedure Fail(const Msg: string);
+begin
+  writeln(Msg);
+  Halt(1);
+end;
+
+function GetResource(ResourceName, ResourceType: PChar; PResSize: PLongInt = nil): pointer;
+var
+  hRes: TFPResourceHandle;
+  gRes: TFPResourceHGLOBAL;
+begin
+  hRes:=FindResource(HINSTANCE, ResourceName, ResourceType);
+  if hRes = 0 then
+    Fail('FindResource failed.');
+  gRes:=LoadResource(HINSTANCE, hRes);
+  if gRes = 0 then
+    Fail('LoadResource failed.');
+  if PResSize <> nil then begin
+    PResSize^:=SizeofResource(HINSTANCE, hRes);
+    if PResSize^ = 0 then
+      Fail('SizeofResource failed.');
+  end;
+  Result:=LockResource(gRes);
+  if Result = nil then
+    Fail('LockResource failed.');
+end;
+
+procedure DoTest;
+var
+  s: string;
+  p: PChar;
+  sz: longint;
+begin
+  p:=GetResource('TestFile', 'FILE', @sz);
+  SetString(s, p, sz);
+  if s <> 'test file.' then
+    Fail('Invalid resource loaded.');
+  writeln(s);
+
+  p:=GetResource('Test', 'TEXT', @sz);
+  SetString(s, p, sz);
+  if s <> 'Another test file.' then
+    Fail('Invalid resource loaded.');
+  writeln(s);
+end;
+
+begin
+  writeln('Resources test.');
+  DoTest;
+  writeln('Done.');
+end.

+ 2 - 0
tests/test/units/system/tres5.rc

@@ -0,0 +1,2 @@
+TestFile FILE "tres1.txt"
+Test TEXT "tres2.txt"