Пример #1
0
void SelectServerTest::setUp() {
  connected_read_descriptor_count = m_map.GetIntegerVar(
      PollerInterface::K_CONNECTED_DESCRIPTORS_VAR);
  read_descriptor_count = m_map.GetIntegerVar(
      PollerInterface::K_READ_DESCRIPTOR_VAR);
  write_descriptor_count = m_map.GetIntegerVar(
      PollerInterface::K_WRITE_DESCRIPTOR_VAR);

  m_ss = new SelectServer(&m_map);
  m_timeout_counter = 0;
  m_loop_counter = 0;

#if _WIN32
  WSADATA wsa_data;
  int result = WSAStartup(MAKEWORD(2, 0), &wsa_data);
  OLA_ASSERT_EQ(result, 0);
#endif
}
Пример #2
0
/*
 * Check AddReadDescriptor/RemoveReadDescriptor works correctly and that the
 * export map is updated.
 */
void SelectServerTest::testAddRemoveReadDescriptor() {
  LoopbackDescriptor bad_socket;
  IntegerVariable *connected_socket_count =
    m_map->GetIntegerVar(PollerInterface::K_CONNECTED_DESCRIPTORS_VAR);
  IntegerVariable *socket_count =
    m_map->GetIntegerVar(PollerInterface::K_READ_DESCRIPTOR_VAR);
  OLA_ASSERT_EQ(1, connected_socket_count->Get());  // internal socket
  OLA_ASSERT_EQ(0, socket_count->Get());
  // adding and removin a non-connected socket should fail
  OLA_ASSERT_FALSE(m_ss->AddReadDescriptor(&bad_socket));
  OLA_ASSERT_FALSE(m_ss->RemoveReadDescriptor(&bad_socket));

  LoopbackDescriptor loopback_socket;
  loopback_socket.Init();
  OLA_ASSERT_EQ(1, connected_socket_count->Get());
  OLA_ASSERT_EQ(0, socket_count->Get());
  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback_socket));
  // Adding a second time should fail
  OLA_ASSERT_FALSE(m_ss->AddReadDescriptor(&loopback_socket));
  OLA_ASSERT_EQ(2, connected_socket_count->Get());
  OLA_ASSERT_EQ(0, socket_count->Get());

  // Add a udp socket
  UDPSocket udp_socket;
  OLA_ASSERT_TRUE(udp_socket.Init());
  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&udp_socket));
  OLA_ASSERT_FALSE(m_ss->AddReadDescriptor(&udp_socket));
  OLA_ASSERT_EQ(2, connected_socket_count->Get());
  OLA_ASSERT_EQ(1, socket_count->Get());

  // Check remove works
  OLA_ASSERT_TRUE(m_ss->RemoveReadDescriptor(&loopback_socket));
  OLA_ASSERT_EQ(1, connected_socket_count->Get());
  OLA_ASSERT_EQ(1, socket_count->Get());
  OLA_ASSERT_TRUE(m_ss->RemoveReadDescriptor(&udp_socket));
  OLA_ASSERT_EQ(1, connected_socket_count->Get());
  OLA_ASSERT_EQ(0, socket_count->Get());

  // Remove again should fail
  OLA_ASSERT_FALSE(m_ss->RemoveReadDescriptor(&loopback_socket));
}