summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/tsafecall4.pp
blob: 2a6e0cc142d39a59790075a6edc74894266179ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{ %TARGET=win32,win64,wince,linux}
program tsafecall4;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils;

procedure SafecallProcedure(AParam1,AParam2: integer); safecall;
var i,j: double;
begin
  if (AParam1<>$123456) or (AParam2<>$654321) then
    halt(1);
  i := 1;
  j := 0;
  // division by zero, but no exception should be raised. Instead the function
  // result has to be <> 0
  i := i/j;
end;

function SafecallFunction(AParam1,AParam2: integer): string; safecall;
begin
  if (AParam1<>$123456) or (AParam2<>$654321) then
    halt(2);
  raise exception.create('Ignore and return non-zero');
end;

var
  s : string;
  pass : boolean;

begin
  pass := false;
  try
    SafecallProcedure($123456,$654321);
  except
    on E: ESafecallException do
      pass := true;
  end;
  if not pass then
    halt(11);

  pass := false;
  try
    s := SafecallFunction($123456,$654321);
  except
    on E: ESafecallException do
      pass := true;
  end;
  if not pass then
    halt(12);
end.