Ejemplo n.º 1
0
/**
 * test device model description works
 */
void RDMMessageInterationTest::testDeviceModelDescription() {
  const PidDescriptor *device_model_pid =
    m_esta_store->LookupPID(ola::rdm::PID_DEVICE_MODEL_DESCRIPTION);
  OLA_ASSERT_TRUE(device_model_pid);
  const Descriptor *descriptor = device_model_pid->GetResponse();
  OLA_ASSERT_TRUE(descriptor);

  vector<string> inputs;
  inputs.push_back("wigglelight 2000");  // description

  auto_ptr<const Message> message(m_builder.GetMessage(inputs, descriptor));
  OLA_ASSERT_TRUE(message.get());

  unsigned int data_length;
  const uint8_t *data = m_serializer.SerializeMessage(message.get(),
                                                      &data_length);
  OLA_ASSERT_TRUE(data);
  OLA_ASSERT_EQ(16u, data_length);

  auto_ptr<const Message> inflated_message(
      m_deserializer.InflateMessage(descriptor, data, data_length));
  OLA_ASSERT_TRUE(inflated_message.get());

  const string input = m_printer.AsString(message.get());
  const string output = m_printer.AsString(inflated_message.get());
  OLA_ASSERT_EQ(input, output);

  const string expected = "description: wigglelight 2000\n";
  OLA_ASSERT_EQ(expected, output);
}
/**
 * Check the StringBuilder works with variable sized groups.
 */
void StringBuilderTest::testBuilderWithGroups() {
  // build the descriptor
  vector<const FieldDescriptor*> group_fields;
  group_fields.push_back(new BoolFieldDescriptor("bool"));
  group_fields.push_back(new UInt8FieldDescriptor("uint8"));

  vector<const FieldDescriptor*> fields;
  fields.push_back(new FieldDescriptorGroup("group", group_fields, 0, 3));
  Descriptor descriptor("Test Descriptor", fields);

  // now setup the inputs
  vector<string> inputs;
  inputs.push_back("true");
  inputs.push_back("10");

  auto_ptr<const Message> message(BuildMessage(descriptor, inputs));

  // verify
  OLA_ASSERT_TRUE(message.get());
  OLA_ASSERT_EQ(1u, message->FieldCount());

  string expected = (
      "group {\n  bool: true\n  uint8: 10\n}\n");
  OLA_ASSERT_EQ(expected, m_printer.AsString(message.get()));

  // now do multiple groups
  vector<string> inputs2;
  inputs2.push_back("true");
  inputs2.push_back("10");
  inputs2.push_back("true");
  inputs2.push_back("42");
  inputs2.push_back("false");
  inputs2.push_back("240");

  auto_ptr<const Message> message2(BuildMessage(descriptor, inputs2));

  // verify
  OLA_ASSERT_NOT_NULL(message2.get());
  OLA_ASSERT_EQ(3u, message2->FieldCount());

  string expected2 = (
      "group {\n  bool: true\n  uint8: 10\n}\n"
      "group {\n  bool: true\n  uint8: 42\n}\n"
      "group {\n  bool: false\n  uint8: 240\n}\n");
  OLA_ASSERT_EQ(expected2, m_printer.AsString(message2.get()));

  // now provide too many inputs
  inputs2.clear();
  inputs2.push_back("true");
  inputs2.push_back("10");
  inputs2.push_back("true");
  inputs2.push_back("42");
  inputs2.push_back("false");
  inputs2.push_back("240");
  inputs2.push_back("false");
  inputs2.push_back("53");

  OLA_ASSERT_NULL(BuildMessage(descriptor, inputs2));
}
/**
 * test StringBuilder with nested fixed groups
 */
void StringBuilderTest::testBuilderWithNestedGroups() {
  vector<const FieldDescriptor*> fields, group_fields, group_fields2;
  group_fields.push_back(new BoolFieldDescriptor("bool"));

  group_fields2.push_back(new Int16FieldDescriptor("int16"));
  group_fields2.push_back(new FieldDescriptorGroup("bar", group_fields, 2, 2));

  const FieldDescriptorGroup *nested_group = new FieldDescriptorGroup(
      "", group_fields2, 0, 4);

  fields.push_back(nested_group);
  Descriptor descriptor("Test Descriptor", fields);

  vector<string> inputs;
  inputs.push_back("1");
  inputs.push_back("true");
  inputs.push_back("true");

  auto_ptr<const Message> message(BuildMessage(descriptor, inputs));

  // verify
  OLA_ASSERT_NOT_NULL(message.get());
  OLA_ASSERT_EQ(1u, message->FieldCount());

  string expected = (
      " {\n  int16: 1\n  bar {\n    bool: true\n  }\n"
      "  bar {\n    bool: true\n  }\n}\n");
  OLA_ASSERT_EQ(expected, m_printer.AsString(message.get()));
}
/**
 * Check the builder accepts labels
 */
void StringBuilderTest::testBuilderWithLabels() {
  // build the descriptor
  UInt8FieldDescriptor::IntervalVector intervals;
  UInt8FieldDescriptor::LabeledValues labels;
  labels["dozen"] = 12;
  labels["bakers_dozen"] = 13;

  vector<const FieldDescriptor*> fields;
  fields.push_back(new UInt8FieldDescriptor("uint8", intervals, labels));
  Descriptor descriptor("Test Descriptor", fields);

  // now setup the inputs
  vector<string> inputs;
  inputs.push_back("dozen");
  auto_ptr<const Message> message(BuildMessage(descriptor, inputs));

  // verify
  OLA_ASSERT_NOT_NULL(message.get());
  OLA_ASSERT_EQ(static_cast<unsigned int>(fields.size()),
                message->FieldCount());

  string expected = "uint8: dozen\n";
  OLA_ASSERT_EQ(expected, m_printer.AsString(message.get()));

  // Test an invalid case
  // setup the inputs
  vector<string> inputs2;
  inputs2.push_back("half_dozen");
  auto_ptr<const Message> message2(BuildMessage(descriptor, inputs2));

  // verify
  OLA_ASSERT_NULL(message2.get());
}
Ejemplo n.º 5
0
/**
 * test Device Info Request
 */
void RDMMessageInterationTest::testDeviceInfoRequest() {
  const PidDescriptor *device_info_pid =
    m_esta_store->LookupPID(ola::rdm::PID_DEVICE_INFO);
  OLA_ASSERT_TRUE(device_info_pid);
  const Descriptor *descriptor = device_info_pid->GetResponse();
  OLA_ASSERT_TRUE(descriptor);

  vector<string> inputs;
  inputs.push_back("1");  // major
  inputs.push_back("0");  // minor
  inputs.push_back("300");  // device model
  inputs.push_back("400");  // product category
  inputs.push_back("40000");  // software version
  inputs.push_back("512");  // dmx footprint
  inputs.push_back("1");  // current personality
  inputs.push_back("5");  // personality count
  inputs.push_back("1");  // dmx start address
  inputs.push_back("0");  // sub device count
  inputs.push_back("6");  // sensor count

  auto_ptr<const Message> message(m_builder.GetMessage(inputs, descriptor));
  OLA_ASSERT_TRUE(message.get());

  unsigned int data_length;
  const uint8_t *data = m_serializer.SerializeMessage(message.get(),
                                                      &data_length);
  OLA_ASSERT_TRUE(data);
  OLA_ASSERT_EQ(19u, data_length);

  auto_ptr<const Message> inflated_message(
      m_deserializer.InflateMessage(descriptor, data, data_length));
  OLA_ASSERT_TRUE(inflated_message.get());

  const string input = m_printer.AsString(message.get());
  const string output = m_printer.AsString(inflated_message.get());
  OLA_ASSERT_EQ(input, output);

  const string expected = (
      "protocol_major: 1\nprotocol_minor: 0\ndevice_model: 300\n"
      "product_category: 400\nsoftware_version: 40000\n"
      "dmx_footprint: 512\ncurrent_personality: 1\npersonality_count: 5\n"
      "dmx_start_address: 1\nsub_device_count: 0\nsensor_count: 6\n");
  OLA_ASSERT_EQ(expected, output);
}
Ejemplo n.º 6
0
/**
 * test parameter description works
 */
void RDMMessageInterationTest::testParameterDescription() {
  const PidDescriptor *param_description_pid =
    m_esta_store->LookupPID(ola::rdm::PID_PARAMETER_DESCRIPTION);
  OLA_ASSERT_TRUE(param_description_pid);
  const Descriptor *descriptor = param_description_pid->GetResponse();
  OLA_ASSERT_TRUE(descriptor);

  vector<string> inputs;
  inputs.push_back("8000");  // pid
  inputs.push_back("2");  // pdl size
  inputs.push_back("6");  // data type
  inputs.push_back("3");  // command class
  inputs.push_back("0");  // type (unused)
  inputs.push_back("1");  // unit
  inputs.push_back("0");  // prefix
  inputs.push_back("0");  // min valid value
  inputs.push_back("400");  // max valid value
  inputs.push_back("0");  // default value
  inputs.push_back("room temp");  // description

  auto_ptr<const Message> message(m_builder.GetMessage(inputs, descriptor));
  OLA_ASSERT_TRUE(message.get());

  unsigned int data_length;
  const uint8_t *data = m_serializer.SerializeMessage(message.get(),
                                                      &data_length);
  OLA_ASSERT_TRUE(data);
  OLA_ASSERT_EQ(29u, data_length);

  auto_ptr<const Message> inflated_message(
      m_deserializer.InflateMessage(descriptor, data, data_length));
  OLA_ASSERT_TRUE(inflated_message.get());

  const string input = m_printer.AsString(message.get());
  const string output = m_printer.AsString(inflated_message.get());
  OLA_ASSERT_EQ(input, output);

  const string expected = (
      "pid: 8000\npdl_size: 2\ndata_type: 6\ncommand_class: 3\n"
      "type: 0\nunit: 1\nprefix: 0\nmin_value: 0\nmax_value: 400\n"
      "default_value: 0\ndescription: room temp\n");
  OLA_ASSERT_EQ(expected, output);
}
/**
 * Check the StringBuilder works.
 */
void StringBuilderTest::testSimpleBuilder() {
  // build the descriptor
  vector<const FieldDescriptor*> fields;
  fields.push_back(new BoolFieldDescriptor("bool1"));
  fields.push_back(new BoolFieldDescriptor("bool2"));
  fields.push_back(new BoolFieldDescriptor("bool3"));
  fields.push_back(new BoolFieldDescriptor("bool4"));
  fields.push_back(new BoolFieldDescriptor("bool5"));
  fields.push_back(new BoolFieldDescriptor("bool6"));
  fields.push_back(new IPV4FieldDescriptor("ip1"));
  fields.push_back(new MACFieldDescriptor("mac1"));
  fields.push_back(new UInt8FieldDescriptor("uint8"));
  fields.push_back(new UInt16FieldDescriptor("uint16"));
  fields.push_back(new UInt32FieldDescriptor("uint32"));
  fields.push_back(new Int8FieldDescriptor("int8"));
  fields.push_back(new Int16FieldDescriptor("int16"));
  fields.push_back(new Int32FieldDescriptor("int32"));
  fields.push_back(new StringFieldDescriptor("string", 0, 32));
  fields.push_back(new UInt16FieldDescriptor("hex uint16"));
  Descriptor descriptor("Test Descriptor", fields);

  // now setup the inputs
  vector<string> inputs;
  inputs.push_back("true");
  inputs.push_back("false");
  inputs.push_back("1");
  inputs.push_back("0");
  inputs.push_back("TRUE");
  inputs.push_back("FALSE");
  inputs.push_back("10.0.0.1");
  inputs.push_back("01:23:45:67:89:ab");
  inputs.push_back("255");
  inputs.push_back("300");
  inputs.push_back("66000");
  inputs.push_back("-128");
  inputs.push_back("-300");
  inputs.push_back("-66000");
  inputs.push_back("foo");
  inputs.push_back("0x400");

  auto_ptr<const Message> message(BuildMessage(descriptor, inputs));

  // verify
  OLA_ASSERT_TRUE(message.get());
  OLA_ASSERT_EQ(static_cast<unsigned int>(fields.size()),
                       message->FieldCount());

  string expected = (
      "bool1: true\nbool2: false\nbool3: true\nbool4: false\nbool5: true\n"
      "bool6: false\nip1: 10.0.0.1\nmac1: 01:23:45:67:89:ab\nuint8: 255\n"
      "uint16: 300\nuint32: 66000\nint8: -128\nint16: -300\nint32: -66000\n"
      "string: foo\nhex uint16: 1024\n");
  OLA_ASSERT_EQ(expected, m_printer.AsString(message.get()));
}
Ejemplo n.º 8
0
/**
 * test PROXIED_DEVICES
 */
void RDMMessageInterationTest::testProxiedDevices() {
  const PidDescriptor *device_info_pid =
    m_esta_store->LookupPID(ola::rdm::PID_PROXIED_DEVICES);
  OLA_ASSERT_NOT_NULL(device_info_pid);
  const Descriptor *descriptor = device_info_pid->GetResponse();
  OLA_ASSERT_TRUE(descriptor);

  vector<string> inputs;
  inputs.push_back("31344");  // manufacturer ID
  inputs.push_back("1");  // device id
  inputs.push_back("31344");  // manufacturer ID
  inputs.push_back("2");  // device id
  inputs.push_back("21324");  // manufacturer ID
  inputs.push_back("1");  // device id

  auto_ptr<const Message> message(m_builder.GetMessage(inputs, descriptor));
  OLA_ASSERT_TRUE(message.get());

  unsigned int data_length;
  const uint8_t *data = m_serializer.SerializeMessage(message.get(),
                                                      &data_length);
  OLA_ASSERT_TRUE(data);
  OLA_ASSERT_EQ(18u, data_length);

  auto_ptr<const Message> inflated_message(
      m_deserializer.InflateMessage(descriptor, data, data_length));
  OLA_ASSERT_TRUE(inflated_message.get());

  const string input = m_printer.AsString(message.get());
  const string output = m_printer.AsString(inflated_message.get());
  OLA_ASSERT_EQ(input, output);

  const string expected = (
      "uids {\n  manufacturer_id: 31344\n  device_id: 1\n}\n"
      "uids {\n  manufacturer_id: 31344\n  device_id: 2\n}\n"
      "uids {\n  manufacturer_id: 21324\n  device_id: 1\n}\n");
  OLA_ASSERT_EQ(expected, output);
}
/**
 * Check the builder accepts labels and intervals
 */
void StringBuilderTest::testBuilderWithLabelsAndIntervals() {
  // build the descriptor
  UInt8FieldDescriptor::IntervalVector intervals;
  intervals.push_back(UInt16FieldDescriptor::Interval(2, 8));
  intervals.push_back(UInt16FieldDescriptor::Interval(12, 14));
  UInt8FieldDescriptor::LabeledValues labels;
  labels["dozen"] = 12;
  labels["bakers_dozen"] = 13;

  vector<const FieldDescriptor*> fields;
  fields.push_back(new UInt8FieldDescriptor("uint8", intervals, labels));
  Descriptor descriptor("Test Descriptor", fields);

  auto_ptr<const Message> message(BuildMessageSingleInput(descriptor, "dozen"));

  // verify
  OLA_ASSERT_NOT_NULL(message.get());
  OLA_ASSERT_EQ(static_cast<unsigned int>(fields.size()),
                message->FieldCount());

  string expected = "uint8: dozen\n";
  OLA_ASSERT_EQ(expected, m_printer.AsString(message.get()));


  // Test an invalid case
  auto_ptr<const Message> message2(BuildMessageSingleInput(descriptor,
                                                           "half_dozen"));

  // verify
  OLA_ASSERT_NULL(message2.get());

  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "0"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "1"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "2"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "8"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "9"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "11"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "12"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "13"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "14"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "15"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "255"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "65535"));

  // check labels
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "one"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "dozen"));
  OLA_ASSERT_NOT_NULL(BuildMessageSingleInput(descriptor, "bakers_dozen"));
  OLA_ASSERT_NULL(BuildMessageSingleInput(descriptor, "twenty"));
}