2323#include < string>
2424
2525#include " ola/Logging.h"
26+ #include " ola/io/IOQueue.h"
2627#include " ola/io/IOStack.h"
28+ #include " ola/io/OutputStream.h"
2729#include " ola/network/NetworkUtils.h"
2830#include " ola/rdm/UID.h"
2931#include " ola/rdm/UIDSet.h"
@@ -35,16 +37,23 @@ namespace ola {
3537namespace acn {
3638
3739using ola::acn::LLRPProbeReplyPDU;
40+ using ola::io::IOQueue;
3841using ola::io::IOStack;
42+ using ola::io::OutputStream;
43+ using ola::network::HostToNetwork;
3944using ola::network::MACAddress;
4045using ola::rdm::UID;
4146
4247class LLRPProbeReplyPDUTest : public CppUnit ::TestFixture {
4348 CPPUNIT_TEST_SUITE (LLRPProbeReplyPDUTest);
49+ CPPUNIT_TEST (testSimpleLLRPProbeReplyPDU);
50+ CPPUNIT_TEST (testSimpleLLRPProbeReplyPDUToOutputStream);
4451 CPPUNIT_TEST (testPrepend);
4552 CPPUNIT_TEST_SUITE_END ();
4653
4754 public:
55+ void testSimpleLLRPProbeReplyPDU ();
56+ void testSimpleLLRPProbeReplyPDUToOutputStream ();
4857 void testPrepend ();
4958
5059 private:
@@ -53,6 +62,98 @@ class LLRPProbeReplyPDUTest: public CppUnit::TestFixture {
5362
5463CPPUNIT_TEST_SUITE_REGISTRATION (LLRPProbeReplyPDUTest);
5564
65+ const unsigned int LLRPProbeReplyPDUTest::TEST_VECTOR = 39 ;
66+
67+
68+ /*
69+ * Test that packing a LLRPProbeReplyPDU works.
70+ */
71+ void LLRPProbeReplyPDUTest::testSimpleLLRPProbeReplyPDU () {
72+ UID target_uid = UID (0x4321 , 0x12345678 );
73+ MACAddress hardware_address;
74+ MACAddress::FromString (" 01:23:45:67:89:ab" , &hardware_address);
75+ LLRPProbeReplyPDU pdu (
76+ TEST_VECTOR,
77+ target_uid,
78+ hardware_address,
79+ LLRPProbeReplyPDU::LLRP_COMPONENT_TYPE_NON_RDMNET);
80+
81+ OLA_ASSERT_EQ (0u , pdu.HeaderSize ());
82+ OLA_ASSERT_EQ (13u , pdu.DataSize ());
83+ OLA_ASSERT_EQ (17u , pdu.Size ());
84+
85+ unsigned int size = pdu.Size ();
86+ uint8_t *data = new uint8_t [size];
87+ unsigned int bytes_used = size;
88+ OLA_ASSERT (pdu.Pack (data, &bytes_used));
89+ OLA_ASSERT_EQ (size, bytes_used);
90+
91+ // spot check the data
92+ OLA_ASSERT_EQ ((uint8_t ) 0xf0 , data[0 ]);
93+ // bytes_used is technically data[1] and data[2] if > 255
94+ OLA_ASSERT_EQ ((uint8_t ) bytes_used, data[2 ]);
95+ OLA_ASSERT_EQ (HostToNetwork ((uint8_t ) TEST_VECTOR), data[3 ]);
96+
97+ uint8_t buffer[UID::LENGTH];
98+ target_uid.Pack (buffer, sizeof (buffer));
99+ OLA_ASSERT_DATA_EQUALS (&data[4 ], UID::LENGTH, buffer, sizeof (buffer));
100+ uint8_t buffer2[MACAddress::LENGTH];
101+ hardware_address.Pack (buffer2, sizeof (buffer2));
102+ OLA_ASSERT_DATA_EQUALS (&data[10 ], MACAddress::LENGTH,
103+ buffer2, sizeof (buffer2));
104+
105+ // test undersized buffer
106+ bytes_used = size - 1 ;
107+ OLA_ASSERT_FALSE (pdu.Pack (data, &bytes_used));
108+ OLA_ASSERT_EQ (0u , bytes_used);
109+
110+ // test oversized buffer
111+ bytes_used = size + 1 ;
112+ OLA_ASSERT (pdu.Pack (data, &bytes_used));
113+ OLA_ASSERT_EQ (size, bytes_used);
114+ delete[] data;
115+ }
116+
117+
118+ /*
119+ * Test that writing to an output stream works.
120+ */
121+ void LLRPProbeReplyPDUTest::testSimpleLLRPProbeReplyPDUToOutputStream () {
122+ UID target_uid = UID (0x4321 , 0x12345678 );
123+ MACAddress hardware_address;
124+ MACAddress::FromString (" 01:23:45:67:89:ab" , &hardware_address);
125+ LLRPProbeReplyPDU pdu (
126+ TEST_VECTOR,
127+ target_uid,
128+ hardware_address,
129+ LLRPProbeReplyPDU::LLRP_COMPONENT_TYPE_NON_RDMNET);
130+
131+ OLA_ASSERT_EQ (0u , pdu.HeaderSize ());
132+ OLA_ASSERT_EQ (13u , pdu.DataSize ());
133+ OLA_ASSERT_EQ (17u , pdu.Size ());
134+
135+ IOQueue output;
136+ OutputStream stream (&output);
137+ pdu.Write (&stream);
138+ OLA_ASSERT_EQ (17u , output.Size ());
139+
140+ uint8_t *pdu_data = new uint8_t [output.Size ()];
141+ unsigned int pdu_size = output.Peek (pdu_data, output.Size ());
142+ OLA_ASSERT_EQ (output.Size (), pdu_size);
143+
144+ uint8_t EXPECTED[] = {
145+ 0xf0 , 0x00 , 0x11 ,
146+ 39 ,
147+ 0x43 , 0x21 , 0x12 , 0x34 , 0x56 , 0x78 ,
148+ 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0xab ,
149+ 0xff
150+ };
151+ OLA_ASSERT_DATA_EQUALS (EXPECTED, sizeof (EXPECTED), pdu_data, pdu_size);
152+ output.Pop (output.Size ());
153+ delete[] pdu_data;
154+ }
155+
156+
56157void LLRPProbeReplyPDUTest::testPrepend () {
57158 IOStack stack;
58159 UID target_uid = UID (0x4321 , 0x12345678 );
0 commit comments