Ejemplo n.º 1
0
static void event1 (struct lwes_emitter *emitter)
{
  struct lwes_event *event;
  int ret = 0;

  LWES_SHORT_STRING eventname = (LWES_SHORT_STRING)"TypeChecker";
  LWES_SHORT_STRING key01     = (LWES_SHORT_STRING)"aString";
  LWES_LONG_STRING  value01   = (LWES_LONG_STRING)"http://www.test.com";
  LWES_SHORT_STRING key02     = (LWES_SHORT_STRING)"aBoolean";
  LWES_BOOLEAN      value02   = (LWES_BOOLEAN)1;
  LWES_SHORT_STRING key03     = (LWES_SHORT_STRING)"anIPAddress";
  LWES_IP_ADDR      value03;
  LWES_SHORT_STRING key04     = (LWES_SHORT_STRING)"aUInt16";
  LWES_U_INT_16     value04   = (LWES_U_INT_16)65535;
  LWES_SHORT_STRING key05     = (LWES_SHORT_STRING)"anInt16";
  LWES_INT_16       value05   = (LWES_INT_16)-1;
  LWES_SHORT_STRING key06     = (LWES_SHORT_STRING)"aUInt32";
  LWES_U_INT_32     value06   = (LWES_U_INT_32)0xffffffffL;
  LWES_SHORT_STRING key07     = (LWES_SHORT_STRING)"anInt32";
  LWES_INT_32       value07   = (LWES_INT_32)-1;
  LWES_SHORT_STRING key08     = (LWES_SHORT_STRING)"aUInt64";
  LWES_U_INT_64     value08   = (LWES_U_INT_64)0xffffffffffffffffULL;
  LWES_SHORT_STRING key09     = (LWES_SHORT_STRING)"anInt64";
  LWES_INT_64       value09   = (LWES_INT_64)-1;

  /* set this one here since we need to call a function */
  value03.s_addr = inet_addr("224.0.0.100");
  /* create event */
  event  = lwes_event_create (NULL, eventname);
  MY_ASSERT (event != NULL);

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

  /* now emit event */
  ret = lwes_emitter_emit (emitter, event);
  MY_ASSERT (ret == 0);

  /* now clean up */
  lwes_event_destroy (event);
}
Ejemplo n.º 2
0
static char *
test_event1 (void)
{
  struct lwes_event *event1;
  struct lwes_event_type_db *db = NULL;
  LWES_BYTE bytes[MAX_MSG_SIZE];
  int size1;
  LWES_LONG_STRING string1;
  LWES_LONG_STRING string2;
  LWES_IP_ADDR      ip_addr;
  char bigbuf[200];
  char *retbuf;
  char bigdirbuf[4048];
  char file[4100];

  assert (getcwd (bigdirbuf, 4048) != NULL);
  snprintf (file, 4100, "%s/test1.esf", bigdirbuf);

  ip_addr.s_addr = inet_addr ("127.0.0.1");

  db = lwes_event_type_db_create (file);
  assert (db != NULL);

  event1 = lwes_event_create_with_encoding (db, "Event1", encoding);
  assert ( event1 != NULL );

  /* use the max string size */
  string1 = random_ascii (10);
  string2 = random_ascii (50);
  assert (lwes_event_set_STRING   (event1, "st",       string1) == 2);
  assert (lwes_event_set_BOOLEAN  (event1, "t_bool",   1)       == 3);
  assert (lwes_event_set_INT_16   (event1, "t_int16",  1)       == 4);
  assert (lwes_event_set_U_INT_16 (event1, "t_uint16", 1)       == 5);
  assert (lwes_event_set_INT_32   (event1, "t_int32",  1)       == 6);
  assert (lwes_event_set_U_INT_32 (event1, "t_uint32", 1)       == 7);
  assert (lwes_event_set_INT_64   (event1, "t_int64",  1)       == 8);
  assert (lwes_event_set_U_INT_64 (event1, "t_uint64", 1)       == 9);
  assert (lwes_event_set_IP_ADDR  (event1, "t_ip_addr",ip_addr) == 10);
  assert (lwes_event_set_STRING   (event1, "t_string", string2) == 11);

  size1 = lwes_event_to_bytes (event1, bytes, MAX_MSG_SIZE, 0);

  sprintf (bigbuf, "Event1\t%d\n",size1);

  lwes_event_destroy (event1);
  lwes_event_type_db_destroy (db);
  free (string1);
  free (string2);

  retbuf = (char *) malloc (sizeof (char) * strlen (bigbuf) + 1);
  strcpy (retbuf, bigbuf);

  return retbuf;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}