Esempio n. 1
0
static int test_2_TriggerPolicy()
{
    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

//trigger default policy
    res = swi_av_TriggerPolicy(NULL );
    if (res != SWI_STATUS_OK)
        return res;

//trigger one existing policy
    res = swi_av_TriggerPolicy("now");
    if (res != SWI_STATUS_OK)
        return res;

//trigger "never" policy: this must fail
    res = swi_av_TriggerPolicy("never");
    if (res == SWI_STATUS_OK)
        return res;

//test using unknown policy
    res = swi_av_TriggerPolicy("plop");
    if (res == SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;
    return 0;
}
Esempio n. 2
0
static int test_3_ConnectToServer()
{
    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

//test using requesting SYNC connexion
    res = swi_av_ConnectToServer(SWI_AV_CX_SYNC);
    if (res != SWI_STATUS_OK)
        return res;

    SWI_LOG("AV_TEST", DEBUG, "sync done\n");

//test using 0 latency: async but "immediate" connection
    res = swi_av_ConnectToServer(0);
    if (res != SWI_STATUS_OK)
        return res;

//test using correct latency
    res = swi_av_ConnectToServer(10);
    if (res != SWI_STATUS_OK)
        return res;

//test using too big latency:
//expected behavior here: rejected
    res = swi_av_ConnectToServer((unsigned int) INT_MAX + 1);
    if (res != SWI_STATUS_WRONG_PARAMS)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    return 0;
}
Esempio n. 3
0
int sampleMain()
{
    swi_av_Asset_t *asset = NULL;
    swi_av_Table_t *table = NULL;
    rc_ReturnCode_t res;

    const char *columns[] = {
          "col1",
          "col2",
          "timestamp"
        };

    res = swi_av_Init();
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to initialize airvantage module\n");
        return 1;
    }

    LE_INFO("Initializing asset\n");
    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to create asset\n");
        return 1;
    }

    LE_INFO("Registering asset\n");
    res = swi_av_asset_Start(asset);
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to register asset module\n");
        return 1;
    }

    res = swi_av_asset_PushString(asset, "event.status", "now", SWI_AV_TSTAMP_AUTO, "booting");
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to push data\n");
        return 1;
    }

    res = swi_av_table_Create(asset, &table, "col.data", 3, columns, POLICY, STORAGE_RAM, 0);
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to create table bedroom.data\n");
        return 1;
    }

    AddBedroomData(asset, table, 10);
    sleep(2);

    swi_av_asset_Destroy(asset);

    swi_av_Destroy();
    return 0;
}
Esempio n. 4
0
static int test_1_Init_Destroy()
{
    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    return 0;
}
Esempio n. 5
0
static int test_1_Init_Destroy()
{
  rc_ReturnCode_t res = swi_av_Init();
  if (res != RC_OK)
    return res;

  res = swi_av_Init();
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  return 0;
}
Esempio n. 6
0
static int test_10_asset_receiveDataWriting()
{
    swi_status_t res = SWI_STATUS_OK;
    waiting_notification = 1;

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    swi_av_Asset_t* asset;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_RegisterDataWrite(asset, dwcb_DataWritting, NULL );
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

    /*command sends to TOTO asset*/
    const char* str = "'SendData', { Path = 'TOTO.sub.path', Body = { foo = 'bar' }, TicketId = %u, Type = 5, __class = 'AWT-DA::Message' })\n";
    char* cmd_SendDataWriting = addTicketId(str);

    exec_lua_code(cmd_SendDataWriting);
    SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SendDataWriting done\n");
    while (waiting_notification)
        ;

    res = swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    free(cmd_SendDataWriting);
    return result;
}
Esempio n. 7
0
static int test_12_asset_receiveDataCommandList()
{
  rc_ReturnCode_t res = RC_OK;
  waiting_notification = 1;

  res = swi_av_Init();
  if (res != RC_OK)
    return res;

  swi_av_Asset_t* asset;

  res = swi_av_asset_Create(&asset, ASSET_ID);
  if (res != RC_OK)
    return res;

  res = swi_av_RegisterDataWrite(asset, dwcb_DataCommandList, NULL );
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Start(asset);
  if (res != RC_OK)
    return res;

  const char* str = "'SendData', { Path = 'av_test_asset_id.sub.path', Body = { Command = 'plop',  Args = {42, 'bar'}, __class = 'AWT-DA::Command' },  TicketId = %u, Type = 2,  __class = 'AWT-DA::Message' })\n";
  char* cmd_SendDataCommandList = addTicketId(str);

  exec_lua_code(cmd_SendDataCommandList);
  SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SendDataCommandList done\n");
  while (waiting_notification)
    ;

  res = swi_av_asset_Destroy(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  free(cmd_SendDataCommandList);
  return result;
}
Esempio n. 8
0
static int test_4_asset_Create_Start_Destroy()
{
  rc_ReturnCode_t res = swi_av_Init();
  if (res != RC_OK)
    return res;

  swi_av_Asset_t* asset;
  /*
   res = swi_av_asset_Create(&asset, NULL);
   if (res != RC_BAD_PARAMETER)
   return 1;

   res = swi_av_asset_Create(NULL, "test_asset");
   if (res != RC_BAD_PARAMETER)
   return 1;
   */
  res = swi_av_asset_Create(&asset, ASSET_ID);
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Start(NULL );
  if (res != RC_BAD_PARAMETER)
    return res;

  res = swi_av_asset_Start(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Destroy(NULL);
  if (res != RC_BAD_PARAMETER)
    return res;

  res = swi_av_asset_Destroy(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  return RC_OK;
}
Esempio n. 9
0
static int test_4_asset_Create_Start_Destroy()
{
    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    swi_av_Asset_t* asset;
    /*
     res = swi_av_asset_Create(&asset, NULL);
     if (res != SWI_STATUS_WRONG_PARAMS)
     return 1;

     res = swi_av_asset_Create(NULL, "test_asset");
     if (res != SWI_STATUS_WRONG_PARAMS)
     return 1;
     */
    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;
    res = swi_av_asset_Start(NULL );
    if (res != SWI_STATUS_CONTEXT_IS_CORRUPTED)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Destroy(NULL );
    if (res != SWI_STATUS_CONTEXT_IS_CORRUPTED)
        return res;

    res = swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    return 0;
}