85 lines
1.5 KiB
C
85 lines
1.5 KiB
C
/**
|
|
* Copyright (c) 2023 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "assert.h"
|
|
|
|
#ifndef ASSERTIONS_FAKED
|
|
void assertTrueImpl(
|
|
const char *file,
|
|
const int32_t line,
|
|
const bool x,
|
|
const char *message
|
|
) {
|
|
if(x != true) {
|
|
fprintf(
|
|
stderr,
|
|
"Assertion Failed in %s:%i\n\n%s\n",
|
|
file,
|
|
line,
|
|
message
|
|
);
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void assertFalseImpl(
|
|
const char *file,
|
|
const int32_t line,
|
|
bool x,
|
|
const char *message
|
|
) {
|
|
assertTrueImpl(file, line, !x, message);
|
|
}
|
|
|
|
void assertUnreachableImpl(
|
|
const char *file,
|
|
const int32_t line,
|
|
const char *message
|
|
) {
|
|
assertTrueImpl(file, line, false, message);
|
|
}
|
|
|
|
void assertNotNullImpl(
|
|
const char *file,
|
|
const int32_t line,
|
|
const void *pointer,
|
|
const char *message
|
|
) {
|
|
assertTrueImpl(
|
|
file,
|
|
line,
|
|
pointer != NULL,
|
|
message
|
|
);
|
|
|
|
// Ensure we can touch it
|
|
volatile char temp;
|
|
temp = *((char*)pointer);
|
|
}
|
|
|
|
void assertNullImpl(
|
|
const char *file,
|
|
const int32_t line,
|
|
const void *pointer,
|
|
const char *message
|
|
) {
|
|
assertTrueImpl(
|
|
file,
|
|
line,
|
|
pointer == NULL,
|
|
message
|
|
);
|
|
}
|
|
|
|
void assertDeprecatedImpl(
|
|
const char *file,
|
|
const int32_t line,
|
|
const char *message
|
|
) {
|
|
assertUnreachableImpl(file, line, message);
|
|
}
|
|
#endif |