Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UT for setDestructorCallback #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/test_openclhpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4517,4 +4517,49 @@ void testgetObjectInfo() {
TEST_ASSERT_EQUAL(type, CL_GL_OBJECT_BUFFER);
TEST_ASSERT_EQUAL(bufobj, 0);
}
#if CL_HPP_TARGET_OPENCL_VERSION >= 300
static void CL_CALLBACK test_context_destructor_callback(
cl_context,
void*)
{
}

static cl_int clSetContextDestructorCallback_testsetDestructorCallback(
cl_context context, cmock_cl_func_ptr3 pfn_notify, void *user_data,
int num_calls) {
TEST_ASSERT_EQUAL_PTR(context, make_context(0));
TEST_ASSERT_EQUAL_PTR(user_data, nullptr);
TEST_ASSERT_EQUAL(0, num_calls);
if(test_context_destructor_callback == pfn_notify)
{
return CL_SUCCESS;
}
else
{
return CL_INVALID_VALUE;
}
}

void testsetDestructorCallbackNull() {
cl_int ret = 0;
void(CL_CALLBACK * pfn_notify)(cl_context, void *) = nullptr;

clSetContextDestructorCallback_StubWithCallback(
clSetContextDestructorCallback_testsetDestructorCallback);
ret = contextPool[0].setDestructorCallback(pfn_notify);
TEST_ASSERT_EQUAL(CL_INVALID_VALUE, ret);
}

void testsetDestructorCallbackNotNull() {
cl_int ret = 0;

clSetContextDestructorCallback_StubWithCallback(
clSetContextDestructorCallback_testsetDestructorCallback);
ret = contextPool[0].setDestructorCallback(test_context_destructor_callback);
TEST_ASSERT_EQUAL(CL_SUCCESS, ret);
}
#else
void testsetDestructorCallbackNull() {}
void testsetDestructorCallbackNotNull() {}
#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
} // extern "C"