Skip to content

Commit

Permalink
[Tests] CppInterOp: Expect get_wrapper_code to fail making a wrapper …
Browse files Browse the repository at this point in the history
…for a template function

Signed-off-by: Shreyas Atre <shreyasatre16@gmail.com>
  • Loading branch information
SAtacker committed Jan 3, 2024
1 parent 0e75241 commit 42b0833
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ TEST(FunctionReflectionTest, IsTemplatedFunction) {
TEST(FunctionReflectionTest, ExistsFunctionTemplate) {
std::vector<Decl*> Decls;
std::string code = R"(
template <typename T> void f(T a);
template<typename T>
void f(T a) {}
Expand All @@ -405,8 +407,8 @@ TEST(FunctionReflectionTest, ExistsFunctionTemplate) {

GetAllTopLevelDecls(code, Decls);
EXPECT_TRUE(Cpp::ExistsFunctionTemplate("f", 0));
EXPECT_TRUE(Cpp::ExistsFunctionTemplate("f", Decls[1]));
EXPECT_FALSE(Cpp::ExistsFunctionTemplate("f", Decls[2]));
EXPECT_TRUE(Cpp::ExistsFunctionTemplate("f", Decls[2]));
EXPECT_FALSE(Cpp::ExistsFunctionTemplate("f", Decls[3]));
}

TEST(FunctionReflectionTest, IsPublicMethod) {
Expand Down Expand Up @@ -636,6 +638,9 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
Interp->process(R"(
#include <string>
void f2(std::string &s) { printf("%s", s.c_str()); };
template<typename T>
int func(T a){return 42;}
)");

Interp->process(R"(
Expand All @@ -652,14 +657,17 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
Cpp::JitCall FCI2 =
Cpp::MakeFunctionCallable(Cpp::GetNamed("f2"));
EXPECT_TRUE(FCI2.getKind() == Cpp::JitCall::kGenericCall);
Cpp::JitCall FUNC =
Cpp::MakeFunctionCallable(Cpp::GetNamed("func"));
EXPECT_TRUE(FCI2.getKind() == Cpp::JitCall::kGenericCall);
Cpp::JitCall FCI3 =
Cpp::MakeFunctionCallable(Cpp::GetNamed("f3", Cpp::GetNamed("NS")));
EXPECT_TRUE(FCI3.getKind() == Cpp::JitCall::kGenericCall);
Cpp::JitCall FCI4 =
Cpp::MakeFunctionCallable(Cpp::GetNamed("f4", Cpp::GetNamed("NS")));
EXPECT_TRUE(FCI4.getKind() == Cpp::JitCall::kGenericCall);

int i = 9, ret1, ret3, ret4;
int i = 9, ret1, ret3, ret4, ret5;
std::string s("Hello World!\n");
void *args0[1] = { (void *) &i };
void *args1[1] = { (void *) &s };
Expand All @@ -678,6 +686,9 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
FCI4.Invoke(&ret4);
EXPECT_EQ(ret4, 4);

FUNC.Invoke(&ret5, {args0, /*args_size=*/1});
EXPECT_EQ(ret5,42);

// FIXME: Do we need to support private ctors?
Interp->process(R"(
class C {
Expand Down

0 comments on commit 42b0833

Please sign in to comment.