Esempio n. 1
0
static rc_ReturnCode_t test_dt_MultipleGet()
{
  rc_ReturnCode_t res;
  swi_dset_Iterator_t *set;
  const char * pathPtr[] = {
    "config.toto",
    "config",
    "config.tata",
    NULL
  };

  res = swi_dt_Init();

  if (res != RC_OK)
    return res;

  res = swi_dt_MultipleGet(3, pathPtr, &set);
  if (res != RC_OK)
    return res;

  swi_dset_Next(set);
  if (swi_dset_GetType(set) != SWI_DSET_STRING)
    return 1;
  if (strcmp(swi_dset_ToString(set), "toto") != 0)
    return 2;

  swi_dset_Next(set);
  if (swi_dset_GetType(set) != SWI_DSET_STRING)
    return 4;
  if (strcmp(swi_dset_ToString(set), "tata") != 0)
    return 5;

  if (swi_dset_Next(set) != RC_NOT_FOUND)
    return 6;
  swi_dset_Destroy(set);

  res = swi_dt_MultipleGet(0, pathPtr, &set);
  if (res != RC_NOT_FOUND)
    return 7;

  res = swi_dt_MultipleGet(3, NULL, &set);
  if (res != RC_NOT_FOUND)
    return 8;

  res = swi_dt_MultipleGet(0, NULL, &set);
  if (res != RC_NOT_FOUND)
    return 9;

  return 0;
}
Esempio n. 2
0
static void getLeafCheckTypeValue(const char* getpath, swi_dset_Type_t gettype, union t_value tval)
{
  swi_dset_Iterator_t *set = NULL;
  bool isLeaf = true;
  swi_dset_Type_t t;
  SWI_LOG("DT_TEST", DEBUG, "get on %s\n", getpath);
  rc_ReturnCode_t res = swi_dt_Get(getpath, &set, &isLeaf);
  ASSERT_TESTCASE_IS_OK(res);
  if (isLeaf == false)
    ABORT("Leaf was expected here");

  res = swi_dset_Next(set);
  ASSERT_TESTCASE_IS_OK(res);
  t = swi_dset_GetType(set);
  if(gettype != t)
    ABORT("getLeafCheckTypeValue: unexpected type [%d] for path [%s], expected [%d]", t, getpath, gettype);
  int64_t ival = 0;
  double dval = 0;
  bool bval = false;
  const char* sval;
  switch(t){
    case SWI_DSET_STRING:
      sval = swi_dset_ToString(set);
      if(strcmp(sval, tval.sval) != 0)
        ABORT("getLeafCheckTypeValue: unexpected value [%s] for path [%s], expected [%s]", sval, getpath, tval.sval );
      break;
    case SWI_DSET_INTEGER:
      ival = swi_dset_ToInteger(set);
      if(ival != tval.ival)
        ABORT("getLeafCheckTypeValue: unexpected value [%d] for path [%s], expected [%d]", ival, getpath, tval.ival );
      break;
    case SWI_DSET_FLOAT:
      dval = swi_dset_ToFloat(set);
      if(dval != tval.dval )
        ABORT("getLeafCheckTypeValue: unexpected value [%f] for path [%s], expected [%f]", dval, getpath, tval.dval );
      break;
    case SWI_DSET_BOOL:
      bval = swi_dset_ToBool(set);
      if(bval != tval.bval)
        ABORT("getLeafCheckTypeValue: unexpected value [%d] for path [%s], expected [%d]", bval, getpath, tval.bval );
      break;
    case SWI_DSET_NIL:
      if(tval.sval != NULL)//not sure how to have a variable of NIL type as a result of a Get request.
        ABORT("getLeafCheckTypeValue: received type SWI_DSET_NIL, with expected value was not NULL");
      break;
    default:
      ABORT("Unexpected swi_dset_Type_t [%d] for path [%s]", t, getpath);
  }

  swi_dset_Destroy(set);
}
Esempio n. 3
0
static void dwcb_DataCommand(swi_av_Asset_t *asset, ///< [IN] the asset receiving the data
    const char *pathPtr, ///< [IN] the path targeted by the data sent by the server.
    swi_dset_Iterator_t* data, ///< [IN] the data iterator containing the received data.
                               ///<      The data contained in the iterator will be automatically released when the callback returns.
    int ack_id,                              ///< [IN] the id to be used to acknowledge the received data.
                                             ///<      If ack_id=0 then there is no need to acknowledge.
    void *userDataPtr)
{
  SWI_LOG("AV_TEST", DEBUG, "dwcb_DataCommand: pathPtr=%s, ack_id=%d\n", pathPtr, ack_id);
  //init result
  result = 0;

  if (strcmp(pathPtr, "commands.avTestCommand"))
  {
    result = 122;
    waiting_notification = 0;
    return;
  }

  if (data == NULL )
  {
    result = 124;
    waiting_notification = 0;
    return;
  }


  rc_ReturnCode_t res = RC_OK;
  int value1 = -1, value2 = -1, pname1 = -1, pname2 = -1; //init at -1 meaning: not received

  res = swi_dset_Next(data);


  while (res == RC_OK && result == 0)
  {
    swi_dset_Type_t type = swi_dset_GetType(data);

    switch (type)
    {
      case SWI_DSET_INTEGER:
        if (strcmp(swi_dset_GetName(data), "param1"))
          result = 125;
        else
          pname1 = 0;
        if (swi_dset_ToInteger(data) != 42)
          result = 126;
        else
          value1 =  0;
        break;
      case SWI_DSET_STRING:
        if (strcmp(swi_dset_GetName(data), "param2"))
          result = 127;
        else
          pname2 = 0;
        if (strcmp(swi_dset_ToString(data), "bar"))
          result = 128;
        else
          value2 = 0;
        break;
      default:
        result = 129; //unexpected data!
        break;
    }
    res = swi_dset_Next(data);
  }

  //check all param were received
  if ( result == 0 && (value1 == -1 || value2 == -1 || pname1 == -1 || pname2 == -1)){
    result = 130;
    SWI_LOG("AV_TEST", ERROR, "at least one value was missing (i.e. -1): value1 = %d, value2 = %d, pname1 = %d, pname2 = %d\n", value1, value2, pname1, pname2);
  }

  if (ack_id)
    swi_av_Acknowledge(ack_id, result, "some error msg", "now", 0);

  swi_dset_Destroy(data);
  waiting_notification = 0;
  return;
}
Esempio n. 4
0
static void dwcb_DataWrittingList(swi_av_Asset_t *asset, ///< [IN] the asset receiving the data
    const char *pathPtr, ///< [IN] the path targeted by the data sent by the server.
    swi_dset_Iterator_t* data, ///< [IN] the data iterator containing the received data.
                               ///<      The data contained in the iterator will be automatically released when the callback returns.
    int ack_id,                              ///< [IN] the id to be used to acknowledge the received data.
                                             ///<      If ack_id=0 then there is no need to acknowledge.
    void *userDataPtr)
{
  SWI_LOG("AV_TEST", DEBUG, "dwcb_DataWrittingList: pathPtr=%s, ack_id=%d\n", pathPtr, ack_id);

  if (strcmp(pathPtr, "sub.path"))
  {
    result = 112;
    waiting_notification = 0;
    return;
  }

  if (data == NULL )
  {
    result = 114;
    waiting_notification = 0;
    return;
  }

  rc_ReturnCode_t res = RC_OK;
  bool valueOK = true;
  res = swi_dset_Next(data);
  while (res == RC_OK && valueOK)
  {
    swi_dset_Type_t type = swi_dset_GetType(data);

    switch (type)
    {
      case SWI_DSET_INTEGER:
        if (swi_dset_ToInteger(data) != 42)
          valueOK = false;
        break;

      case SWI_DSET_STRING:
        if (strcmp(swi_dset_ToString(data), "bar"))
          valueOK = false;
        break;

      default:
        break;
    }
    res = swi_dset_Next(data);
  }

  if (!valueOK)
  {
    result = 125;
    waiting_notification = 0;
    return;
  }

  if (ack_id)
    swi_av_Acknowledge(ack_id, 42, "some error msg", "now", 0);

  swi_dset_Destroy(data);
  result = 0;
  waiting_notification = 0;
  return;
}
Esempio n. 5
0
static rc_ReturnCode_t test_dt_Get()
{
  rc_ReturnCode_t res;
  swi_dset_Iterator_t *set = NULL;
  bool isLeaf = true;

  res = swi_dt_Init();

  if (res != RC_OK)
    return res;

  res = swi_dt_Get("config.toto", &set, NULL);
  if (res != RC_OK)
    return res;

  swi_dset_Next(set);
  if (swi_dset_GetType(set) != SWI_DSET_STRING)
    return 1;
  if (strcmp(swi_dset_ToString(set), "toto") != 0)
    return 2;
  swi_dset_Destroy(set);

  res = swi_dt_Get("config.tata", &set, NULL);
  if (res != RC_OK)
    return 3;

  swi_dset_Next(set);
  if (swi_dset_GetType(set) != SWI_DSET_STRING)
    return 4;
  if (strcmp(swi_dset_ToString(set), "tata") != 0)
    return 5;
  swi_dset_Destroy(set);

  res = swi_dt_Get("config", &set, &isLeaf);
  swi_dset_Destroy(set);
  if (res != RC_OK || isLeaf == true)
    return 6;

  res = swi_dt_Get("config.agent.deviceId", &set, &isLeaf);
  if(res != RC_OK || isLeaf == false)
    return 10;

  res = swi_dset_Next(set);
  swi_dset_Type_t t = swi_dset_GetType(set);
  swi_dset_Destroy(set);
  if (res != RC_OK || t != SWI_DSET_STRING)
    return 11;

  res = swi_dt_Get("unexisting_node", &set, NULL);
  if (res != RC_NOT_FOUND)
    return 7;
  swi_dset_Destroy(set);

  res = swi_dt_Get(NULL, &set, NULL);
  if (res != RC_NOT_FOUND)
    return 8;
  res = swi_dt_Get(NULL, NULL, NULL);
  if (res != RC_BAD_PARAMETER)
    return 9;
  return 0;
}