Assume Pointer

A pointer assumption/assertion evaluates whether pointers correctly point to valid memory addresses, ensuring that references to objects, variables, or data structures are valid and not null or dangling. This type of assertion is vital for systems programming, where incorrect pointer management can lead to crashes, memory corruption, or undefined behavior. It helps ensure that pointer-based operations and memory accesses are safe and reliable.

C, C++ REFERENCE #

/**
 * @brief Assumes that the given pointer is cnull.
 *
 * @param actual The pointer to be evaluated.
 */
#define ASSUME_ITS_CNULL(actual) \
    FOSSIL_TEST_ASSUME((actual) == null, "Expected " #actual " to be cnull")

/**
 * @brief Assumes that the given pointer is not cnull.
 *
 * @param actual The pointer to be evaluated.
 */
#define ASSUME_NOT_CNULL(actual) \
    FOSSIL_TEST_ASSUME((actual) != null, "Expected " #actual " to not be cnull")

/**
 * @brief Assumes that the given pointer is cnull.
 * 
 * @param actual The pointer to be evaluated.
 */
#define ASSUME_ITS_CNULLABLE(actual) \
    FOSSIL_TEST_ASSUME((actual) == null, "Expected " #actual " to be cnull")

/**
 * @brief Assumes that the given pointer is not cnull.
 * 
 * @param actual The pointer to be evaluated.
 */
#define ASSUME_NOT_CNULLABLE(actual) \
    FOSSIL_TEST_ASSUME((actual) != null, "Expected " #actual " to not be cnull")

/**
 * @brief Assumes that the given pointer is cnull.
 *
 * @param actual The pointer to be evaluated.
 */
#define ASSUME_ITS_CNONNULL(actual) \
    FOSSIL_TEST_ASSUME((actual) != null, "Expected " #actual " to not be cnull")

/**
 * @brief Assumes that the given pointer is not cnull.
 *
 * @param actual The pointer to be evaluated.
 */
#define ASSUME_NOT_CNONNULL(actual) \
    FOSSIL_TEST_ASSUME((actual) == null, "Expected " #actual " to be cnull")

/**
 * @brief Assumes that the given condition is likely.
 *
 * @param x The condition to be evaluated.
 */
#define ASSUME_ITS_LIKELY(x) \
    FOSSIL_TEST_ASSUME(likely(x), "Expected " #x " to be likely")

/**
 * @brief Assumes that the given condition is not likely.
 *
 * @param x The condition to be evaluated.
 */
#define ASSUME_NOT_LIKELY(x) \
    FOSSIL_TEST_ASSUME(!likely(x), "Expected " #x " to not be likely")

/**
 * @brief Assumes that the given condition is unlikely.
 *
 * @param x The condition to be evaluated.
 */
#define ASSUME_ITS_UNLIKELY(x) \
    FOSSIL_TEST_ASSUME(unlikely(x), "Expected " #x " to be unlikely")

/**
 * @brief Assumes that the given condition is not unlikely.
 *
 * @param x The condition to be evaluated.
 */
#define ASSUME_NOT_UNLIKELY(x) \
    FOSSIL_TEST_ASSUME(!unlikely(x), "Expected " #x " to not be unlikely")

/**
 * @brief Assumes that the given pointers are equal.
 *
 * @param actual The actual pointer.
 * @param expected The expected pointer.
 */
#define ASSUME_ITS_EQUAL_PTR(actual, expected) \
    FOSSIL_TEST_ASSUME((actual) == (expected), "Expected pointer " #actual " to be equal to pointer " #expected " ")

/**
 * @brief Assumes that the given pointers are not equal.
 *
 * @param actual The actual pointer.
 * @param expected The expected pointer.
 */
#define ASSUME_NOT_EQUAL_PTR(actual, expected) \
    FOSSIL_TEST_ASSUME((actual) != (expected), "Expected pointer " #actual " to not be equal to pointer " #expected " ")

/**
 * @brief Assumes that the given size_t values are equal.
 *
 * @param actual The actual size_t value.
 * @param expected The expected size_t value.
 */
#define ASSUME_ITS_EQUAL_SIZE(actual, expected) \
    FOSSIL_TEST_ASSUME((size_t)(actual) == (size_t)(expected), "Expected " #actual " to be equal to " #expected)

/**
 * @brief Assumes that the given size_t value is less than the expected value.
 *
 * @param actual The actual size_t value.
 * @param expected The expected size_t value.
 */
#define ASSUME_ITS_LESS_THAN_SIZE(actual, expected) \
    FOSSIL_TEST_ASSUME((size_t)(actual) < (size_t)(expected), "Expected " #actual " to be less than " #expected)

/**
 * @brief Assumes that the given size_t value is more than the expected value.
 *
 * @param actual The actual size_t value.
 * @param expected The expected size_t value.
 */
#define ASSUME_ITS_MORE_THAN_SIZE(actual, expected) \
    FOSSIL_TEST_ASSUME((size_t)(actual) > (size_t)(expected), "Expected " #actual " to be more than " #expected)

/**
 * @brief Assumes that the given size_t value is less than or equal to the expected value.
 *
 * @param actual The actual size_t value.
 * @param expected The expected size_t value.
 */
#define ASSUME_ITS_LESS_OR_EQUAL_SIZE(actual, expected) \
    FOSSIL_TEST_ASSUME((size_t)(actual) <= (size_t)(expected), "Expected " #actual " to be less than or equal to " #expected)

/**
 * @brief Assumes that the given size_t value is more than or equal to the expected value.
 *
 * @param actual The actual size_t value.
 * @param expected The expected size_t value.
 */
#define ASSUME_ITS_MORE_OR_EQUAL_SIZE(actual, expected) \
    FOSSIL_TEST_ASSUME((size_t)(actual) >= (size_t)(expected), "Expected " #actual " to be more than or equal to " #expected)

/**
 * @brief Assumes that the given size_t values are not equal.
 *
 * @param actual The actual size_t value.
 * @param expected The expected size_t value.
 */
#define ASSUME_NOT_EQUAL_SIZE(actual, expected) \
    FOSSIL_TEST_ASSUME((size_t)(actual) != (size_t)(expected), "Expected " #actual " to not be equal to " #expected)

PYTHON REFERENCE #

# TODO: add code here

What are your feelings

Updated on May 12, 2025