mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Extra tests for interface invoking and dynamic boxing
This commit is contained in:
parent
186462e0ac
commit
7036433e5d
2 changed files with 53 additions and 3 deletions
|
@ -22,6 +22,7 @@ namespace Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Reflect(.DynamicBoxing)]
|
||||
struct StructB : StructA, IHashable
|
||||
{
|
||||
public int mB = 200;
|
||||
|
@ -60,12 +61,31 @@ namespace Tests
|
|||
Test.Assert(GetFromIFace(iface1) == 2100);
|
||||
Test.Assert(valB.mA == 1100); // This should copy values
|
||||
|
||||
StructC valC = .();
|
||||
|
||||
var boxedVal = scope box valA;
|
||||
iface0 = boxedVal;
|
||||
|
||||
#unwarn
|
||||
var boxedStr = scope box "Test";
|
||||
IHashable ihash = boxedStr;
|
||||
|
||||
Variant saVariant = .Create(valA);
|
||||
var saObj = saVariant.GetBoxed().Value;
|
||||
delete saObj;
|
||||
saVariant.Dispose();
|
||||
|
||||
Variant sbVariant = .Create(valB);
|
||||
var scObj = sbVariant.GetBoxed().Value;
|
||||
IHashable ih = scObj;
|
||||
Test.Assert(ih.GetHashCode() == 200);
|
||||
delete scObj;
|
||||
sbVariant.Dispose();
|
||||
|
||||
Variant scVariant = .Create(valC);
|
||||
var scObjResult = scVariant.GetBoxed();
|
||||
Test.Assert(scObjResult case .Err);
|
||||
scVariant.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -108,7 +108,14 @@ namespace Tests
|
|||
}
|
||||
|
||||
[Reflect, AlwaysInclude(IncludeAllMethods=true)]
|
||||
struct StructA
|
||||
interface IFaceA
|
||||
{
|
||||
void MethodA0();
|
||||
int MethodA1(int a, float b);
|
||||
}
|
||||
|
||||
[Reflect, AlwaysInclude(IncludeAllMethods=true)]
|
||||
struct StructA : IFaceA
|
||||
{
|
||||
public int mA;
|
||||
public int mB;
|
||||
|
@ -123,6 +130,16 @@ namespace Tests
|
|||
mB += a;
|
||||
return a + mA * 100;
|
||||
}
|
||||
|
||||
public void MethodA0()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public int MethodA1(int a, float b)
|
||||
{
|
||||
return mA + a + (int)b;
|
||||
}
|
||||
}
|
||||
|
||||
struct StructC
|
||||
|
@ -473,10 +490,14 @@ namespace Tests
|
|||
result.Dispose();
|
||||
|
||||
case 2:
|
||||
Test.Assert(methodInfo.Name == "__BfCtor");
|
||||
Test.Assert(methodInfo.Name == "MethodA0");
|
||||
case 3:
|
||||
Test.Assert(methodInfo.Name == "__Equals");
|
||||
Test.Assert(methodInfo.Name == "MethodA1");
|
||||
case 4:
|
||||
Test.Assert(methodInfo.Name == "__BfCtor");
|
||||
case 5:
|
||||
Test.Assert(methodInfo.Name == "__Equals");
|
||||
case 6:
|
||||
Test.Assert(methodInfo.Name == "__StrictEquals");
|
||||
default:
|
||||
Test.FatalError(); // Shouldn't have any more
|
||||
|
@ -484,6 +505,15 @@ namespace Tests
|
|||
|
||||
methodIdx++;
|
||||
}
|
||||
|
||||
let ifaceType = typeof(IFaceA);
|
||||
let methodA1 = ifaceType.GetMethod("MethodA1").Value;
|
||||
var saVariant = Variant.Create(sa);
|
||||
defer saVariant.Dispose();
|
||||
var result = methodA1.Invoke(saVariant, .Create(1000), .Create(2000.f)).Value;
|
||||
Test.Assert(result.Get<int>() == 3012);
|
||||
result = methodA1.Invoke(.Create(&sa), .Create(1000), .Create(2000.f)).Value;
|
||||
Test.Assert(result.Get<int>() == 3012);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue