Quellcode durchsuchen

+ Test for resources support.

git-svn-id: trunk@5302 -
yury vor 19 Jahren
Ursprung
Commit
95868909bd

+ 5 - 0
.gitattributes

@@ -6644,6 +6644,11 @@ tests/test/units/system/trandom.pp svneol=native#text/plain
 tests/test/units/system/trdtxt01.pp svneol=native#text/plain
 tests/test/units/system/trdtxt02.pp svneol=native#text/plain
 tests/test/units/system/trdtxt03.pp svneol=native#text/plain
+tests/test/units/system/tres.pp -text
+tests/test/units/system/tres1.RES -text
+tests/test/units/system/tres1.rc -text
+tests/test/units/system/tres1.txt -text
+tests/test/units/system/tres2.txt -text
 tests/test/units/system/tround.pp svneol=native#text/plain
 tests/test/units/system/tseg.pp svneol=native#text/plain
 tests/test/units/system/tsetstr.pp svneol=native#text/plain

+ 59 - 0
tests/test/units/system/tres.pp

@@ -0,0 +1,59 @@
+{ Test for resources support. }
+
+{%TARGET=win32,win64,wince,linux}
+
+{$mode objfpc}
+
+{$R tres1.res}
+
+procedure Fail(const Msg: string);
+begin
+  writeln(Msg);
+  Halt(1);
+end;
+
+function GetResource(ResourceName, ResourceType: PChar; PResSize: PLongInt = nil): pointer;
+var
+  hRes: TResourceHandle;
+  gRes: HGLOBAL;
+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.

BIN
tests/test/units/system/tres1.RES


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

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

+ 1 - 0
tests/test/units/system/tres1.txt

@@ -0,0 +1 @@
+test file.

+ 1 - 0
tests/test/units/system/tres2.txt

@@ -0,0 +1 @@
+Another test file.