summaryrefslogtreecommitdiff
path: root/tests/test/trtti13.pp
blob: 98acf0e54378a28c9b2d798d1dd2184d6515a782 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
program trtti13;

uses
  TypInfo;

var
  error: LongInt = 0;

const
  RangedInt64Min = $FFFFFFFF00000000;
  RangedInt64Max = $100000000;

  RangedQWordMin = QWord($100000000);
  RangedQWordMax = QWord($8000000000000000);

type
  TRangedInt64 = RangedInt64Min..RangedInt64Max;
  TRangedQWord = RangedQWordMin..RangedQWordMax;

procedure TestOrdTypeInfo(aTI: PTypeInfo; aTypeKind: TTypeKind; aOrdType: TOrdType);
var
  td: PTypeData;
begin
  Inc(error);
  if aTI^.Kind <> aTypeKind then
    Halt(error);

  td := GetTypeData(aTI);

  Inc(error);
  if td^.OrdType <> aOrdType then
    Halt(error);
end;

procedure TestMinMax64(aTI: PTypeInfo; aMin, aMax: Int64);
var
  td: PTypeData;
begin
  td := GetTypeData(aTI);

  Inc(error);
  if (td^.OrdType=otSQWord) and (td^.MinInt64Value<>Int64(aMin)) then
    Halt(error);
  if (td^.OrdType=otUQWord) and (td^.MinQWordValue<>QWord(aMin)) then
    Halt(error);

  Inc(error);
  if (td^.OrdType=otSQWord) and (td^.MaxInt64Value<>Int64(aMax)) then
    Halt(error);
  if (td^.OrdType=otUQWord) and (td^.MaxQWordValue<>QWord(aMax)) then
    Halt(error);
end;

begin
  TestOrdTypeInfo(PTypeInfo(TypeInfo(Int8)), tkInteger, otSByte);
  TestOrdTypeInfo(PTypeInfo(TypeInfo(Int16)), tkInteger, otSWord);
  TestOrdTypeInfo(PTypeInfo(TypeInfo(Int32)), tkInteger, otSLong);
  TestOrdTypeInfo(PTypeInfo(TypeInfo(Int64)), tkInt64, otSQWord);

  TestOrdTypeInfo(PTypeInfo(TypeInfo(UInt8)), tkInteger, otUByte);
  TestOrdTypeInfo(PTypeInfo(TypeInfo(UInt16)), tkInteger, otUWord);
  TestOrdTypeInfo(PTypeInfo(TypeInfo(UInt32)), tkInteger, otULong);
  TestOrdTypeInfo(PTypeInfo(TypeInfo(UInt64)), tkQWord, otUQWord);

  TestMinMax64(PTypeInfo(TypeInfo(Int64)), Low(Int64), High(Int64));
  TestMinMax64(PTypeInfo(TypeInfo(TRangedInt64)), RangedInt64Min, RangedInt64Max);
  TestMinMax64(PTypeInfo(TypeInfo(QWord)), Int64(Low(QWord)), Int64(High(QWord)));
  TestMinMax64(PTypeInfo(TypeInfo(TRangedQWord)), Int64(RangedQWordMin), Int64(RangedQWordMax));
end.