mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Toy now fits into the C spec. Fixed #158 Addendum: MacOS test caught an error: error: a function declaration without a prototype is deprecated in all versions of C That took 3 attempts to fix correctly. Addendum: 'No new line at the end of file' are you shitting me?
113 lines
1.9 KiB
C
113 lines
1.9 KiB
C
#include "toy_print.h"
|
|
#include "toy_console_colors.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
int counter = 0;
|
|
|
|
void count(const char* msg) {
|
|
(void)msg;
|
|
counter++;
|
|
}
|
|
|
|
int test_callbacks(void) {
|
|
//set a custom print callback, invoke it, and reset
|
|
{
|
|
//setup
|
|
Toy_setPrintCallback(count);
|
|
|
|
//invoke
|
|
Toy_print("");
|
|
|
|
//check
|
|
if (counter != 1) {
|
|
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to set print callback\n" TOY_CC_RESET);
|
|
return -1;
|
|
}
|
|
|
|
//reset and retry
|
|
Toy_resetPrintCallback();
|
|
Toy_print("");
|
|
|
|
if (counter != 1) {
|
|
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to reset print callback\n" TOY_CC_RESET);
|
|
return -1;
|
|
}
|
|
|
|
//cleanup
|
|
counter = 0;
|
|
}
|
|
|
|
//set a custom error callback, invoke it, and reset
|
|
{
|
|
//setup
|
|
Toy_setErrorCallback(count);
|
|
|
|
//invoke
|
|
Toy_error("");
|
|
|
|
//check
|
|
if (counter != 1) {
|
|
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to set error callback\n" TOY_CC_RESET);
|
|
return -1;
|
|
}
|
|
|
|
//reset and retry
|
|
Toy_resetErrorCallback();
|
|
Toy_error("");
|
|
|
|
if (counter != 1) {
|
|
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to reset error callback\n" TOY_CC_RESET);
|
|
return -1;
|
|
}
|
|
|
|
//cleanup
|
|
counter = 0;
|
|
}
|
|
|
|
//set a custom assert failure callback, invoke it, and reset
|
|
{
|
|
//setup
|
|
Toy_setAssertFailureCallback(count);
|
|
|
|
//invoke
|
|
Toy_assertFailure("");
|
|
|
|
//check
|
|
if (counter != 1) {
|
|
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to set assert failure callback\n" TOY_CC_RESET);
|
|
return -1;
|
|
}
|
|
|
|
//reset and retry
|
|
Toy_resetAssertFailureCallback();
|
|
Toy_assertFailure("");
|
|
|
|
if (counter != 1) {
|
|
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to reset assert failure callback\n" TOY_CC_RESET);
|
|
return -1;
|
|
}
|
|
|
|
//cleanup
|
|
counter = 0;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main(void) {
|
|
//run each test set, returning the total errors given
|
|
int total = 0, res = 0;
|
|
|
|
{
|
|
res = test_callbacks();
|
|
if (res == 0) {
|
|
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
|
|
}
|
|
total += res;
|
|
}
|
|
|
|
return total;
|
|
}
|
|
|