forked from OpenLightingProject/ola
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the BrokerFetchClientListPDU class
(cherry picked from commit e00322d)
- Loading branch information
1 parent
5dabc8b
commit 8af9777
Showing
4 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* BrokerFetchClientListPDU.cpp | ||
* The BrokerFetchClientListPDU | ||
* Copyright (C) 2023 Peter Newman | ||
*/ | ||
|
||
#include "libs/acn/BrokerFetchClientListPDU.h" | ||
|
||
#include <ola/network/NetworkUtils.h> | ||
#include <ola/acn/ACNVectors.h> | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
using ola::network::HostToNetwork; | ||
|
||
void BrokerFetchClientListPDU::PrependPDU(ola::io::IOStack *stack) { | ||
uint16_t vector = HostToNetwork(static_cast<uint16_t>( | ||
VECTOR_BROKER_FETCH_CLIENT_LIST)); | ||
stack->Write(reinterpret_cast<uint8_t*>(&vector), sizeof(vector)); | ||
PrependFlagsAndLength(stack, VFLAG_MASK | HFLAG_MASK | DFLAG_MASK, true); | ||
} | ||
} // namespace acn | ||
} // namespace ola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* BrokerFetchClientListPDU.h | ||
* The BrokerFetchClientListPDU class | ||
* Copyright (C) 2023 Peter Newman | ||
*/ | ||
|
||
#ifndef LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_ | ||
#define LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_ | ||
|
||
#include <ola/io/IOStack.h> | ||
|
||
#include "libs/acn/PDU.h" | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
class BrokerFetchClientListPDU : public PDU { | ||
public: | ||
explicit BrokerFetchClientListPDU(unsigned int vector): | ||
PDU(vector, TWO_BYTES, true) {} | ||
|
||
unsigned int HeaderSize() const { return 0; } | ||
bool PackHeader(OLA_UNUSED uint8_t *data, | ||
unsigned int *length) const { | ||
*length = 0; | ||
return true; | ||
} | ||
void PackHeader(OLA_UNUSED ola::io::OutputStream *stream) const {} | ||
|
||
unsigned int DataSize() const { return 0; } | ||
bool PackData(OLA_UNUSED uint8_t *data, | ||
unsigned int *length) const { | ||
*length = 0; | ||
return true; | ||
} | ||
void PackData(OLA_UNUSED ola::io::OutputStream *stream) const {} | ||
|
||
static void PrependPDU(ola::io::IOStack *stack); | ||
}; | ||
} // namespace acn | ||
} // namespace ola | ||
#endif // LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* BrokerFetchClientListPDUTest.cpp | ||
* Test fixture for the BrokerFetchClientListPDU class | ||
* Copyright (C) 2023 Peter Newman | ||
*/ | ||
|
||
#include <cppunit/extensions/HelperMacros.h> | ||
|
||
#include "ola/Logging.h" | ||
#include "ola/io/IOQueue.h" | ||
#include "ola/io/IOStack.h" | ||
#include "ola/io/OutputStream.h" | ||
#include "ola/network/NetworkUtils.h" | ||
#include "ola/testing/TestUtils.h" | ||
#include "libs/acn/PDUTestCommon.h" | ||
#include "libs/acn/BrokerFetchClientListPDU.h" | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
using ola::acn::BrokerFetchClientListPDU; | ||
using ola::io::IOQueue; | ||
using ola::io::IOStack; | ||
using ola::io::OutputStream; | ||
using ola::network::HostToNetwork; | ||
|
||
class BrokerFetchClientListPDUTest: public CppUnit::TestFixture { | ||
CPPUNIT_TEST_SUITE(BrokerFetchClientListPDUTest); | ||
CPPUNIT_TEST(testSimpleBrokerFetchClientListPDU); | ||
CPPUNIT_TEST(testSimpleBrokerFetchClientListPDUToOutputStream); | ||
CPPUNIT_TEST(testPrepend); | ||
CPPUNIT_TEST_SUITE_END(); | ||
|
||
public: | ||
void testSimpleBrokerFetchClientListPDU(); | ||
void testSimpleBrokerFetchClientListPDUToOutputStream(); | ||
void testPrepend(); | ||
|
||
void setUp() { | ||
ola::InitLogging(ola::OLA_LOG_DEBUG, ola::OLA_LOG_STDERR); | ||
} | ||
|
||
private: | ||
static const uint16_t TEST_VECTOR; | ||
}; | ||
|
||
CPPUNIT_TEST_SUITE_REGISTRATION(BrokerFetchClientListPDUTest); | ||
|
||
const uint16_t BrokerFetchClientListPDUTest::TEST_VECTOR = 39; | ||
|
||
|
||
/* | ||
* Test that packing a BrokerFetchClientListPDU works. | ||
*/ | ||
void BrokerFetchClientListPDUTest::testSimpleBrokerFetchClientListPDU() { | ||
BrokerFetchClientListPDU pdu(TEST_VECTOR); | ||
|
||
OLA_ASSERT_EQ(0u, pdu.HeaderSize()); | ||
OLA_ASSERT_EQ(0u, pdu.DataSize()); | ||
OLA_ASSERT_EQ(5u, pdu.Size()); | ||
|
||
unsigned int size = pdu.Size(); | ||
uint8_t *data = new uint8_t[size]; | ||
unsigned int bytes_used = size; | ||
OLA_ASSERT(pdu.Pack(data, &bytes_used)); | ||
OLA_ASSERT_EQ(size, bytes_used); | ||
|
||
// spot check the data | ||
OLA_ASSERT_EQ((uint8_t) 0xf0, data[0]); | ||
// bytes_used is technically data[1] and data[2] if > 255 | ||
OLA_ASSERT_EQ((uint8_t) bytes_used, data[2]); | ||
uint16_t actual_value; | ||
memcpy(&actual_value, data + 3, sizeof(actual_value)); | ||
OLA_ASSERT_EQ(HostToNetwork(TEST_VECTOR), actual_value); | ||
|
||
// test undersized buffer | ||
bytes_used = size - 1; | ||
OLA_ASSERT_FALSE(pdu.Pack(data, &bytes_used)); | ||
OLA_ASSERT_EQ(0u, bytes_used); | ||
|
||
// test oversized buffer | ||
bytes_used = size + 1; | ||
OLA_ASSERT(pdu.Pack(data, &bytes_used)); | ||
OLA_ASSERT_EQ(size, bytes_used); | ||
delete[] data; | ||
} | ||
|
||
/* | ||
* Test that writing to an output stream works. | ||
*/ | ||
void BrokerFetchClientListPDUTest:: | ||
testSimpleBrokerFetchClientListPDUToOutputStream() { | ||
BrokerFetchClientListPDU pdu(TEST_VECTOR); | ||
|
||
OLA_ASSERT_EQ(0u, pdu.HeaderSize()); | ||
OLA_ASSERT_EQ(0u, pdu.DataSize()); | ||
OLA_ASSERT_EQ(5u, pdu.Size()); | ||
|
||
IOQueue output; | ||
OutputStream stream(&output); | ||
pdu.Write(&stream); | ||
OLA_ASSERT_EQ(5u, output.Size()); | ||
|
||
uint8_t *pdu_data = new uint8_t[output.Size()]; | ||
unsigned int pdu_size = output.Peek(pdu_data, output.Size()); | ||
OLA_ASSERT_EQ(output.Size(), pdu_size); | ||
|
||
uint8_t EXPECTED[] = { | ||
0xf0, 0x00, 0x05, | ||
0, 39 | ||
}; | ||
OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size); | ||
output.Pop(output.Size()); | ||
delete[] pdu_data; | ||
} | ||
|
||
|
||
void BrokerFetchClientListPDUTest::testPrepend() { | ||
IOStack stack; | ||
BrokerFetchClientListPDU::PrependPDU(&stack); | ||
|
||
unsigned int length = stack.Size(); | ||
uint8_t *buffer = new uint8_t[length]; | ||
OLA_ASSERT(stack.Read(buffer, length)); | ||
|
||
const uint8_t expected_data[] = { | ||
0xf0, 0x00, 0x05, | ||
0, 0x06 | ||
}; | ||
OLA_ASSERT_DATA_EQUALS(expected_data, sizeof(expected_data), buffer, length); | ||
delete[] buffer; | ||
} | ||
} // namespace acn | ||
} // namespace ola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters