117 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/**
 | 
						|
 * Copyright (c) 2022 Dominic Masters
 | 
						|
 * 
 | 
						|
 * This software is released under the MIT License.
 | 
						|
 * https://opensource.org/licenses/MIT
 | 
						|
 */
 | 
						|
 | 
						|
#pragma once
 | 
						|
#include "dawn.h"
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a given statement must evaluate to true or the assertion fails
 | 
						|
 * and the game will close semi-gracefully.
 | 
						|
 * 
 | 
						|
 * @param file String filename of the file that has the assertion.
 | 
						|
 * @param line Integer line number within the file that the assertion is on.
 | 
						|
 * @param func Called function that has the assertion.
 | 
						|
 * @param result The statement that must equate to true.
 | 
						|
 * @param message Message (sprintf format) to send to the stdout.
 | 
						|
 * @param ... Varargs of the sprintf arguments.
 | 
						|
 */
 | 
						|
void assertTrueImplement(
 | 
						|
  const char *file,
 | 
						|
  const int32_t line,
 | 
						|
  const char *func,
 | 
						|
  const bool_t result,
 | 
						|
  const char *message,
 | 
						|
  ...
 | 
						|
);
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a statement must be true in order for the assertion to not cause
 | 
						|
 * an error. Basically this is a throw statement in disguise.
 | 
						|
 * 
 | 
						|
 * @param statement Statement of the assertion.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertTrue(...) assertTrueImplement( \
 | 
						|
  __FILE__, __LINE__, __func__, __VA_ARGS__  \
 | 
						|
)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a statement must be false in order for the assertion to not
 | 
						|
 * cause an error.
 | 
						|
 * 
 | 
						|
 * @param statement Statement of the assertion.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertFalse(x, ...) assertTrue(!(x), __VA_ARGS__)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a specified piece of code should be entirely unreachable.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertUnreachable(...) assertTrue(false, __VA_ARGS__)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a given pointer is not null.
 | 
						|
 * @param x Pointer to check.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertNotNull(x, ...) assertTrue(x != NULL, __VA_ARGS__)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a given pointer is null.
 | 
						|
 * @param x Pointer to check.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertNull(x, ...) assertTrue(x == NULL, __VA_ARGS__)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a given value has a specific flag turned off.
 | 
						|
 * 
 | 
						|
 * @param value Value to check.
 | 
						|
 * @param flag Flag to check for.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertFlagOff(value, flag, ...) assertTrue( \
 | 
						|
  (value & flag) == 0, __VA_ARGS__ \
 | 
						|
)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that a given value has a specific flag turned on.
 | 
						|
 * 
 | 
						|
 * @param value Value to check.
 | 
						|
 * @param flag Flag to check for.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertFlagOn(value, flag, ...) assertTrue( \
 | 
						|
  (value & flag) == flag, __VA_ARGS__ \
 | 
						|
)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that the given string is not null, and has a length that is less
 | 
						|
 * the maximum buffer size, including the NULL terminator.
 | 
						|
 * 
 | 
						|
 * @param str String to check.
 | 
						|
 * @param bufferSize Maximum buffer size.
 | 
						|
 * @param message Message (sprintf format) to send to the logger.
 | 
						|
 * @param args Optional TParam args for the sprintf message to accept.
 | 
						|
 */
 | 
						|
#define assertStringValid(str, bufferSize, ...) assertTrue( \
 | 
						|
  ((str != NULL) && ((strlen(str)+1) < bufferSize)), __VA_ARGS__ \
 | 
						|
)
 | 
						|
 | 
						|
/**
 | 
						|
 * Asserts that the current code is deprecated and should not be used anymore.
 | 
						|
 * @deprecated
 | 
						|
 */
 | 
						|
#define assertDeprecated(...) assertUnreachable(__VA_ARGS__) |