Began working on unit tests

This commit is contained in:
2022-08-28 08:10:41 +01:00
parent 5300e2ceec
commit 71ff481f6c
3 changed files with 84 additions and 0 deletions

View File

@@ -3,6 +3,9 @@ export OUTDIR = out
all: $(OUTDIR)
$(MAKE) -C source
test: clean $(OUTDIR)
$(MAKE) -C test
$(OUTDIR):
mkdir $(OUTDIR)

32
test/makefile Normal file
View File

@@ -0,0 +1,32 @@
CC=gcc
IDIR +=. ../source
CFLAGS +=$(addprefix -I,$(IDIR)) -g -Wall -W -pedantic -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable
LIBS +=
ODIR = obj
TARGETS = $(filter-out $(wildcard ../source/*main.c),$(wildcard ../source/*.c))
TESTS = $(wildcard *.c)
OBJ = $(addprefix $(ODIR)/,$(TARGETS:../source/%.c=%.o)) $(addprefix $(ODIR)/,$(TESTS:.c=.o))
all: $(OBJ) $(TESTS:%.c=../$(OUTDIR)/%.exe)
../$(OUTDIR)/%.exe: $(ODIR)/%.o
$(CC) -o $@ $< $(TARGETS:../source/%.c=$(ODIR)/%.o) $(CFLAGS) $(LIBS)
$@
$(OBJ): | $(ODIR)
$(ODIR):
mkdir $(ODIR)
$(ODIR)/%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
$(ODIR)/%.o: ../source/%.c
$(CC) -c -o $@ $< $(CFLAGS)
.PHONY: clean
clean:
$(RM) $(ODIR)

49
test/test_memory.c Normal file
View File

@@ -0,0 +1,49 @@
#include "memory.h"
#include "console_colors.h"
#include <stdio.h>
int main() {
{
//test single pointer
int* integer = ALLOCATE(int, 1);
FREE(int, integer);
if (getAllocatedMemoryCount() != 0) {
fprintf(stderr, ERROR "ERROR: integer failed to be allocated and freed correctly\n" RESET);
return -1;
}
}
{
//test single pointer
int* array = ALLOCATE(int, 10);
FREE_ARRAY(int, array, 10);
if (getAllocatedMemoryCount() != 0) {
fprintf(stderr, ERROR "ERROR: integer array failed to be allocated and freed correctly\n" RESET);
return -1;
}
}
{
//test single pointer
int* array1 = ALLOCATE(int, 10);
int* array2 = ALLOCATE(int, 10);
FREE_ARRAY(int, array1, 10);
FREE_ARRAY(int, array2, 10);
if (getAllocatedMemoryCount() != 0) {
fprintf(stderr, ERROR "ERROR: integer array failed to be allocated and freed correctly\n" RESET);
return -1;
}
}
printf(NOTICE "All good\n" RESET);
return 0;
}