First unit tests for scheduler
This commit is contained in:
parent
0319676d7e
commit
46c024efe6
|
@ -0,0 +1,22 @@
|
|||
//=-------------------------------------------------------------------------=//
|
||||
// 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 <https://www.gnu.org/licenses/>. //
|
||||
//=-------------------------------------------------------------------------=//
|
||||
|
||||
#include "../localworker.c"
|
|
@ -0,0 +1,181 @@
|
|||
//=-------------------------------------------------------------------------=//
|
||||
// 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 <https://www.gnu.org/licenses/>. //
|
||||
//=-------------------------------------------------------------------------=//
|
||||
|
||||
#include "../scheduler.c"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// Tests for Center_t functions
|
||||
//
|
||||
|
||||
void printCenters(Center_t *firstCenter)
|
||||
{
|
||||
while (firstCenter) {
|
||||
printf("Center %p\n\tNext %p\n\tPrev %p\n\n",
|
||||
firstCenter,
|
||||
firstCenter->next,
|
||||
firstCenter->prev
|
||||
);
|
||||
firstCenter = firstCenter->next;
|
||||
}
|
||||
}
|
||||
|
||||
bool TestCenterRemove
|
||||
(void)
|
||||
{
|
||||
Center_t *anyCenter = NULL;
|
||||
|
||||
// adding a something to a bad pointer
|
||||
centerRemove(anyCenter);
|
||||
|
||||
//printf("* Status of centers list after deleting NULL\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter == NULL);
|
||||
|
||||
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
|
||||
//printf("* Initial status of centers list\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter->next == NULL);
|
||||
assert(anyCenter->prev == NULL);
|
||||
assert(anyCenter != NULL);
|
||||
|
||||
// Deleting a lonely pointer
|
||||
centerRemove(anyCenter);
|
||||
|
||||
//printf("* Status of centers list after deleting a lonely center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
|
||||
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
|
||||
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
|
||||
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
|
||||
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
|
||||
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
|
||||
|
||||
Center_t *oldfirst = anyCenter->next;
|
||||
Center_t *oldsecond = anyCenter->next->next;
|
||||
|
||||
|
||||
// Deleting a the first pointer
|
||||
centerRemove(anyCenter->next);
|
||||
|
||||
//printf("* Status of centers list after deleting the head center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter->next == oldsecond);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestCenterAdd(void)
|
||||
{
|
||||
Center_t *anyCenter = NULL;
|
||||
|
||||
// adding a something to a bad pointer
|
||||
centerAdd(anyCenter, NULL);
|
||||
|
||||
//printf("* Status of centers list after adding something to NULL\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter == NULL);
|
||||
|
||||
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
|
||||
//printf("* Initial status of centers list\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter->next == NULL);
|
||||
assert(anyCenter->prev == NULL);
|
||||
assert(anyCenter != NULL);
|
||||
|
||||
// adding a bad pointer
|
||||
centerAdd(anyCenter, NULL);
|
||||
|
||||
//printf("* Status of centers list after adding NULL\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter->next == NULL);
|
||||
assert(anyCenter->prev == NULL);
|
||||
assert(anyCenter != NULL);
|
||||
|
||||
// adding a good pointer
|
||||
Center_t *goodpointer = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
centerAdd(anyCenter, goodpointer);
|
||||
|
||||
//printf("* Status of centers list after adding a center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter != NULL);
|
||||
assert(anyCenter->next == goodpointer);
|
||||
assert(anyCenter->prev == NULL);
|
||||
assert(goodpointer->prev == anyCenter);
|
||||
assert(goodpointer->next == NULL);
|
||||
|
||||
// adding another good pointer
|
||||
Center_t *newgoodpointer = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
centerAdd(anyCenter, newgoodpointer);
|
||||
|
||||
//printf("* Status of centers list after adding another center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter != NULL);
|
||||
assert(anyCenter->next == newgoodpointer);
|
||||
assert(anyCenter->prev == NULL);
|
||||
assert(newgoodpointer->prev == anyCenter);
|
||||
assert(newgoodpointer->next == goodpointer);
|
||||
|
||||
// adding another good pointer
|
||||
Center_t *strangepointer = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
strangepointer->next = (Center_t*)0xCAFEBABE;
|
||||
strangepointer->prev = (Center_t*)0xCAFEBABE;
|
||||
centerAdd(anyCenter, strangepointer);
|
||||
|
||||
//printf("* Status of centers list after adding a strange center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter != NULL);
|
||||
assert(anyCenter->next == strangepointer);
|
||||
assert(anyCenter->prev == NULL);
|
||||
assert(strangepointer->prev != (Center_t*)0xCAFEBABE);
|
||||
assert(strangepointer->next != (Center_t*)0xCAFEBABE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("\n==== Testing scheduler.c/centerAdd() ====\n");
|
||||
TestCenterAdd();
|
||||
printf("\n==== Testing scheduler.c/centerAdd() ==== : OK\n");
|
||||
|
||||
printf("\n==== Testing scheduler.c/centerRemove() ====\n");
|
||||
TestCenterRemove();
|
||||
printf("\n==== Testing scheduler.c/centerRemove() ==== : OK\n");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
//=-------------------------------------------------------------------------=//
|
||||
// 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 <https://www.gnu.org/licenses/>. //
|
||||
//=-------------------------------------------------------------------------=//
|
||||
|
||||
#include "../server.c"
|
Loading…
Reference in New Issue