core: test: remove ugly not null check

This commit is contained in:
starnakin 2024-07-30 13:05:18 +02:00
parent 98a5e989c2
commit 0c3ba7ca43

View File

@ -5,13 +5,12 @@
#include "../src/raw_chunk_manager.h"
#include <stdio.h>
#define NOT_NULL (void*) 55342301
#include <stdint.h>
void test(const void* expected_value, const void* value, const char* test_name, const char* description)
{
printf("%s ", test_name);
if ((expected_value == NOT_NULL && value != NULL) || (expected_value != NOT_NULL && expected_value == value))
if (expected_value == value)
printf("[OK]");
else
printf("[FAILED] %s {%p != %p}", description, expected_value, value);
@ -37,13 +36,13 @@ int main(int ac, char **av)
void *ptr1 = ft_malloc(10000000);
void *ptr2 = ft_malloc(10000000);
void *ptr3 = ft_malloc(10000000);
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr1), "alloc first", "");
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr2), "alloc second", "");
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr3), "alloc third", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr1) == NULL), "alloc first", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr2) == NULL), "alloc second", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr3) == NULL), "alloc third", "");
ft_free(ptr1);
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr2), "free disorder1", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr2) == NULL), "free disorder1", "");
ft_free(ptr3);
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr2), "free disorder2", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr2) == NULL), "free disorder2", "");
ft_free(ptr2);
test(NULL, allocs_tree[LARGE], "free disorder3", "");