Ejemplo n.º 1
0
/**
 * Check that writing an Root PDU to an output stream works
 */
void RootPDUTest::testSimpleRootPDUToOutputStream() {
  CID cid = CID::Generate();
  RootPDU pdu1(TEST_VECTOR, cid, NULL);
  OLA_ASSERT(cid == pdu1.Cid());

  OLA_ASSERT_EQ(16u, pdu1.HeaderSize());
  OLA_ASSERT_EQ(4u, pdu1.VectorSize());
  OLA_ASSERT_EQ(0u, pdu1.DataSize());
  OLA_ASSERT_EQ(22u, pdu1.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu1.Write(&stream);

  OLA_ASSERT_EQ(22u, output.Size());

  uint8_t *raw_pdu = new uint8_t[output.Size()];
  unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size());
  OLA_ASSERT_EQ(output.Size(), raw_pdu_size);

  uint8_t EXPECTED[] = {
    0x70, 22,
    0, 0, 0, 4,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  };
  cid.Pack(EXPECTED + 6);
  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED, sizeof(EXPECTED),
                     raw_pdu, raw_pdu_size);

  output.Pop(output.Size());
  delete[] raw_pdu;
}
Ejemplo n.º 2
0
/*
 * Check that BuildServiceAck() works.
 */
void PacketBuilderTest::testBuildServiceAck() {
  SLPPacketBuilder::BuildServiceAck(&output, xid, EN_LANGUAGE_TAG, 0x5678);
  OLA_ASSERT_EQ(18u, ioqueue.Size());

  {
    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 5, 0, 0, 18, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
      0x56, 0x78
    };
    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }

  SLPPacketBuilder::BuildServiceAck(&output, xid, "en-AU", 0x5678);
  OLA_ASSERT_EQ(21u, ioqueue.Size());

  {
    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 5, 0, 0, 21, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 5, 'e', 'n',
      '-', 'A', 'U', 0x56, 0x78
    };
    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }
}
Ejemplo n.º 3
0
/*
 * Check that BuildError() works.
 */
void PacketBuilderTest::testBuildError() {
  SLPPacketBuilder::BuildError(&output, ola::slp::SERVICE_REPLY, xid,
                               EN_LANGUAGE_TAG,
                               ola::slp::LANGUAGE_NOT_SUPPORTED);
  OLA_ASSERT_EQ(18u, ioqueue.Size());

  unsigned int data_size;
  uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data[] = {
    2, 2, 0, 0, 18, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
    0, 1
  };
  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;

  // try a different function-id & language
  SLPPacketBuilder::BuildError(&output, ola::slp::DA_ADVERTISEMENT, xid,
                               "en-AU", ola::slp::INTERNAL_ERROR);
  OLA_ASSERT_EQ(21u, ioqueue.Size());

  output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data2[] = {
    2, 8, 0, 0, 21, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 5, 'e', 'n',
    '-', 'A', 'U', 0, 10
  };
  ASSERT_DATA_EQUALS(__LINE__, expected_data2, sizeof(expected_data2),
                     output_data, data_size);
  delete[] output_data;
}
Ejemplo n.º 4
0
/*
 * Test that writing to an output stream works.
 */
void E133PDUTest::testSimpleE133PDUToOutputStream() {
  const string source = "foo source";
  E133Header header(source, 101, 2);
  E133PDU pdu(TEST_VECTOR, header, NULL);

  OLA_ASSERT_EQ(71u, pdu.HeaderSize());
  OLA_ASSERT_EQ(0u, pdu.DataSize());
  OLA_ASSERT_EQ(77u, pdu.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu.Write(&stream);
  OLA_ASSERT_EQ(77u, 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[] = {
    0x70, 77,
    0, 0, 0, 39,
    'f', 'o', 'o', ' ', 's', 'o', 'u', 'r', 'c', 'e', 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 101,  // seq #
    0, 2,  // endpoint
    0,
  };
  OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size);
  output.Pop(output.Size());
  delete[] pdu_data;
}
Ejemplo n.º 5
0
/*
 * Check that BuildSAAdvert() works.
 */
void PacketBuilderTest::testBuildSAAdvert() {
  ScopeSet scopes("ACN,MYORG\\2c");

  SLPPacketBuilder::BuildSAAdvert(&output, xid, true, "service:foo", scopes);
  OLA_ASSERT_EQ(46u, ioqueue.Size());

  unsigned int data_size;
  uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data[] = {
    2, 11, 0, 0, 0x2e, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
    0, 11, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o',  // url
    0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c',
    0, 0,  // attr list
    0  // auth blocks
  };

  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;

  // try with a non-multicast packet
  SLPPacketBuilder::BuildSAAdvert(&output, xid, false, "service:foo", scopes);
  OLA_ASSERT_EQ(46u, ioqueue.Size());
  output_data = WriteToBuffer(&ioqueue, &data_size);
  expected_data[5] = 0;
  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;
}
Ejemplo n.º 6
0
/*
 * Check that BuildServiceRequest() works.
 */
void PacketBuilderTest::testBuildServiceRequest() {
  set<IPV4Address> pr_list;
  IPV4Address first_ip, second_ip;
  OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.2", &first_ip));
  OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.8", &second_ip));
  pr_list.insert(first_ip);
  pr_list.insert(second_ip);
  ScopeSet scopes("ACN,MYORG\\2c");

  SLPPacketBuilder::BuildServiceRequest(&output, xid, true, EN_LANGUAGE_TAG,
                                        pr_list, "rdmnet-device", scopes);
  OLA_ASSERT_EQ(66u, ioqueue.Size());

  {
    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 1, 0, 0, 66, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
      0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1',
      '.', '8',  // pr-llist
      0, 13, 'r', 'd', 'm', 'n', 'e', 't', '-', 'd', 'e', 'v', 'i', 'c', 'e',
      0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c',
      0, 0,  // pred string
      0, 0,  // SPI string
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }

  // try a different language
  SLPPacketBuilder::BuildServiceRequest(&output, xid, true, "en-AU",
                                        pr_list, "rdmnet-device", scopes);
  OLA_ASSERT_EQ(69u, ioqueue.Size());

  {
    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 1, 0, 0, 69, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 5, 'e', 'n', '-', 'A',
      'U',
      0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1',
      '.', '8',  // pr-llist
      0, 13, 'r', 'd', 'm', 'n', 'e', 't', '-', 'd', 'e', 'v', 'i', 'c', 'e',
      0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c',
      0, 0,  // pred string
      0, 0,  // SPI string
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }
}
Ejemplo n.º 7
0
/*
 * Check that basic appending works.
 */
void OutputStreamTest::testBasicWrite() {
  BigEndianOutputStream stream(&m_buffer);
  OLA_ASSERT_EQ(0u, m_buffer.Size());
  uint8_t data1[] = {0, 1, 2, 3, 4};

  stream.Write(data1, sizeof(data1));
  OLA_ASSERT_EQ(5u, m_buffer.Size());

  m_buffer.Pop(1);
  OLA_ASSERT_EQ(4u, m_buffer.Size());

  m_buffer.Pop(4);
  OLA_ASSERT_EQ(0u, m_buffer.Size());
}
Ejemplo n.º 8
0
/*
 * Test that packing a RDM PDU works. This uses a command data.
 */
void RDMPDUTest::testRDMPDUWithDataToOutputStream() {
  UID source(1, 2);
  UID destination(3, 4);
  uint8_t rdm_data[] = {0xa5, 0xa5, 0xa5, 0xa5};

  RDMGetRequest *command = new RDMGetRequest(
    source,
    destination,
    0,  // transaction #
    1,  // port id
    0,  // message count
    10,  // sub device
    296,  // param id
    rdm_data,  // data
    sizeof(rdm_data));  // data length

  RDMPDU pdu(command);

  OLA_ASSERT_EQ(0u, pdu.HeaderSize());
  OLA_ASSERT_EQ(29u, pdu.DataSize());
  OLA_ASSERT_EQ(32u, pdu.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu.Write(&stream);
  OLA_ASSERT_EQ(32u, 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[] = {
    0x70, 0x20, TEST_VECTOR,
    1, 0x1c,  // sub code & length
    0, 3, 0, 0, 0, 4,   // dst uid
    0, 1, 0, 0, 0, 2,   // src uid
    0, 1, 0, 0, 10,  // transaction, port id, msg count & sub device
    0x20, 1, 40, 4,  // command, param id, param data length
    0xa5, 0xa5, 0xa5, 0xa5,  // data
    3, 0xdf  // checksum
  };
  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED, sizeof(EXPECTED),
                     pdu_data, pdu_size);
  output.Pop(output.Size());
  delete[] pdu_data;
}
Ejemplo n.º 9
0
/**
 * Check that BuildServiceDeRegistration() works.
 */
void PacketBuilderTest::testBuildServiceDeRegistration() {
  ScopeSet service_scopes("ACN,MYORG,FOO");
  ScopeSet scopes("ACN,MYORG");
  ServiceEntry service_entry(service_scopes, "service:foo://1.1.1.1", 0x1234);

  SLPPacketBuilder::BuildServiceDeRegistration(&output, xid, scopes,
                                               service_entry);

  OLA_ASSERT_EQ(56u, ioqueue.Size());

  unsigned int data_size;
  uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data[] = {
    2, 4, 0, 0, 0x38, 0x0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
    // scope list
    0, 0x9, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g',
    // entry 1
    0, 0x12, 0x34, 0, 21,
    's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/',
    '1', '.', '1', '.', '1', '.', '1',
    0,  // # of URL auths
    0, 0  // tag list length
  };

  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;
}
Ejemplo n.º 10
0
/*
 * Test write to an output stream works.
 */
void RDMCommandTest::testOutputStream() {
  IOQueue output;
  OutputStream stream(&output);
  UID source(1, 2);
  UID destination(3, 4);

  RDMGetRequest command(source,
                        destination,
                        0,  // transaction #
                        1,  // port id
                        0,  // message count
                        10,  // sub device
                        296,  // param id
                        NULL,  // data
                        0);  // data length
  command.Write(&stream);

  uint8_t *raw_command = new uint8_t[output.Size()];
  unsigned int raw_command_size = output.Peek(raw_command, output.Size());
  OLA_ASSERT_EQ(raw_command_size, RDMCommandSerializer::RequiredSize(command));

  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED_GET_BUFFER,
                     sizeof(EXPECTED_GET_BUFFER),
                     raw_command,
                     raw_command_size);
  output.Pop(raw_command_size);
  OLA_ASSERT_EQ(0u, output.Size());
  delete[] raw_command;

  // now try a command with data
  uint32_t data_value = 0xa5a5a5a5;
  RDMSetRequest command2(source,
                         destination,
                         0,  // transaction #
                         1,  // port id
                         0,  // message count
                         10,  // sub device
                         296,  // param id
                         reinterpret_cast<uint8_t*>(&data_value),  // data
                         sizeof(data_value));  // data length

  OLA_ASSERT_EQ(29u, RDMCommandSerializer::RequiredSize(command2));

  command2.Write(&stream);
  OLA_ASSERT_EQ(RDMCommandSerializer::RequiredSize(command2), output.Size());

  raw_command = new uint8_t[output.Size()];
  raw_command_size = output.Peek(raw_command, output.Size());
  OLA_ASSERT_EQ(raw_command_size, RDMCommandSerializer::RequiredSize(command2));

  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED_SET_BUFFER,
                     sizeof(EXPECTED_SET_BUFFER),
                     raw_command,
                     raw_command_size);
  output.Pop(raw_command_size);
  OLA_ASSERT_EQ(0u, output.Size());
  delete[] raw_command;
}
Ejemplo n.º 11
0
/*
 * Test writing an empty PDU to an OutputStream works.
 */
void RDMPDUTest::testEmptyPDUToOutputStream() {
  RDMPDU pdu(NULL);

  OLA_ASSERT_EQ(0u, pdu.HeaderSize());
  OLA_ASSERT_EQ(0u, pdu.DataSize());
  OLA_ASSERT_EQ(3u, pdu.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu.Write(&stream);
  OLA_ASSERT_EQ(3u, 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);

  const uint8_t EXPECTED[] = {0x70, 3, TEST_VECTOR};
  OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size);
  output.Pop(output.Size());
  delete[] pdu_data;
}
Ejemplo n.º 12
0
/**
 * Check that BuildServiceRegistration() works.
 */
void PacketBuilderTest::testBuildServiceRegistration() {
  ScopeSet service_scopes("ACN,MYORG,FOO");
  ScopeSet scopes("ACN,MYORG\\2c");
  ServiceEntry service_entry(service_scopes, "service:foo://1.1.1.1", 0x1234);

  SLPPacketBuilder::BuildServiceRegistration(&output, xid, true, scopes,
                                             service_entry);
  OLA_ASSERT_EQ(73u, ioqueue.Size());

  unsigned int data_size;
  uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data[] = {
    2, 3, 0, 0, 0x49, 0x40, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
    // entry 1
    0, 0x12, 0x34, 0, 21,
    's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/',
    '1', '.', '1', '.', '1', '.', '1',
    0,  // # of auth blocks
    0, 0xb, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o',
    0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c',
    0, 0,
    0,  // attr auths
  };

  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;

  // now test a re-registration
  SLPPacketBuilder::BuildServiceRegistration(&output, xid + 1, false, scopes,
      service_entry);
  OLA_ASSERT_EQ(73u, ioqueue.Size());

  output_data = WriteToBuffer(&ioqueue, &data_size);
  expected_data[5] = 0;
  expected_data[11] = 0x35;
  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;
}
Ejemplo n.º 13
0
/*
 * Check that the << operators work
 */
void OutputStreamTest::testWritePrimatives() {
  BigEndianOutputStream stream(&m_buffer);
  OLA_ASSERT_EQ(0u, m_buffer.Size());

  stream << 4;
  OLA_ASSERT_EQ(4u, m_buffer.Size());

  stream << (1u << 31);
  OLA_ASSERT_EQ(8u, m_buffer.Size());

  stream << static_cast<uint8_t>(10) << static_cast<uint16_t>(2400);
  OLA_ASSERT_EQ(11u, m_buffer.Size());

  // confirm this matches what we expect
  const unsigned int DATA_SIZE = 20;
  uint8_t *output_data = new uint8_t[DATA_SIZE];

  uint8_t data1[] = {0, 0, 0, 4, 0x80, 0, 0, 0, 0xa, 0x9, 0x60};
  unsigned int output_size = m_buffer.Peek(output_data, m_buffer.Size());
  OLA_ASSERT_DATA_EQUALS(data1, sizeof(data1), output_data, output_size);
  delete[] output_data;
}
Ejemplo n.º 14
0
/*
 * Test that packing a RootPDU with nested data works
 */
void RootPDUTest::testNestedRootPDUToOutputStream() {
  FakePDU pdu1(1);
  FakePDU pdu2(42);
  PDUBlock<PDU> block;
  block.AddPDU(&pdu1);
  block.AddPDU(&pdu2);

  CID cid = CID::Generate();
  RootPDU pdu(TEST_VECTOR, cid, &block);

  OLA_ASSERT(cid == pdu.Cid());
  OLA_ASSERT_EQ(30u, pdu.Size());

  IOQueue output;
  OutputStream stream(&output);
  pdu.Write(&stream);
  OLA_ASSERT_EQ(30u, output.Size());

  uint8_t *raw_pdu = new uint8_t[output.Size()];
  unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size());
  OLA_ASSERT_EQ(output.Size(), raw_pdu_size);

  uint8_t EXPECTED[] = {
    0x70, 30,
    0, 0, 0, 4,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 1,
    0, 0, 0, 42
  };
  cid.Pack(EXPECTED + 6);
  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED, sizeof(EXPECTED),
                     raw_pdu, raw_pdu_size);

  output.Pop(output.Size());
  delete[] raw_pdu;
}
Ejemplo n.º 15
0
/*
 * Check that BuildDAAdvert() works.
 */
void PacketBuilderTest::testBuildDAAdvert() {
  ScopeSet scopes("ACN,MYORG\\2c");

  SLPPacketBuilder::BuildDAAdvert(&output, xid, true, 12, 0x12345678,
      "service:foo", scopes);
  OLA_ASSERT_EQ(54u, ioqueue.Size());

  unsigned int data_size;
  uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data[] = {
    2, 8, 0, 0, 0x36, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
    0, 0,  // error code is zeroed out if multicast
    0x12, 0x34, 0x56, 0x78,  // boot timestamp
    0, 11, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o',  // service
    0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c',
    0, 0,  // attr list
    0, 0,  // SPI list
    0  // auth blocks
  };

  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;

  // try with a non-multicast packet
  SLPPacketBuilder::BuildDAAdvert(&output, xid, false, 12, 0x12345678,
      "service:foo", scopes);
  OLA_ASSERT_EQ(54u, ioqueue.Size());
  output_data = WriteToBuffer(&ioqueue, &data_size);
  expected_data[5] = 0;
  // update error code
  expected_data[17] = 0xc;
  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;
}
Ejemplo n.º 16
0
/*
 * Check that BuildServiceTypeReply() works.
 */
void PacketBuilderTest::testBuildServiceTypeReply() {
  ScopeSet scopes("ACN,MYORG\\2c");
  vector<string> service_types;
  service_types.push_back("lpr");
  service_types.push_back("foo,bar");  // check escaping

  SLPPacketBuilder::BuildServiceTypeReply(&output, xid, 0, service_types);
  OLA_ASSERT_EQ(33u, ioqueue.Size());

  unsigned int data_size;
  uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
  uint8_t expected_data[] = {
    2, 10, 0, 0, 0x21, 0x0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
    0, 0,  // error code
    0, 13,
    'l', 'p', 'r', ',', 'f', 'o', 'o', '\\', '2', 'c', 'b', 'a', 'r'
  };

  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output_data, data_size);
  delete[] output_data;
}
Ejemplo n.º 17
0
/*
 * Check that BuildServiceTypeRequest() works.
 */
void PacketBuilderTest::testBuildServiceTypeRequest() {
  set<IPV4Address> pr_list;
  IPV4Address first_ip, second_ip;
  OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.2", &first_ip));
  OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.8", &second_ip));
  pr_list.insert(first_ip);
  pr_list.insert(second_ip);

  ScopeSet scopes("ACN,MYORG\\2c");

  {
    // request for all service-types
    SLPPacketBuilder::BuildAllServiceTypeRequest(&output, xid, true, pr_list,
                                                 scopes);
    OLA_ASSERT_EQ(49u, ioqueue.Size());

    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 9, 0, 0, 0x31, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
      0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1',
      '.', '8',  // pr-list
      0xff, 0xff,   // naming auth length
      0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c'
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }

  {
    // request for IANA types
    SLPPacketBuilder::BuildServiceTypeRequest(&output, xid, true, pr_list, "",
                                              scopes);
    OLA_ASSERT_EQ(49u, ioqueue.Size());

    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 9, 0, 0, 0x31, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
      0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1',
      '.', '8',  // pr-list
      0x0, 0x0,   // naming auth length
      0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c'
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }

  {
    // request for a specific naming auth
    SLPPacketBuilder::BuildServiceTypeRequest(&output, xid, true, pr_list,
                                              "foo", scopes);
    OLA_ASSERT_EQ(52u, ioqueue.Size());

    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 9, 0, 0, 0x34, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
      0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1',
      '.', '8',  // pr-list
      0x0, 0x3, 'f', 'o', 'o',  // naming auth length
      0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c'
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }
}
Ejemplo n.º 18
0
/**
 * Check that BuildServiceReply() works.
 */
void PacketBuilderTest::testBuildServiceReply() {
  URLEntry entry1("service:foo://1.1.1.1", 0x1234);
  URLEntry entry2("service:foo://1.1.1.10", 0x5678);
  URLEntries url_entries;
  url_entries.push_back(entry1);
  url_entries.push_back(entry2);

  SLPPacketBuilder::BuildServiceReply(&output, xid, EN_LANGUAGE_TAG, 12,
                                      url_entries);
  OLA_ASSERT_EQ(75u, ioqueue.Size());

  {
    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 2, 0, 0, 0x4b, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n',
      0, 12,  // error code
      0, 2,  // url entry count
      // entry 1
      0, 0x12, 0x34, 0, 21,
      's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/',
      '1', '.', '1', '.', '1', '.', '1',
      0,  // # of auth blocks
      // entry 2
      0, 0x56, 0x78, 0, 22,
      's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/',
      '1', '.', '1', '.', '1', '.', '1', '0',
      0,  // # of auth blocks
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }

  // try a different language
  SLPPacketBuilder::BuildServiceReply(&output, xid, "en-AU", 12,
                                      url_entries);
  OLA_ASSERT_EQ(78u, ioqueue.Size());

  {
    unsigned int data_size;
    uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size);
    uint8_t expected_data[] = {
      2, 2, 0, 0, 0x4e, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 5, 'e', 'n',
      '-', 'A', 'U',
      0, 12,  // error code
      0, 2,  // url entry count
      // entry 1
      0, 0x12, 0x34, 0, 21,
      's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/',
      '1', '.', '1', '.', '1', '.', '1',
      0,  // # of auth blocks
      // entry 2
      0, 0x56, 0x78, 0, 22,
      's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/',
      '1', '.', '1', '.', '1', '.', '1', '0',
      0,  // # of auth blocks
    };

    ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                       output_data, data_size);
    delete[] output_data;
  }
}