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,97 @@ 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, buffer2, sizeof (buffer2));
103+
104+ // test undersized buffer
105+ bytes_used = size - 1 ;
106+ OLA_ASSERT_FALSE (pdu.Pack (data, &bytes_used));
107+ OLA_ASSERT_EQ (0u , bytes_used);
108+
109+ // test oversized buffer
110+ bytes_used = size + 1 ;
111+ OLA_ASSERT (pdu.Pack (data, &bytes_used));
112+ OLA_ASSERT_EQ (size, bytes_used);
113+ delete[] data;
114+ }
115+
116+
117+ /*
118+ * Test that writing to an output stream works.
119+ */
120+ void LLRPProbeReplyPDUTest::testSimpleLLRPProbeReplyPDUToOutputStream () {
121+ UID target_uid = UID (0x4321 , 0x12345678 );
122+ MACAddress hardware_address;
123+ MACAddress::FromString (" 01:23:45:67:89:ab" , &hardware_address);
124+ LLRPProbeReplyPDU pdu (
125+ TEST_VECTOR,
126+ target_uid,
127+ hardware_address,
128+ LLRPProbeReplyPDU::LLRP_COMPONENT_TYPE_NON_RDMNET);
129+
130+ OLA_ASSERT_EQ (0u , pdu.HeaderSize ());
131+ OLA_ASSERT_EQ (13u , pdu.DataSize ());
132+ OLA_ASSERT_EQ (17u , pdu.Size ());
133+
134+ IOQueue output;
135+ OutputStream stream (&output);
136+ pdu.Write (&stream);
137+ OLA_ASSERT_EQ (17u , output.Size ());
138+
139+ uint8_t *pdu_data = new uint8_t [output.Size ()];
140+ unsigned int pdu_size = output.Peek (pdu_data, output.Size ());
141+ OLA_ASSERT_EQ (output.Size (), pdu_size);
142+
143+ uint8_t EXPECTED[] = {
144+ 0xf0 , 0x00 , 0x11 ,
145+ 39 ,
146+ 0x43 , 0x21 , 0x12 , 0x34 , 0x56 , 0x78 ,
147+ 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0xab ,
148+ 0xff
149+ };
150+ OLA_ASSERT_DATA_EQUALS (EXPECTED, sizeof (EXPECTED), pdu_data, pdu_size);
151+ output.Pop (output.Size ());
152+ delete[] pdu_data;
153+ }
154+
155+
56156void LLRPProbeReplyPDUTest::testPrepend () {
57157 IOStack stack;
58158 UID target_uid = UID (0x4321 , 0x12345678 );
0 commit comments