|
| 1 | +#include "cxxtest/TestSuite.h" |
| 2 | + |
| 3 | +#include "test56/Message.h" |
| 4 | +#include "test56/frame/Frame.h" |
| 5 | + |
| 6 | +#include "comms/process.h" |
| 7 | + |
| 8 | +#include <cstdint> |
| 9 | +#include <type_traits> |
| 10 | + |
| 11 | +class TestSuite : public CxxTest::TestSuite |
| 12 | +{ |
| 13 | +public: |
| 14 | + void test1(); |
| 15 | + |
| 16 | + // struct Handler |
| 17 | + // { |
| 18 | + // template <typename TMsg> |
| 19 | + // void handle(TMsg& msg) |
| 20 | + // { |
| 21 | + // static_cast<void>(msg); |
| 22 | + // } |
| 23 | + // }; |
| 24 | + |
| 25 | + using Interface = test56::Message< |
| 26 | + comms::option::app::IdInfoInterface, |
| 27 | + comms::option::app::LengthInfoInterface, |
| 28 | + comms::option::app::ReadIterator<const std::uint8_t*>, |
| 29 | + comms::option::app::WriteIterator<std::uint8_t*>, |
| 30 | + comms::option::app::NameInterface |
| 31 | + >; |
| 32 | + using Frame = test56::frame::Frame<Interface>; |
| 33 | + |
| 34 | + TEST56_ALIASES_FOR_ALL_MESSAGES_DEFAULT_OPTIONS(,,Interface); |
| 35 | +}; |
| 36 | + |
| 37 | +void TestSuite::test1() |
| 38 | +{ |
| 39 | + const std::uint8_t Buf[] = { |
| 40 | + 0x3d, 0x3d, // Prefix |
| 41 | + static_cast<std::uint8_t>(test56::MsgId_M2), |
| 42 | + 'h', 'e', 'l', 'l', 'o', |
| 43 | + 0x40, 0x40, // Suffix |
| 44 | + 0x94 // Checksum |
| 45 | + }; |
| 46 | + const std::size_t BufSize = std::extent<decltype(Buf)>::value; |
| 47 | + |
| 48 | + Frame frame; |
| 49 | + Frame::MsgPtr msgPtr; |
| 50 | + |
| 51 | + auto iter = comms::readIteratorFor<Interface>(Buf); |
| 52 | + auto es = frame.read(msgPtr, iter, BufSize); |
| 53 | + TS_ASSERT_EQUALS(es, comms::ErrorStatus::Success); |
| 54 | + TS_ASSERT(msgPtr); |
| 55 | + TS_ASSERT_EQUALS(msgPtr->getId(), test56::MsgId_M2); |
| 56 | + |
| 57 | + auto* msg2 = static_cast<const Msg2*>(msgPtr.get()); |
| 58 | + TS_ASSERT_EQUALS(msg2->field_f1().value(), "hello"); |
| 59 | + |
| 60 | + std::vector<std::uint8_t> outputBuf; |
| 61 | + outputBuf.resize(frame.length(*msgPtr)); |
| 62 | + |
| 63 | + auto writeIter = comms::writeIteratorFor<Interface>(outputBuf.data()); |
| 64 | + es = frame.write(*msgPtr, writeIter, outputBuf.size()); |
| 65 | + TS_ASSERT_EQUALS(es, comms::ErrorStatus::Success); |
| 66 | + TS_ASSERT_EQUALS(outputBuf.size(), BufSize); |
| 67 | + TS_ASSERT(std::equal(outputBuf.begin(), outputBuf.end(), Buf)); |
| 68 | +} |
| 69 | + |
0 commit comments