static void check_map(t_board *board) { int is_entry; int is_exit; int is_key; is_entry = 0; is_exit = 0; is_key = 0; check_elem(board, &is_entry, &is_exit, &is_key); if (!is_entry) gere_errors(2); if (!is_exit) gere_errors(3); if (!is_key) gere_errors(7); }
int main(int argc, char **argv) { t_elem *elem; t_map *map; if (argc == 2) { if (!(elem = ft_treat_file(argv))) return (0); if (!(check_elem(elem))) return (ft_error(elem, "error\n")); if (!(map = ft_create_struct_map(ft_size_map(elem->nb_elem)))) return (0); elem = ft_treat_elem(elem); map = ft_resolv(elem, map); ft_display_map(map->map, map->size_map); ft_free_map(map); free(map); elem = ft_free_elem(elem); } else ft_printf("error\n"); return (0); }
int main(int argc, char **argv) { int i; link_head_t list[] = { /* some lists to operate on */ LINK_HEAD_INIT(0), LINK_HEAD_INIT(0), { DEADINT, DEADINT, DEADPTR, DEADPTR, 0 } /* list[2] is a bad list */ }; link_elem_t elem[] = { /* some elements to operate on */ LINK_ELEM_INIT(OBJECT0), LINK_ELEM_INIT(OBJECT1), LINK_ELEM_INIT(OBJECT2), LINK_ELEM_INIT(OBJECT3), LINK_ELEM_INIT(OBJECT4), LINK_ELEM_INIT(OBJECT5), LINK_ELEM_INIT(OBJECT6), LINK_ELEM_INIT(OBJECT7), LINK_ELEM_INIT(OBJECT8), LINK_ELEM_INIT(OBJECT9), { DEADINT, DEADPTR, DEADPTR, DEADPTR, DEADPTR, DEADINT } /* elem[10] */ }; /* First, build the lists */ for (i = 0; i < 8; i++) if (ll_add(&list[0], &elem[i], LINK_LOC_TAIL, 0)) return -1; /* failed to initialize test */ if (ll_add(&list[1], &elem[8], LINK_LOC_TAIL, 0)) return -1; /* failed to initialize test */ /* Baseline checks */ check_list(&list[0], 8, &elem[0], &elem[7], 0, "ll_remove_baseline", "Verify baseline list[0]"); check_list(&list[1], 1, &elem[8], &elem[8], 1, "ll_remove_baseline", "Verify baseline list[1]"); /* Check to see if ll_remove verifies its arguments correctly */ check_result(ll_remove(0, 0), DB_ERR_BADARGS, "ll_remove_noargs", "ll_remove() with no arguments", 0); check_result(ll_remove(&list[2], &elem[0]), DB_ERR_BADARGS, "ll_remove_badlist", "ll_remove() with bad list", 1); check_result(ll_remove(&list[0], &elem[10]), DB_ERR_BADARGS, "ll_remove_badelem", "ll_remove() with bad element", 1); /* Unused element test */ check_result(ll_remove(&list[0], &elem[9]), DB_ERR_UNUSED, "ll_remove_unused", "ll_remove() with unused element", 1); /* Wrong list test */ check_result(ll_remove(&list[0], &elem[8]), DB_ERR_WRONGTABLE, "ll_remove_wronglist", "ll_remove() with element in wrong list", 1); /* Make sure removing from a one-item list does the right thing */ check_result(ll_remove(&list[1], &elem[8]), 0, "ll_remove_l1e8", "Remove an item from one-item list", 1); check_list(&list[1], 0, 0, 0, 1, "ll_remove_l1e8", "Test removal of an item from one-item list"); /* Now try removing an item from the head of a longer list */ check_result(ll_remove(&list[0], &elem[0]), 0, "ll_remove_l0e0", "Remove an item from head of list", 1); check_list(&list[0], 7, &elem[1], &elem[7], 0, "ll_remove_l0e0", "Test removal of an item from head of list"); check_elem(&elem[1], 0, &elem[2], &list[0], 0, 1, "ll_remove_l0e0", "Test removal of an item from head of list"); /* Now try the tail... */ check_result(ll_remove(&list[0], &elem[7]), 0, "ll_remove_l0e7", "Remove an item from tail of list", 1); check_list(&list[0], 6, &elem[1], &elem[6], 0, "ll_remove_l0e7", "Test removal of an item from tail of list"); check_elem(&elem[6], &elem[5], 0, &list[0], 0, 6, "ll_remove_l0e7", "Test removal of an item from tail of list"); /* Finally, try the middle of the list */ check_result(ll_remove(&list[0], &elem[3]), 0, "ll_remove_l0e3", "Remove an item from middle of list", 1); check_list(&list[0], 5, &elem[1], &elem[6], 0, "ll_remove_l0e3", "Test removal of an item from middle of list"); check_elem(&elem[2], &elem[1], &elem[4], &list[0], 0, 2, "ll_remove_l0e3", "Test removal of an item from middle of list"); check_elem(&elem[4], &elem[2], &elem[5], &list[0], 0, 4, "ll_remove_l0e3", "Test removal of an item from middle of list"); return 0; }