diff options
author | Andreas Lindhé <andreas@lindhe.io> | 2017-10-31 08:33:46 +0100 |
---|---|---|
committer | Andreas Lindhé <andreas@lindhe.io> | 2017-10-31 08:41:40 +0100 |
commit | bc5ecd6da7f068a12b9ee5397178723481c7a3ea (patch) | |
tree | 6ac5bb33df7c3aacde8eb254c4aee1ce1df9dd29 /test | |
parent | 2d5d5be5702867a7a719312a5a148489c3b68f31 (diff) | |
download | midbro-bc5ecd6da7f068a12b9ee5397178723481c7a3ea.tar.gz midbro-bc5ecd6da7f068a12b9ee5397178723481c7a3ea.tar.bz2 |
Move all files one level down
Diffstat (limited to 'test')
-rw-r--r-- | test/midbro_test.c | 11 | ||||
-rw-r--r-- | test/tests.c | 126 |
2 files changed, 137 insertions, 0 deletions
diff --git a/test/midbro_test.c b/test/midbro_test.c new file mode 100644 index 0000000..c0f4ba6 --- /dev/null +++ b/test/midbro_test.c @@ -0,0 +1,11 @@ +#include "midbro.h" + + int +main(int argc, char **argv) +{ + start_data_capture(); + while(1){ + request_value(); + } + return 0; +} diff --git a/test/tests.c b/test/tests.c new file mode 100644 index 0000000..5b91feb --- /dev/null +++ b/test/tests.c @@ -0,0 +1,126 @@ +#include "fifoqueue.h" +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + + void +create_sensor_object_test() { + int value, uid; + value = 1; + uid = 2; + Sensor_t * sensor = create_sensor_object(value, uid); + assert(sensor->value == value); + assert(sensor->uid == uid); + printf("create_sensor_object_test SUCCESS\n"); + free(sensor); +} + + void +init_queue_test() +{ + int size; + Fifo_q * q; + size = 50; + q = init_queue(size); + assert(q->maxSize == size); + printf("init_queue_test SUCCESS\n"); + free(q); +} + + void +add_to_queue_test() +{ + int size, value, uid; + Fifo_q * q; + Sensor_t * sensor; + size = 50; + value = 1; + uid = 2; + q = init_queue(size); + sensor = create_sensor_object(value, uid); + add_to_queue(q,sensor); + assert(q->currentSize == 1); + assert(q->head->sensor == sensor); + assert(q->tail->sensor == sensor); + printf("add_to_queue_test SUCCESS\n"); + free(sensor); + free(q->head); + free(q); +} + + void +pop_from_queue_test() +{ + int size, value, uid; + Fifo_q * q; + Sensor_t * actual; + Sensor_t * expected; + size = 50; + value = 1; + uid = 2; + q = init_queue(size); + actual = create_sensor_object(value, uid); + add_to_queue(q, actual); + expected = pop_from_queue(q); + assert(actual == expected); + printf("pop_from_queue_test SUCCESS\n"); + free(actual); + free(q->head); + free(q); +} + + void +is_full_test() +{ + int size, value, uid; + Fifo_q * q; + Sensor_t * sensor; + size = 1; + value = 1; + uid = 2; + q = init_queue(size); + sensor = create_sensor_object(value, uid); + assert(is_full(q) == false); + add_to_queue(q,sensor); + assert(is_full(q) == true); + printf("is_full_test SUCCESS\n"); + free(sensor); + free(q->head); + free(q); +} + void +is_empty_test() +{ + int size, value, uid; + Fifo_q * q; + Sensor_t * sensor; + size = 1; + value = 1; + uid = 2; + q = init_queue(size); + sensor = create_sensor_object(value, uid); + assert(is_empty(q) == true); + add_to_queue(q,sensor); + assert(is_empty(q) == false); + printf("is_empty_test SUCCESS\n"); + free(sensor); + free(q->head); + free(q); +} + void +all_tests() +{ + create_sensor_object_test(); + init_queue_test(); + add_to_queue_test(); + pop_from_queue_test(); + is_full_test(); + is_empty_test(); + printf("TEST SUITE PASSED\n"); +} + int +main(int argc, char **argv) +{ + all_tests(); + return 0; +} |