summaryrefslogtreecommitdiff
path: root/serial_link/tests
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-21 21:04:42 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-02-21 21:04:42 +0200
commit415ab91c9d2ed034bbbabf3cbb8502f525b91abb (patch)
treec269398c9f07ee6be89d7e55b505972fe717d2be /serial_link/tests
parentfe1db50fc32c13bb1030676b1381125398bce5de (diff)
Add master to slave transport
Diffstat (limited to 'serial_link/tests')
-rw-r--r--serial_link/tests/transport_tests.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/serial_link/tests/transport_tests.c b/serial_link/tests/transport_tests.c
index 61b9a65080..34d451de4d 100644
--- a/serial_link/tests/transport_tests.c
+++ b/serial_link/tests/transport_tests.c
@@ -25,11 +25,21 @@ SOFTWARE.
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
#include "protocol/transport.c"
+#include "protocol/triple_buffered_object.c"
void signal_data_written(void) {
mock();
}
+static uint8_t sent_data[2048];
+static uint16_t sent_data_size;
+
+void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
+ mock(destination);
+ memcpy(sent_data + sent_data_size, data, size);
+ sent_data_size += size;
+}
+
typedef struct {
uint32_t test;
} test_object1_t;
@@ -51,7 +61,8 @@ remote_object_t* test_remote_objects[] = {
Describe(Transport);
BeforeEach(Transport) {
- init_transport(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t));
+ init_transport(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*));
+ sent_data_size = 0;
}
AfterEach(Transport) {}
@@ -66,3 +77,18 @@ Ensure(Transport, write_to_local_signals_an_event) {
expect(signal_data_written);
end_write_master_to_single_slave(1);
}
+
+Ensure(Transport, writes_from_master_to_all_slaves) {
+ update_transport();
+ test_object1_t* obj = begin_write_master_to_slave();
+ obj->test = 5;
+ expect(signal_data_written);
+ end_write_master_to_slave();
+ expect(router_send_frame,
+ when(destination, is_equal_to(0xFF)));
+ update_transport();
+ transport_recv_frame(0, sent_data, sent_data_size);
+ test_object1_t* obj2 = read_master_to_slave();
+ assert_that(obj2, is_not_equal_to(NULL));
+ assert_that(obj2->test, is_equal_to(5));
+}