Beispiel #1
0
void GeneratorTest()
{
    char* string;
    JsonObject* root = CreateJsonObject();
    JsonObject* element = CreateJsonObject();
    JsonArray* array = CreateJsonArray();
    AddInteger(array, 0);
    AddReal(array, 0.0);
    AddBoolean(array, FALSE);
    AddObject(array, element);
    AddString(array, "element");
    AddNull(array);
    PutNull(root, "0");
    PutInteger(root, "Year", 1970);
    PutInteger(root, "Month", 3);
    PutInteger(root, "Date", 18);
    PutArray(root, "Array", array);
    PutBoolean(root, "Proposition", TRUE);
    PutString(root, "Text", "Hello World");
    PutReal(root, "Pi", 3.14159265358979323846264338327950288419716939937510582097494459230781640);
    string = ToString(root);
    printf("%s", string);
    printf("\r\n");
    EXPECT_EQUAL_STRING("{\"0\":null,\"Year\":1970,\"Month\":3,\"Date\":18,\"Array\":[0,0.000000,false,{},\"element\",null],\"Proposition\":true,\"Text\":\"Hello World\",\"Pi\":3.141593}", string);
    free(string);
    ClearJsonObject(root);
    ClearJsonArray(array);
    string = ToString(root);
    EXPECT_EQUAL_STRING("{}", string);
    free(string);
}
Beispiel #2
0
static void PutData(hid_t obj, char dtype, int htype, int size, int n_dims, hsize_t *dims,int is_attr, struct descriptor_xd *xd)
{
  /*********************************************
  Read data from HDF5 file using H5Aread for
  attributes and H5Dread for datasets. Load the
  data into MDSplus nodes.
  *********************************************/
  if (dtype)
  {
    char *mem;
/*     if (dtype == DTYPE_T) { */
/*       hid_t type = H5Aget_type(obj); */
/*       int slen = H5Tget_size (type); */
/*       if (slen <0) { */
/* 	printf("Badly formed string attribute\n"); */
/*       } else { */
/* 	mem = (char *) malloc((slen+1)*sizeof(char)); */
/* 	hid_t st_id = H5Tcopy (H5T_C_S1); */
/*         size=slen; */
/* 	H5Tset_size (st_id, slen); */
/* 	if (H5Aread(obj, st_id, (void *)mem)) { */
/* 	  printf("error reading string\n"); */
/*           free(mem); */
/*           return; */
/* 	} */
/*       } */
/*     } else { */
      int  array_size = 1;
      int i;
      for (i=0;i<n_dims;i++) array_size *= dims[i];
      mem = malloc(size*array_size);
      if (is_attr)
	H5Aread ( obj, htype, (void *)mem);
      else
	/* printf("H5Dread: obj = %p, htype = %d, status = %d\n",obj,htype, */
	H5Dread ( obj, htype, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)mem) /* ) */ ;
/*     } */
    if (n_dims > 0)
      PutArray(dtype, size, n_dims, dims, mem, xd);
    else
      PutScalar(dtype, size, mem, xd);
    free(mem);
  }
}