Browse Source

* fix for Mantis #35693: IsOrdinal also needs to return true for enums (with that AsOrdinal will work correctly as well)
* extended RTTI test by a test for enums

git-svn-id: trunk@42219 -

svenbarth 6 years ago
parent
commit
a2a403e2e5
2 changed files with 21 additions and 1 deletions
  1. 1 1
      packages/rtl-objpas/src/inc/rtti.pp
  2. 20 0
      packages/rtl-objpas/tests/tests.rtti.pas

+ 1 - 1
packages/rtl-objpas/src/inc/rtti.pp

@@ -1548,7 +1548,7 @@ end;
 
 function TValue.IsOrdinal: boolean;
 begin
-  result := (Kind in [tkInteger, tkInt64, tkQWord, tkBool]) or
+  result := (Kind in [tkInteger, tkInt64, tkQWord, tkBool, tkEnumeration]) or
             ((Kind in [tkClass, tkClassRef, tkInterfaceRaw, tkUnknown]) and not Assigned(FData.FAsPointer));
 end;
 

+ 20 - 0
packages/rtl-objpas/tests/tests.rtti.pas

@@ -60,6 +60,7 @@ type
     procedure TestMakeExtended;
     procedure TestMakeCurrency;
     procedure TestMakeComp;
+    procedure TestMakeEnum;
 
     procedure TestDataSize;
     procedure TestDataSizeEmpty;
@@ -665,6 +666,25 @@ begin
   CheckFalse(hadexcept, 'Had unsigned type conversion exception');
 end;
 
+procedure TTestCase1.TestMakeEnum;
+var
+  e: TTestEnum;
+  v: TValue;
+begin
+  e := te1;
+
+  TValue.Make(@e, TypeInfo(e), v);
+  Check(not v.IsClass);
+  Check(not v.IsArray);
+  Check(not v.IsEmpty);
+  Check(not v.IsOpenArray);
+  Check(not v.IsObject);
+  Check(v.IsOrdinal);
+
+  Check(v.GetReferenceToRawData <> @e);
+  Check(TTestEnum(v.AsOrdinal) = te1);
+end;
+
 procedure TTestCase1.TestGetIsReadable;
 var
   c: TRttiContext;