+ double Cdfgrd0[373][3];
+ double Cdfgrd1[3][3];
+ double Cstress[106];
+ double Cddsdde[106][106];
+};
+ )
+typedef struct s_pbio pbio_t;
+
+gras_error_t test_pbio(gras_socket_t *sock, int direction) {
+ gras_error_t errcode;
+ pbio_t i,j;
+ int cpt;
+ int cpt2;
+ gras_datadesc_type_t *pbio_type;
+
+ INFO0("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----");
+ pbio_type = gras_datadesc_by_symbol(s_pbio);
+
+ /* Fill in that damn struct */
+ i.Cnstatv = 325115;
+ for (cpt=0; cpt<12; cpt++)
+ i.Cstatev[cpt] = ((double) cpt) * -2361.11;
+ i.Cnprops = -37373;
+ for (cpt=0; cpt<110; cpt++)
+ i.Cprops[cpt] = cpt * 100.0;
+ for (cpt=0; cpt<4; cpt++)
+ i.Cndi[cpt] = cpt * 23262;
+ i.Cnshr = -4634;
+ i.Cnpt = 114142;
+ i.Cdtime = -11515.662;
+ i.Ctime[0] = 332523.226;
+ i.Ctime[1] = -26216.113;
+ i.Cntens = 235211411;
+
+ for (cpt=0; cpt<3; cpt++) {
+ for (cpt2=0; cpt2<373; cpt2++)
+ i.Cdfgrd0[cpt2][cpt] = ((double)cpt) * ((double)cpt2);
+ for (cpt2=0; cpt2<3; cpt2++)
+ i.Cdfgrd1[cpt][cpt2] = -((double)cpt) * ((double)cpt2);
+ }
+ for (cpt=0; cpt<106; cpt++) {
+ i.Cstress[cpt]=(double)cpt * 22.113;
+ for (cpt2=0; cpt2<106; cpt2++)
+ i.Cddsdde[cpt][cpt2] = ((double)cpt) * ((double)cpt2);
+ }
+ TRY(write_read(gras_datadesc_by_symbol(s_pbio),
+ &i,&j, sock,direction));
+ if (direction == READ || direction == RW) {
+ /* Check that the data match */
+ gras_assert(i.Cnstatv == j.Cnstatv);
+ for (cpt=0; cpt<12; cpt++)
+ gras_assert(i.Cstatev[cpt] == j.Cstatev[cpt]);
+ gras_assert(i.Cnprops == j.Cnprops);
+ for (cpt=0; cpt<110; cpt++)
+ gras_assert(i.Cprops[cpt] == j.Cprops[cpt]);
+ for (cpt=0; cpt<4; cpt++)
+ gras_assert(i.Cndi[cpt] == j.Cndi[cpt]);
+ gras_assert(i.Cnshr == j.Cnshr);
+ gras_assert(i.Cnpt == j.Cnpt);
+ gras_assert(i.Cdtime == j.Cdtime);
+ gras_assert(i.Ctime[0] == j.Ctime[0]);
+ gras_assert(i.Ctime[1] == j.Ctime[1]);
+ gras_assert(i.Cntens == j.Cntens);
+ for (cpt=0; cpt<3; cpt++) {
+ for (cpt2=0; cpt2<373; cpt2++)
+ gras_assert(i.Cdfgrd0[cpt2][cpt] == j.Cdfgrd0[cpt2][cpt]);
+ for (cpt2=0; cpt2<3; cpt2++)
+ gras_assert(i.Cdfgrd1[cpt][cpt2] == j.Cdfgrd1[cpt][cpt2]);
+ }
+ for (cpt=0; cpt<106; cpt++) {
+ gras_assert(i.Cstress[cpt] == j.Cstress[cpt]);
+ for (cpt2=0; cpt2<106; cpt2++)
+ gras_assert4(i.Cddsdde[cpt][cpt2] == j.Cddsdde[cpt][cpt2],
+ "%f=i.Cddsdde[%d][%d] != j.Cddsdde[cpt][cpt2]=%f",
+ i.Cddsdde[cpt][cpt2],cpt,cpt2,j.Cddsdde[cpt][cpt2]);
+ }
+ }
+
+ return no_error;
+}
+
+typedef struct {
+ int num_lits; /* size of next array */
+ int* literals;
+} Clause;
+
+void Clause_pre_cb (void *vars,gras_datadesc_type_t *p_type,void *data);
+int Clause_num_lits(void *vars,gras_datadesc_type_t *p_type,void *data);
+
+void Clause_pre_cb(void *vars,
+ gras_datadesc_type_t *p_type,
+ void *data) {
+ Clause c=*(Clause*)data;
+ int *count=malloc(sizeof(int));
+ *count=c.num_lits;
+
+ gras_dd_cbps_push(vars,"num_lits",count,
+ gras_datadesc_by_name("int"));
+ DEBUG2("writen data=%p (got %p)",count,data);
+ DEBUG1("writen count=%d",*count);
+}
+
+int Clause_num_lits(void *vars,
+ gras_datadesc_type_t *p_type,
+ void *data) {
+ // int *res;
+ gras_datadesc_type_t *ddt;
+ void *d = gras_dd_cbps_get (vars,"num_lits",&ddt);
+ DEBUG1("read data=%p",d);
+ DEBUG1("read count=%d",*(int*)d);
+ return *(int*)d;
+}
+
+gras_error_t test_clause(gras_socket_t *sock, int direction) {
+ gras_error_t errcode;
+ gras_datadesc_type_t *ddt,*array_t;
+ Clause *i,*j;
+ int cpt;
+
+ INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----");
+
+ /* create and fill the struct */
+ if (! (i=malloc(sizeof(Clause))) )
+ RAISE_MALLOC;
+
+ i->num_lits = 5432;
+ if (! (i->literals = malloc(sizeof(int) * i->num_lits)) )
+ RAISE_MALLOC;
+ for (cpt=0; cpt<i->num_lits; cpt++)
+ i->literals[cpt] = cpt * cpt - ((cpt * cpt) / 2);
+ DEBUG3("created data=%p (within %p @%p)",&(i->num_lits),i,&i);
+ DEBUG1("created count=%d",i->num_lits);
+
+ /* create the damn type descriptor */
+ TRYFAIL(gras_datadesc_declare_struct("Clause",&ddt));
+ gras_datadesc_cb_set_pre(ddt,Clause_pre_cb);
+
+ TRYFAIL(gras_datadesc_declare_struct_append(ddt,"num_lits",
+ gras_datadesc_by_name("int")));
+
+ TRYFAIL(gras_datadesc_declare_array_dyn("Clause{int[]}",
+ gras_datadesc_by_name("int"),
+ Clause_num_lits,
+ &array_t));
+ TRYFAIL(gras_datadesc_declare_ref("Clause{int[]}*",array_t,&array_t));
+ TRYFAIL(gras_datadesc_declare_struct_append(ddt,"literals",array_t));
+ gras_datadesc_declare_struct_close(ddt);
+ TRYFAIL(gras_datadesc_declare_ref("Clause*",ddt,&ddt));
+
+ TRY(write_read(ddt, &i,&j, sock,direction));
+ if (direction == READ || direction == RW) {
+ gras_assert(i->num_lits == j->num_lits);
+ for (cpt=0; cpt<i->num_lits; cpt++)
+ gras_assert(i->literals[cpt] == j->literals[cpt]);
+
+ free(j->literals);
+ free(j);
+ }
+ free(i->literals);
+ free(i);
+ return no_error;
+}