Skip to content

Commit

Permalink
Add test to check base virtual method call
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-panda committed Aug 7, 2023
1 parent a5a21bf commit 0411eb4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,35 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
EXPECT_TRUE(object) << "Failed to call the ctor.";
// Building a wrapper with a typedef decl must be possible.
Cpp::Destruct(object, Decls[1]);

Interp->declare(R"(
struct A {
virtual ~A() {}
virtual int func() {
return 1;
}
};
struct B : public A {
virtual int func() {
return 2;
}
};
)");

auto *St_A = Cpp::GetNamed("A", 0);
auto *St_B = Cpp::GetNamed("B", 0);

auto *BCtorD = Cpp::GetDefaultConstructor(St_B);
auto BCtor = Cpp::MakeFunctionCallable(BCtorD);
void *BObj = nullptr;
BCtor.Invoke(&BObj);

auto *AfuncD = Cpp::GetNamed("func", St_A);
auto Afunc = Cpp::MakeFunctionCallable(AfuncD);
int ret_func;
Afunc.Invoke(&ret_func, {nullptr, 0}, BObj);
EXPECT_EQ(ret_func, 1);
}

TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
Expand Down

0 comments on commit 0411eb4

Please sign in to comment.