/**
 * 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"));
}
Beispiel #2
0
/**
 * Check that labels are added
 */
void GenericMessagePrinterTest::testLabeledPrinter() {
  UInt8FieldDescriptor::IntervalVector intervals;
  intervals.push_back(UInt8FieldDescriptor::Interval(0, 2));

  UInt8FieldDescriptor::LabeledValues labels;
  labels["off"] = 0;
  labels["on"] = 1;
  labels["auto"] = 2;

  UInt8FieldDescriptor uint8_descriptor("State", intervals, labels);

  vector<const ola::messaging::MessageFieldInterface*> fields;
  fields.push_back(new UInt8MessageField(&uint8_descriptor, 0));
  fields.push_back(new UInt8MessageField(&uint8_descriptor, 1));
  fields.push_back(new UInt8MessageField(&uint8_descriptor, 2));

  Message message(fields);
  string expected = "State: off\nState: on\nState: auto\n";
  CPPUNIT_ASSERT_EQUAL(expected, m_printer.AsString(&message));
}