Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
async_datagram_test_helper.hxx
Go to the documentation of this file.
1
35#ifndef _UTILS_ASYNC_DATAGRAM_TEST_HELPER_HXX_
36#define _UTILS_ASYNC_DATAGRAM_TEST_HELPER_HXX_
37
38#include "utils/async_if_test_helper.hxx"
39#include "openlcb/Datagram.hxx"
41
42namespace openlcb {
43
46{
47protected:
48 AsyncDatagramTest() : datagram_support_(ifCan_.get(), 10, 2)
49 {
50 }
51
52 CanDatagramService datagram_support_;
53};
54
56
77{
78protected:
79 enum
80 {
81 OTHER_NODE_ID = TEST_NODE_ID + 0x100,
82 OTHER_NODE_ALIAS = 0x225,
83 };
84
87 {
88 NodeHandle ret;
89 ret.id = OTHER_NODE_ID;
90 ret.alias = OTHER_NODE_ALIAS;
91 return ret;
92 }
93
97 void setup_other_node(bool separate_if)
98 {
99 if (separate_if)
100 {
101 otherIfCan_.reset(
102 new IfCan(&g_executor, &can_hub0, 10, 10, 5));
103 otherIfCan_->add_addressed_message_support();
104 otherNodeIf_ = otherIfCan_.get();
105 otherDatagramSupport_.reset(
106 new CanDatagramService(otherNodeIf_, 10, 2));
107 otherNodeDatagram_ = otherDatagramSupport_.get();
108 }
109 else
110 {
111 otherNodeIf_ = ifCan_.get();
112 otherNodeDatagram_ = &datagram_support_;
113 }
114 run_x([this]() {
115 otherNodeIf_->local_aliases()->add(OTHER_NODE_ID, OTHER_NODE_ALIAS);
116 });
117 expect_packet(":X19100225N02010D000103;"); // node up
118 otherNode_.reset(new DefaultNode(otherNodeIf_, OTHER_NODE_ID));
119 wait();
120 }
121
126 {
127 expect_packet(":X1070222AN02010D000103;"); // looking for DST node
128 expect_packet(":X10701225N02010D000103;"); // found dst node
129 // expect_packet(":X1949022AN02010D000103;"); // hard-looking for DST node
130 // expect_packet(":X19170225N02010D000103;"); // node ID verified
131 }
132
133 std::unique_ptr<DefaultNode> otherNode_;
134 // Second objects if we want a bus-traffic test.
135 std::unique_ptr<IfCan> otherIfCan_;
136 IfCan* otherNodeIf_;
137 std::unique_ptr<CanDatagramService> otherDatagramSupport_;
138 CanDatagramService* otherNodeDatagram_;
139};
140
141} // namespace
142
143
144#endif // _UTILS_ASYNC_DATAGRAM_TEST_HELPER_HXX_
DynamicPool * mainBufferPool
main buffer pool instance
Definition Buffer.cxx:37
void wait()
Delays the current thread until we are certain that all asynchrnous processing has completed.
Pool of previously allocated, but currently unused, items.
Definition Buffer.hxx:278
Test base class for OpenLCB unittests that need a datagram handler.
std::unique_ptr< IfCan > ifCan_
The interface under test.
Base class for test cases with one virtual node on a CANbus interface.
Implementation of the DatagramService with the CANbus-specific OpenLCB datagram protocol.
Trivial implementation of a virtual Node.
Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard.
Definition IfCan.hxx:65
AliasCache * local_aliases()
Definition IfCan.hxx:96
Test base class for OpenLCB unittests that simulate two physical or virtual nodes talking to each oth...
void expect_other_node_lookup()
Adds the necessary expectations for the address lookup reuqests on the CANbus by the first datagram b...
Pool *const g_incoming_datagram_allocator
Allocator to be used for Buffer<IncomingDatagram> objects.
Container of both a NodeID and NodeAlias.
NodeID id
48-bit NMRAnet Node ID
NodeAlias alias
alias to NMRAnet Node ID
Executor< 1 > g_executor
Global executor thread for tests.
void run_x(std::function< void()> fn)
Synchronously runs a function in the main executor.