Skip to content

Commit

Permalink
Merge pull request #1896 from peternewman/mac-type-tests
Browse files Browse the repository at this point in the history
Add some testing of MAC addresses within messaging fields
  • Loading branch information
peternewman committed Sep 4, 2023
2 parents 96aa95e + 8bcce71 commit 2666ce5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
8 changes: 8 additions & 0 deletions common/messaging/DescriptorTest.cpp
Expand Up @@ -34,6 +34,7 @@ using ola::messaging::BoolFieldDescriptor;
using ola::messaging::FieldDescriptor;
using ola::messaging::FieldDescriptorGroup;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::StringFieldDescriptor;
using ola::messaging::UIDFieldDescriptor;
using ola::messaging::UInt16FieldDescriptor;
Expand Down Expand Up @@ -76,6 +77,13 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_TRUE(ipv4_descriptor.LimitedSize());
OLA_ASSERT_EQ(4u, ipv4_descriptor.MaxSize());

// MAC address
MACFieldDescriptor mac_descriptor("mac");
OLA_ASSERT_EQ(string("mac"), mac_descriptor.Name());
OLA_ASSERT_TRUE(mac_descriptor.FixedSize());
OLA_ASSERT_TRUE(mac_descriptor.LimitedSize());
OLA_ASSERT_EQ(6u, mac_descriptor.MaxSize());

// UID
UIDFieldDescriptor uid_descriptor("uid");
OLA_ASSERT_EQ(string("uid"), uid_descriptor.Name());
Expand Down
18 changes: 13 additions & 5 deletions common/messaging/MessagePrinterTest.cpp
Expand Up @@ -33,20 +33,23 @@
using std::string;
using std::vector;
using ola::rdm::UID;
using ola::network::MACAddress;


using ola::messaging::BoolFieldDescriptor;
using ola::messaging::BoolMessageField;
using ola::messaging::FieldDescriptor;
using ola::messaging::FieldDescriptorGroup;
using ola::messaging::GroupMessageField;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::GenericMessagePrinter;
using ola::messaging::IPV4MessageField;
using ola::messaging::GroupMessageField;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int16MessageField;
using ola::messaging::Int8FieldDescriptor;
using ola::messaging::Int8MessageField;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::IPV4MessageField;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::MACMessageField;
using ola::messaging::Message;
using ola::messaging::MessageFieldInterface;
using ola::messaging::StringFieldDescriptor;
Expand Down Expand Up @@ -87,6 +90,7 @@ void GenericMessagePrinterTest::testSimplePrinter() {
// setup some fields
BoolFieldDescriptor bool_descriptor("On/Off");
IPV4FieldDescriptor ipv4_descriptor("ip");
MACFieldDescriptor mac_descriptor("mac");
UIDFieldDescriptor uid_descriptor("uid");
StringFieldDescriptor string_descriptor("Name", 0, 32);
UInt32FieldDescriptor uint32_descriptor("Id");
Expand All @@ -100,6 +104,9 @@ void GenericMessagePrinterTest::testSimplePrinter() {
fields.push_back(
new IPV4MessageField(&ipv4_descriptor,
ola::network::HostToNetwork(0x0a000001)));
fields.push_back(
new MACMessageField(&mac_descriptor,
MACAddress::FromStringOrDie("01:23:45:67:89:ab")));
fields.push_back(new UIDMessageField(&uid_descriptor, UID(0x7a70, 1)));
fields.push_back(new StringMessageField(&string_descriptor, "foobar"));
fields.push_back(new UInt32MessageField(&uint32_descriptor, 42));
Expand All @@ -109,8 +116,9 @@ void GenericMessagePrinterTest::testSimplePrinter() {

Message message(fields);
string expected = (
"On/Off: false\nip: 10.0.0.1\nuid: 7a70:00000001\nName: foobar\nId: 42\n"
"Count: 4 x 10 ^ -3\nDelta: 10 x 10 ^ 1\nRate: 10 x 10 ^ -1\n");
"On/Off: false\nip: 10.0.0.1\nmac: 01:23:45:67:89:ab\n"
"uid: 7a70:00000001\nName: foobar\nId: 42\nCount: 4 x 10 ^ -3\n"
"Delta: 10 x 10 ^ 1\nRate: 10 x 10 ^ -1\n");
OLA_ASSERT_EQ(expected, m_printer.AsString(&message));
}

Expand Down
11 changes: 7 additions & 4 deletions common/rdm/GroupSizeCalculatorTest.cpp
Expand Up @@ -37,6 +37,7 @@ using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int32FieldDescriptor;
using ola::messaging::Int8FieldDescriptor;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::StringFieldDescriptor;
using ola::messaging::UIDFieldDescriptor;
using ola::messaging::UInt16FieldDescriptor;
Expand Down Expand Up @@ -83,6 +84,7 @@ void GroupSizeCalculatorTest::testSimpleCases() {
fields.push_back(new Int8FieldDescriptor("int8"));
fields.push_back(new Int16FieldDescriptor("int16"));
fields.push_back(new Int32FieldDescriptor("int32"));
fields.push_back(new MACFieldDescriptor("mac"));
fields.push_back(new StringFieldDescriptor("string", 0, 32));
fields.push_back(new IPV4FieldDescriptor("address"));
fields.push_back(new UIDFieldDescriptor("uid"));
Expand All @@ -91,7 +93,8 @@ void GroupSizeCalculatorTest::testSimpleCases() {
unsigned int token_count, group_repeat_count;
OLA_ASSERT_TRUE(
m_static_calculator.CalculateTokensRequired(&descriptor, &token_count));
OLA_ASSERT_EQ(10u, token_count);
OLA_ASSERT_EQ(11u, token_count); // Actual token count


OLA_ASSERT_EQ(
GroupSizeCalculator::INSUFFICIENT_TOKENS,
Expand All @@ -103,21 +106,21 @@ void GroupSizeCalculatorTest::testSimpleCases() {
OLA_ASSERT_EQ(
GroupSizeCalculator::INSUFFICIENT_TOKENS,
m_calculator.CalculateGroupSize(
9,
10, // Actual token count - 1
&descriptor,
&group_repeat_count));

OLA_ASSERT_EQ(
GroupSizeCalculator::NO_VARIABLE_GROUPS,
m_calculator.CalculateGroupSize(
10,
11, // Actual token count
&descriptor,
&group_repeat_count));

OLA_ASSERT_EQ(
GroupSizeCalculator::EXTRA_TOKENS,
m_calculator.CalculateGroupSize(
11,
12, // Actual token count + 1
&descriptor,
&group_repeat_count));
}
Expand Down

0 comments on commit 2666ce5

Please sign in to comment.