Example #1
0
/*
 * test the IntToString function.
 */
void StringUtilsTest::testIntToString() {
  OLA_ASSERT_EQ(string("0"), IntToString(0));
  OLA_ASSERT_EQ(string("1234"), IntToString(1234));
  OLA_ASSERT_EQ(string("-1234"), IntToString(-1234));
  unsigned int i = 42;
  OLA_ASSERT_EQ(string("42"), IntToString(i));
}
Example #2
0
/*
 * Setup the Node
 */
bool OSCNode::Init() {
  // create a new lo_server
  // lo_server_new_with_proto doesn't understand that "0" means "any port".
  // Instead you have to pass in NULL. Weird.
  if (m_listen_port) {
    m_osc_server = lo_server_new_with_proto(IntToString(m_listen_port).c_str(),
                                            LO_UDP, OSCErrorHandler);
  } else {
    m_osc_server = lo_server_new_with_proto(NULL, LO_UDP, OSCErrorHandler);
  }

  if (!m_osc_server)
    return false;

  // Get the socket descriptor that liblo is using, create a
  // UnmanagedFileDescriptor, assign a callback and register with the
  // SelectServer.
  int fd = lo_server_get_socket_fd(m_osc_server);
  m_descriptor.reset(new ola::io::UnmanagedFileDescriptor(fd));
  m_descriptor->SetOnData(NewCallback(this, &OSCNode::DescriptorReady));
  m_ss->AddReadDescriptor(m_descriptor.get());

  // liblo doesn't support address pattern matching. So rather than registering
  // a bunch of handlers, we just register for any address matching the types
  // we want, and handle the dispatching ourselves. NULL means 'any address'
  // Similarly liblo tries to coerce types so rather than letting it do
  // anything we just register for all types and sort it out ourselves.
  lo_server_add_method(m_osc_server, NULL, NULL, OSCDataHandler, this);
  return true;
}
Example #3
0
OSCNode::NodeOSCTarget::NodeOSCTarget(const OSCTarget &target)
  : socket_address(target.socket_address),
    osc_address(target.osc_address),
    liblo_address(lo_address_new(
      socket_address.Host().ToString().c_str(),
      IntToString(socket_address.Port()).c_str())) {
}
Example #4
0
/*
 * Check that we can get/set the preferences
 */
void PreferencesTest::testGetSetRemove() {
  MemoryPreferencesFactory factory;
  Preferences *preferences = factory.NewPreference("dummy");

  string key1 = "foo";
  string key2 = "bat";
  string value1 = "bar";
  string value2 = "baz";
  unsigned int value3 = 1;
  unsigned int value4 = 2;
  int value5 = 3;
  int value6 = 4;

  // test get/set/has single values string
  OLA_ASSERT_EQ(string(""), preferences->GetValue(key1));
  preferences->SetValue(key1, value1);
  OLA_ASSERT_EQ(value1, preferences->GetValue(key1));
  OLA_ASSERT(preferences->HasKey(key1));
  preferences->SetValue(key1, value2);
  OLA_ASSERT_EQ(value2, preferences->GetValue(key1));

  preferences->RemoveValue(key1);
  OLA_ASSERT_EQ(string(""), preferences->GetValue(key1));
  OLA_ASSERT_FALSE(preferences->HasKey(key1));

  // test get/set/has single values uint
  OLA_ASSERT_EQ(string(""), preferences->GetValue(key1));
  preferences->SetValue(key1, value3);
  OLA_ASSERT_EQ(IntToString(value3), preferences->GetValue(key1));
  OLA_ASSERT(preferences->HasKey(key1));
  preferences->SetValue(key1, value4);
  OLA_ASSERT_EQ(IntToString(value4), preferences->GetValue(key1));

  preferences->RemoveValue(key1);
  OLA_ASSERT_EQ(string(""), preferences->GetValue(key1));
  OLA_ASSERT_FALSE(preferences->HasKey(key1));

  // test get/set/has single values int
  OLA_ASSERT_EQ(string(""), preferences->GetValue(key1));
  preferences->SetValue(key1, value5);
  OLA_ASSERT_EQ(IntToString(value5), preferences->GetValue(key1));
  OLA_ASSERT(preferences->HasKey(key1));
  preferences->SetValue(key1, value6);
  OLA_ASSERT_EQ(IntToString(value6), preferences->GetValue(key1));

  preferences->RemoveValue(key1);
  OLA_ASSERT_EQ(string(""), preferences->GetValue(key1));
  OLA_ASSERT_FALSE(preferences->HasKey(key1));

  vector<string> values;
  // test get/set multiple value string
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT_EQ((size_t) 0, values.size());
  preferences->SetMultipleValue(key2, value1);
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT(preferences->HasKey(key2));
  OLA_ASSERT_EQ((size_t) 1, values.size());
  OLA_ASSERT_EQ(value1, values.at(0));
  preferences->SetMultipleValue(key2, value2);
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT_EQ((size_t) 2, values.size());
  OLA_ASSERT_EQ(value1, values.at(0));
  OLA_ASSERT_EQ(value2, values.at(1));
  preferences->RemoveValue(key2);

  // test get/set multiple value uint
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT_EQ((size_t) 0, values.size());
  preferences->SetMultipleValue(key2, value3);
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT(preferences->HasKey(key2));
  OLA_ASSERT_EQ((size_t) 1, values.size());
  OLA_ASSERT_EQ(IntToString(value3), values.at(0));
  preferences->SetMultipleValue(key2, value4);
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT_EQ((size_t) 2, values.size());
  OLA_ASSERT_EQ(IntToString(value3), values.at(0));
  OLA_ASSERT_EQ(IntToString(value4), values.at(1));
  preferences->RemoveValue(key2);

  // test get/set multiple value int
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT_EQ((size_t) 0, values.size());
  preferences->SetMultipleValue(key2, value5);
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT(preferences->HasKey(key2));
  OLA_ASSERT_EQ((size_t) 1, values.size());
  OLA_ASSERT_EQ(IntToString(value5), values.at(0));
  preferences->SetMultipleValue(key2, value6);
  values = preferences->GetMultipleValue(key2);
  OLA_ASSERT_EQ((size_t) 2, values.size());
  OLA_ASSERT_EQ(IntToString(value5), values.at(0));
  OLA_ASSERT_EQ(IntToString(value6), values.at(1));
  preferences->RemoveValue(key2);

  // test SetDefaultValue String
  OLA_ASSERT(preferences->SetDefaultValue(key1, StringValidator(), value1));
  OLA_ASSERT_EQ(value1, preferences->GetValue(key1));
  OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, StringValidator(),
                                                value2));
  OLA_ASSERT_EQ(value1, preferences->GetValue(key1));
  OLA_ASSERT(preferences->HasKey(key1));
  preferences->RemoveValue(key1);

  // test SetDefaultValue uint
  UIntValidator uint_validator(0, 3);
  OLA_ASSERT(preferences->SetDefaultValue(key1, uint_validator, value3));
  OLA_ASSERT_EQ(IntToString(value3), preferences->GetValue(key1));
  OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, uint_validator,
                                                value4));
  OLA_ASSERT_EQ(IntToString(value3), preferences->GetValue(key1));
  OLA_ASSERT(preferences->HasKey(key1));
  preferences->RemoveValue(key1);

  // test SetDefaultValue int
  IntValidator int_validator(0, 5);
  OLA_ASSERT(preferences->SetDefaultValue(key1, int_validator, value5));
  OLA_ASSERT_EQ(IntToString(value5), preferences->GetValue(key1));
  OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, int_validator,
                                                value6));
  OLA_ASSERT_EQ(IntToString(value5), preferences->GetValue(key1));
  OLA_ASSERT(preferences->HasKey(key1));
  preferences->RemoveValue(key1);
}