Skip to content

Commit 2406c42

Browse files
committed
Improve the test coverage of the C API -- Take 2
1 parent 4e3541c commit 2406c42

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ namespace Cpp {
783783
return false;
784784
}
785785

786-
TCppFunction_t GetDefaultConstructor(compat::Interpreter& interp, TCppScope_t scope) {
786+
TCppFunction_t GetDefaultConstructor(compat::Interpreter& interp,
787+
TCppScope_t scope) {
787788
if (!HasDefaultConstructor(scope))
788789
return nullptr;
789790

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ TEST(FunctionReflectionTest, HasDefaultConstructor) {
161161
EXPECT_TRUE(Cpp::HasDefaultConstructor(Decls[0]));
162162
EXPECT_TRUE(Cpp::HasDefaultConstructor(Decls[1]));
163163
EXPECT_FALSE(Cpp::HasDefaultConstructor(Decls[3]));
164+
165+
// C API
166+
auto I = clang_createInterpreterFromRawPtr(Cpp::GetInterpreter());
167+
EXPECT_TRUE(clang_hasDefaultConstructor(make_scope(Decls[0], I)));
168+
EXPECT_TRUE(clang_hasDefaultConstructor(make_scope(Decls[1], I)));
169+
EXPECT_FALSE(clang_hasDefaultConstructor(make_scope(Decls[3], I)));
170+
// Clean up resources
171+
clang_Interpreter_takeInterpreterAsPtr(I);
172+
clang_Interpreter_dispose(I);
164173
}
165174

166175
TEST(FunctionReflectionTest, GetDestructor) {
@@ -189,6 +198,14 @@ TEST(FunctionReflectionTest, GetDestructor) {
189198
EXPECT_TRUE(DeletedDtor);
190199
EXPECT_TRUE(Cpp::IsFunctionDeleted(DeletedDtor));
191200
EXPECT_FALSE(Cpp::GetDestructor(Decls[3]));
201+
202+
// C API
203+
auto I = clang_createInterpreterFromRawPtr(Cpp::GetInterpreter());
204+
EXPECT_TRUE(clang_getDestructor(make_scope(Decls[0], I)).data[0]);
205+
EXPECT_TRUE(clang_getDestructor(make_scope(Decls[1], I)).data[0]);
206+
// Clean up resources
207+
clang_Interpreter_takeInterpreterAsPtr(I);
208+
clang_Interpreter_dispose(I);
192209
}
193210

194211
TEST(FunctionReflectionTest, GetFunctionsUsingName) {
@@ -509,6 +526,17 @@ TEST(FunctionReflectionTest, IsTemplatedFunction) {
509526
EXPECT_FALSE(Cpp::IsTemplatedFunction(Decls[3]));
510527
EXPECT_FALSE(Cpp::IsTemplatedFunction(SubDeclsC1[1]));
511528
EXPECT_TRUE(Cpp::IsTemplatedFunction(SubDeclsC1[2]));
529+
530+
// C API
531+
auto I = clang_createInterpreterFromRawPtr(Cpp::GetInterpreter());
532+
EXPECT_FALSE(clang_isTemplatedFunction(make_scope(Decls[0], I)));
533+
EXPECT_TRUE(clang_isTemplatedFunction(make_scope(Decls[1], I)));
534+
EXPECT_FALSE(clang_isTemplatedFunction(make_scope(Decls[3], I)));
535+
EXPECT_FALSE(clang_isTemplatedFunction(make_scope(SubDeclsC1[1], I)));
536+
EXPECT_TRUE(clang_isTemplatedFunction(make_scope(SubDeclsC1[2], I)));
537+
// Clean up resources
538+
clang_Interpreter_takeInterpreterAsPtr(I);
539+
clang_Interpreter_dispose(I);
512540
}
513541

514542
TEST(FunctionReflectionTest, ExistsFunctionTemplate) {
@@ -529,6 +557,14 @@ TEST(FunctionReflectionTest, ExistsFunctionTemplate) {
529557
EXPECT_TRUE(Cpp::ExistsFunctionTemplate("f", 0));
530558
EXPECT_TRUE(Cpp::ExistsFunctionTemplate("f", Decls[1]));
531559
EXPECT_FALSE(Cpp::ExistsFunctionTemplate("f", Decls[2]));
560+
561+
// C API
562+
auto I = clang_createInterpreterFromRawPtr(Cpp::GetInterpreter());
563+
EXPECT_TRUE(clang_existsFunctionTemplate("f", make_scope(Decls[1], I)));
564+
EXPECT_FALSE(clang_existsFunctionTemplate("f", make_scope(Decls[2], I)));
565+
// Clean up resources
566+
clang_Interpreter_takeInterpreterAsPtr(I);
567+
clang_Interpreter_dispose(I);
532568
}
533569

534570
TEST(FunctionReflectionTest, InstantiateTemplateFunctionFromString) {

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "clang/Basic/Version.h"
1515

16+
#include <clang-c/CXErrorCode.h>
1617
#include "clang-c/CXCppInterOp.h"
1718

1819
#include "llvm/ADT/SmallString.h"
@@ -122,10 +123,10 @@ TEST(InterpreterTest, CreateInterpreter) {
122123
clang_Interpreter_addIncludePath(CXI, "dummy");
123124
clang_Interpreter_declare(CXI, "#include <iostream>", false);
124125
clang_Interpreter_process(CXI, "int c = 42;");
125-
auto CXV = clang_createValue();
126+
auto* CXV = clang_createValue();
126127
auto Res = clang_Interpreter_evaluate(CXI, "c", CXV);
127128
EXPECT_EQ(Res, CXError_Success);
128-
129+
129130
clang_Value_dispose(CXV);
130131
auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);
131132
EXPECT_EQ(I, I2);

0 commit comments

Comments
 (0)