summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gustafsson <robg@student.chalmers.se>2017-10-02 20:13:07 +0200
committerRobert Gustafsson <robg@student.chalmers.se>2017-10-02 20:13:07 +0200
commitb8e28ed52cec6de9179a5bb6058def0efc6fcfa5 (patch)
tree357de3e63d5a71df7174ba509c2619d1ea274d5e
parentf2fd66ebf34e010770dca687f1a0a817b8fa4212 (diff)
downloadmidbro-b8e28ed52cec6de9179a5bb6058def0efc6fcfa5.tar.gz
midbro-b8e28ed52cec6de9179a5bb6058def0efc6fcfa5.tar.bz2
Add some basic unit tests
-rw-r--r--broccoli/Makefile11
-rw-r--r--broccoli/tests.c124
2 files changed, 133 insertions, 2 deletions
diff --git a/broccoli/Makefile b/broccoli/Makefile
index d6e2a37..329c60c 100644
--- a/broccoli/Makefile
+++ b/broccoli/Makefile
@@ -2,11 +2,14 @@ CC=gcc
CFLAGS = -c -Wall -I/usr/local/include -I/usr/local/include -DBROCCOLI
LDFLAGS = -L/usr/local/lib -lbroccoli -pthread
-all: midbropasad
+all: midbropasad tests
midbropasad: midbropasad.o broevent.o fifoqueue.o
$(CC) midbropasad.o broevent.o fifoqueue.o -o midbropasad $(LDFLAGS)
+tests: tests.o fifoqueue.o
+ $(CC) tests.o fifoqueue.o -o tests
+
midbropasad.o: midbropasad.c
$(CC) $(CFLAGS) midbropasad.c
@@ -15,5 +18,9 @@ broevent.o: broevent.c
fifoqueue.o: fifoqueue.c
$(CC) -c -Wall fifoqueue.c
+
+tests.o: tests.c
+ $(CC) -c -Wall tests.c
+
clean:
- rm *.o midbropasad
+ rm *.o midbropasad tests
diff --git a/broccoli/tests.c b/broccoli/tests.c
new file mode 100644
index 0000000..73e0346
--- /dev/null
+++ b/broccoli/tests.c
@@ -0,0 +1,124 @@
+#include "includes/fifoqueue.h"
+#include <assert.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;
+}