コード例 #1
0
ファイル: testnetfuncs.c プロジェクト: ifzz/lwes
static void test_ttl_functions (void)
{
  struct lwes_net_connection connection;
  assert (lwes_net_open (&connection,
                         (char*)mcast_ip,
                         (char*)mcast_iface,
                         (int)mcast_port) == 0);

  /* test success of get */
  assert (lwes_net_get_ttl (&connection) == 1);

  /* now test failure of getsockopt in get */
  getsockopt_error_when = IP_MULTICAST_TTL;
  assert (lwes_net_get_ttl (&connection) < 0);
  getsockopt_error_when = GETSOCKOPT_NO_ERROR;

  /* test success of set */
  assert (lwes_net_set_ttl (&connection, 3) == 0);
  /* check success of set */
  assert (lwes_net_get_ttl (&connection) == 3);

  /* now test failure of setsockopt in set */
  setsockopt_error_when = IP_MULTICAST_TTL;
  assert (lwes_net_set_ttl (&connection,5) < 0);
  setsockopt_error_when = GETSOCKOPT_NO_ERROR;
  assert (lwes_net_get_ttl (&connection) == 3);
}
コード例 #2
0
ファイル: testnetfuncs.c プロジェクト: ifzz/lwes
static void test_null_args (void)
{
  LWES_BYTE buffer[500];
  unsigned int i;
  struct lwes_net_connection connection;

  /* initialize to nothing */
  for (i = 0; i < 500; i++)
    buffer[i]=(LWES_BYTE)0;

  /* now set 45 bytes */
  for (i = 0; i < 45; i++)
    {
      buffer[i]=(LWES_BYTE)i;
    }


  /* test NULL connection to all calls */

  assert (lwes_net_open (NULL, 
                         (char*)mcast_ip,
                         (char*)mcast_iface,
                         (int)mcast_port) == -1);
  assert (lwes_net_close (NULL) == -1);

  assert (lwes_net_get_ttl (NULL) == -1);

  assert (lwes_net_set_ttl (NULL, 5) == -1);

  assert (lwes_net_get_sock_fd (NULL) == -1);

  assert (lwes_net_send_bytes (NULL, buffer, 45) == -1);
  assert (lwes_net_send_bytes (&connection, NULL, 45) == -1);

  assert (lwes_net_sendto_bytes (NULL,
                                 (char*)mcast_ip,
                                 (char*)mcast_iface,
                                 (int)mcast_port,
                                 buffer,
                                 45) == -1);

  assert (lwes_net_sendto_bytes (&connection,
                                 (char*)mcast_ip,
                                 (char*)mcast_iface,
                                 (int)mcast_port,
                                 NULL,
                                 45) == -1);

  assert (lwes_net_recv_bind (NULL) == -1);

  assert (lwes_net_recv_bytes (NULL, buffer, 500) == -1);
  assert (lwes_net_recv_bytes (&connection, NULL, 500) == -1);

  assert (lwes_net_recv_bytes_by (NULL, buffer, 500, 10000) == -1);
  assert (lwes_net_recv_bytes_by (&connection, NULL, 500, 10000) == -1);
}
コード例 #3
0
static void emitter    (const char *ip, const int port, const char *iface)
{
  struct lwes_emitter *emitter;
  struct lwes_event *event;
  struct lwes_event_type_db *db = NULL;

/*  db = lwes_event_type_db_create ( (char*)esffile );
 * assert ( db != NULL );
 */

  /* test null safety */
  assert ( lwes_emitter_emit(NULL, NULL) == -1 );

  /* emit without heartbeat */
  emitter = lwes_emitter_create (ip, iface, port, 0, 60);
  assert ( emitter != NULL );
  assert (lwes_net_get_ttl (&(emitter->connection)) == 3);
  event  = lwes_event_create (db, eventname);
  assert ( event != NULL );

  assert ( lwes_event_set_STRING   (event, key01, value01) == 1 );
  assert ( lwes_event_set_BOOLEAN  (event, key02, value02) == 2 );
  assert ( lwes_event_set_IP_ADDR  (event, key03, value03) == 3 );
  assert ( lwes_event_set_U_INT_16 (event, key04, value04) == 4 );
  assert ( lwes_event_set_INT_16   (event, key05, value05) == 5 );
  assert ( lwes_event_set_U_INT_32 (event, key06, value06) == 6 );
  assert ( lwes_event_set_INT_32   (event, key07, value07) == 7 );
  assert ( lwes_event_set_U_INT_64 (event, key08, value08) == 8 );
  assert ( lwes_event_set_INT_64   (event, key09, value09) == 9 );

  assert ( lwes_emitter_emit(emitter,event) == 0 );

  lwes_event_destroy(event);
  lwes_emitter_destroy(emitter);
/*  lwes_event_type_db_destroy(db); */

  /* emit with heartbeat */
  emitter = lwes_emitter_create (ip, iface, port, 1, 2);
  assert ( emitter != NULL );
  event  = lwes_event_create (db, eventname);
  assert ( event != NULL );

  assert ( lwes_event_set_STRING   (event, key01, value01) == 1 );
  assert ( lwes_event_set_BOOLEAN  (event, key02, value02) == 2 );
  assert ( lwes_event_set_IP_ADDR  (event, key03, value03) == 3 );
  assert ( lwes_event_set_U_INT_16 (event, key04, value04) == 4 );
  assert ( lwes_event_set_INT_16   (event, key05, value05) == 5 );
  assert ( lwes_event_set_U_INT_32 (event, key06, value06) == 6 );
  assert ( lwes_event_set_INT_32   (event, key07, value07) == 7 );
  assert ( lwes_event_set_U_INT_64 (event, key08, value08) == 8 );
  assert ( lwes_event_set_INT_64   (event, key09, value09) == 9 );

  /* emit one */
  assert ( lwes_emitter_emit(emitter,event) == 0 );

  /* then pretend it's the future so we get a heartbeat */
  time_future = 10;
  assert ( lwes_emitter_emit(emitter,event) == 0 );
  time_future = 0;

  lwes_event_destroy(event);

  /* pretend its really really far in the future to see that freq is
     capped */
  time_future = 100000;
  lwes_emitter_destroy(emitter);
  time_future = 0;
}
コード例 #4
0
static void emitter_to  (const char *ip,
                         const int port,
                         const char *iface,
                         const char *n_ip,
                         const int n_port,
                         const char *n_iface)
{
  struct lwes_emitter *emitter;
  struct lwes_event *event;
  struct lwes_event_type_db *db = NULL;

/* db = lwes_event_type_db_create ( (char*)esffile );
 * assert ( db != NULL );
 */

  /* emit without heartbeat */
  emitter = lwes_emitter_create (ip, iface, port, 0, 60);
  assert (emitter != NULL);
  assert (lwes_net_get_ttl (&(emitter->connection)) == 3);
  event  = lwes_event_create (db, eventname);
  assert (event != NULL);

  assert (lwes_event_set_STRING   (event, key01, value01) == 1);
  assert (lwes_event_set_BOOLEAN  (event, key02, value02) == 2 );
  assert (lwes_event_set_IP_ADDR  (event, key03, value03) == 3);
  assert (lwes_event_set_U_INT_16 (event, key04, value04) == 4);
  assert (lwes_event_set_INT_16   (event, key05, value05) == 5);
  assert (lwes_event_set_U_INT_32 (event, key06, value06) == 6);
  assert (lwes_event_set_INT_32   (event, key07, value07) == 7);
  assert (lwes_event_set_U_INT_64 (event, key08, value08) == 8);
  assert (lwes_event_set_INT_64   (event, key09, value09) == 9);

  assert (lwes_emitter_emitto ((char *) n_ip,
                               (char *) n_iface,
                               (int)    n_port,
                               emitter,
                               event) == 0);

  lwes_event_destroy(event);
  lwes_emitter_destroy(emitter);
/*  lwes_event_type_db_destroy(db); */

  /* emit with heartbeat */
  emitter = lwes_emitter_create (ip, iface, port, 1, 2);
  assert (emitter != NULL);
  event  = lwes_event_create (db, eventname);
  assert (event != NULL);

  assert (lwes_event_set_STRING   (event, key01, value01) == 1);
  assert (lwes_event_set_BOOLEAN  (event, key02, value02) == 2);
  assert (lwes_event_set_IP_ADDR  (event, key03, value03) == 3);
  assert (lwes_event_set_U_INT_16 (event, key04, value04) == 4);
  assert (lwes_event_set_INT_16   (event, key05, value05) == 5);
  assert (lwes_event_set_U_INT_32 (event, key06, value06) == 6);
  assert (lwes_event_set_INT_32   (event, key07, value07) == 7);
  assert (lwes_event_set_U_INT_64 (event, key08, value08) == 8);
  assert (lwes_event_set_INT_64   (event, key09, value09) == 9);

  assert (lwes_emitter_emitto ((char *) n_ip,
                               (char *) n_iface,
                               (int)    n_port,
                               emitter,
                               event) == 0);

  /* pretend its the future */
  time_future = 10;

  assert (lwes_emitter_emitto ((char *) n_ip,
                               (char *) n_iface,
                               (int)    n_port,
                               emitter,
                               event) == 0);

  lwes_event_destroy (event);

  /* pretend its the past to test the other edge case for freqency */
  time_past = 2000;
  lwes_emitter_destroy (emitter);
  time_past = 0;
}