/* Copying tests */ #include "test.h" struct junk { int junk1; char *junk2; }; static struct junk * junk_create(int arg1, char *arg2) { struct junk *j = V_ALLOC(struct junk, 1); j->junk1 = arg1; j->junk2 = v_strdup(arg2); return j; } static struct junk * junk_copy(struct junk *j) { return junk_create(j->junk1, j->junk2); } static void junk_print(struct junk *j, FILE *fp) { fprintf(fp, "%d %s\n", j->junk1, j->junk2); } int main(void) { vhash *h, *hcopy; struct junk *j; vmatrix *m; vscalar *s; char *file; vlist *l; TEST_START("copy"); #if 0 h = vh_hash("FOO", V_STRING, "BAR", NULL); l = vl_list(V_TYPE_POINTER, h, V_TYPE_POINTER, h, V_TYPE_POINTER, h, V_TYPE_NULL); v_print(l, stdout); l = v_copy(l); v_print(l, stdout); #endif m = vm_create(); vm_store(m, 0, 0, 1.0); vm_store(m, 1, 1, 1.0); vm_store(m, 2, 2, 1.0); s = vs_dcreate(3.14159); l = vl_list(V_TYPE_STRING, "brian", V_TYPE_INT, -45, V_TYPE_FLOAT, 90.34, V_TYPE_DOUBLE, 1e22, V_TYPE_NULL); h = vh_hash("LIST", V_TYPE_POINTER, l, "LIST REF", V_TYPE_POINTER, l, "STRING", V_TYPE_STRING, "fred", "INT", V_TYPE_INT, 42, "REAL", V_TYPE_DOUBLE, 11.7, "MATRIX", V_TYPE_POINTER, m, "SCALAR", V_TYPE_POINTER, s, NULL); TEST_NOFAIL("copying", (hcopy = v_copy(h)) != NULL); TEST("copy value 1", vh_iget(h, "INT") == vh_iget(hcopy, "INT")); TEST("copy value 2", vh_iget(h, "REAL") == vh_iget(hcopy, "REAL")); TEST("copy value 3", v_type(vh_pget(hcopy, "LIST")) == vlist_type); TEST("copy value 4", v_type(vh_pget(hcopy, "SCALAR")) == vscalar_type); j = junk_create(23, "skidoo"); v_copy_with(j, (void *(*)()) junk_copy); v_print_with(j, (void (*)()) junk_print); vh_pstore(h, "JUNK", j); TEST_NOFAIL("copying with", (hcopy = v_copy(h)) != NULL && vh_exists(hcopy, "JUNK")); TEST_FINISH; }