diff --git a/Makefile b/Makefile
index 59d2495..c1d3b30 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,15 @@ DEBDIR=debian
OBJ=$(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o $(BINDIR)/main.o
.DEFAULT_GOAL:= all
-.PHONY: all clean deb
+.PHONY: all clean deb tests install run
+
+# ---- Tests enumeration ----------------------------------------------------- #
+TEST_SCHEDULER=$(BINDIR)/tests/scheduler
+TESTS=$(TEST_SCHEDULER)
+
+$(BINDIR)/tests/scheduler: $(SRCDIR)/tests/scheduler.c
+ @echo "Compiling $<"
+ @$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) $(LDFLAGS) -o $@ $<
# ---- General recipes ------------------------------------------------------- #
@@ -43,9 +51,11 @@ $(BINDIR)/gem-graph-server: $(OBJ)
# ---- Misc recipes ---------------------------------------------------------- #
clean:
- rm -rf $(SRCDIR)/*.o $(BINDIR)/* *.deb
+ -rm -f $(SRCDIR)/*.o $(BINDIR)/* $(BINDIR)/tests/* *.deb
-all: $(DYNLIBS) $(BINDIR)/gem-graph-server
+all: $(BINDIR)/gem-graph-server
+
+tests: $(TESTS)
# ---- Build debian package -------------------------------------------------- #
$(BINDIR)/gem-graph-server.deb: all
@@ -63,6 +73,8 @@ install:
echo "Installing is not supported"
# ---- Builder uses this target to run your application ---------------------- #
-run:
+run: all
bin/gem-graph-server
+run-tests: tests
+ bin/tests/scheduler
diff --git a/README.md b/README.md
index 137a290..98d84be 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,13 @@
# gem-graph-server
+Build & execute the program:
+```
+make
+make run
+```
+
+Build & execute tests
+```
+make tests
+make run-tests
+```
diff --git a/src/scheduler.c b/src/scheduler.c
index 0fe8630..c38ae1c 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -50,6 +50,7 @@ static inline void centerAssign(Center_t *center, int x, int y, int z)
static inline Center_t *centerAdd(Center_t *anyCenter, Center_t *newCenter)
{
+ if (!newCenter) return NULL;
if (anyCenter->next) {
anyCenter->next->prev = newCenter;
}
@@ -62,10 +63,9 @@ static inline Center_t *centerAdd(Center_t *anyCenter, Center_t *newCenter)
static inline void centerRemove(Center_t *oldCenter)
{
- oldCenter->prev->next = oldCenter->next;
- oldCenter->next->prev = oldCenter->prev;
-
- free(oldCenter);
+ if (!oldCenter) return;
+ if (oldCenter->prev) oldCenter->prev->next = oldCenter->next;
+ if (oldCenter->next) oldCenter->next->prev = oldCenter->prev;
}
// -------------------------------------------------------------------------- //
diff --git a/src/test/localworker.c b/src/test/localworker.c
deleted file mode 100644
index 3b87380..0000000
--- a/src/test/localworker.c
+++ /dev/null
@@ -1,22 +0,0 @@
-//=-------------------------------------------------------------------------=//
-// Local worker tests //
-// //
-// Copyright © 2021 The Gem-graph Project //
-// //
-// This file is part of gem-graph. //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU Affero General Public License as //
-// published by the Free Software Foundation, either version 3 of the //
-// License, or (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU Affero General Public License for more details. //
-// //
-// You should have received a copy of the GNU Affero General Public License //
-// along with this program. If not, see . //
-//=-------------------------------------------------------------------------=//
-
-#include "../localworker.c"
diff --git a/src/test/scheduler.c b/src/test/scheduler.c
deleted file mode 100644
index 6764c2b..0000000
--- a/src/test/scheduler.c
+++ /dev/null
@@ -1,22 +0,0 @@
-//=-------------------------------------------------------------------------=//
-// Scheduler tests //
-// //
-// Copyright © 2021 The Gem-graph Project //
-// //
-// This file is part of gem-graph. //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU Affero General Public License as //
-// published by the Free Software Foundation, either version 3 of the //
-// License, or (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU Affero General Public License for more details. //
-// //
-// You should have received a copy of the GNU Affero General Public License //
-// along with this program. If not, see . //
-//=-------------------------------------------------------------------------=//
-
-#include "../scheduler.c"
diff --git a/src/test/server.c b/src/test/server.c
deleted file mode 100644
index 80f92af..0000000
--- a/src/test/server.c
+++ /dev/null
@@ -1,22 +0,0 @@
-//=-------------------------------------------------------------------------=//
-// Server tests //
-// //
-// Copyright © 2021 The Gem-graph Project //
-// //
-// This file is part of gem-graph. //
-// //
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the GNU Affero General Public License as //
-// published by the Free Software Foundation, either version 3 of the //
-// License, or (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU Affero General Public License for more details. //
-// //
-// You should have received a copy of the GNU Affero General Public License //
-// along with this program. If not, see . //
-//=-------------------------------------------------------------------------=//
-
-#include "../server.c"