Beispiel #1
0
static rc_ReturnCode_t notificationCb(swi_dset_Iterator_t *data)
{
  swi_dset_Iterator_t *set = NULL;
  rc_ReturnCode_t res;

  waitingForNotification = 0;
  res = swi_dt_Get("config.server.serverId", &set, NULL);
  ASSERT_TESTCASE_IS_OK(res);
  return RC_OK;
}
Beispiel #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);
}
Beispiel #3
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;
}