Skip to content

Commit

Permalink
Merge pull request #2 from greenliquidlight/test
Browse files Browse the repository at this point in the history
Change name for callback register fn
  • Loading branch information
greenliquidlight authored Nov 20, 2023
2 parents a1d7218 + 767d2c5 commit 83cd68b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ CTestTestfile.cmake
_deps
build
/.vs
/.vscode
2 changes: 1 addition & 1 deletion include/C_Callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DLL_EXPORT CallbackFunction printNumberInHex(int number, char* buffer, size_t bu

// Function that takes a function pointer as an argument and
// set the callback function to the one passed in
DLL_EXPORT void setCallback(CallbackFunction callback);
DLL_EXPORT void registerCallback(CallbackFunction callback);

// Run the callback function with the given number
DLL_EXPORT void runCallback(int number, char* buffer, size_t bufferSize);
Expand Down
2 changes: 1 addition & 1 deletion src/C_Callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CallbackFunction printNumberInHex(int number, char* buffer, size_t bufferSize)

// Function that takes a function pointer as an argument and
// set the callback function to the one passed in
void setCallback(CallbackFunction callback)
void registerCallback(CallbackFunction callback)
{
callbackFunction = callback;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_C_Callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ TEST(C_Callback, testPrintNumberInHex)
int number = 42;

// Test when callback function is not set
setCallback(NULL);
registerCallback(NULL);
runCallback(number, buffer, sizeof(buffer));
printf("Callback Function (NULL): %s\n", buffer);
// Add assertions to check the output
ASSERT_STREQ(buffer, "No callback function set\n");

// Test when callback function is set
setCallback((CallbackFunction) printNumberInDec);
registerCallback((CallbackFunction) printNumberInDec);
runCallback(number, buffer, sizeof(buffer));
printf("Callback Function (printNumberInDec): %s\n", buffer);
// Add assertions to check the output
ASSERT_STREQ(buffer, "Number: 42\n");

// Test when callback function is set
setCallback((CallbackFunction)printNumberInHex);
registerCallback((CallbackFunction)printNumberInHex);
runCallback(number, buffer, sizeof(buffer));
printf("Callback Function (printNumberInDec): %s\n", buffer);
// Add assertions to check the output
Expand Down

0 comments on commit 83cd68b

Please sign in to comment.