diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2016-02-21 21:04:42 +0200 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2016-02-21 21:04:42 +0200 |
commit | 415ab91c9d2ed034bbbabf3cbb8502f525b91abb (patch) | |
tree | c269398c9f07ee6be89d7e55b505972fe717d2be /serial_link/tests | |
parent | fe1db50fc32c13bb1030676b1381125398bce5de (diff) |
Add master to slave transport
Diffstat (limited to 'serial_link/tests')
-rw-r--r-- | serial_link/tests/transport_tests.c | 28 |
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)); +} |