static int rpcent_test_correctness(struct rpcent *rpc, void *mdata) { printf("testing correctness with the following data:\n"); dump_rpcent(rpc); if (rpc == NULL) goto errfin; if (rpc->r_name == NULL) goto errfin; if (rpc->r_number < 0) goto errfin; if (rpc->r_aliases == NULL) goto errfin; printf("correct\n"); return (0); errfin: printf("incorrect\n"); return (-1); }
static int compare_rpcent(struct rpcent *rpc1, struct rpcent *rpc2, void *mdata) { char **c1, **c2; if (rpc1 == rpc2) return 0; if ((rpc1 == NULL) || (rpc2 == NULL)) goto errfin; if ((strcmp(rpc1->r_name, rpc2->r_name) != 0) || (rpc1->r_number != rpc2->r_number)) goto errfin; c1 = rpc1->r_aliases; c2 = rpc2->r_aliases; if ((rpc1->r_aliases == NULL) || (rpc2->r_aliases == NULL)) goto errfin; for (;*c1 && *c2; ++c1, ++c2) if (strcmp(*c1, *c2) != 0) goto errfin; if ((*c1 != '\0') || (*c2 != '\0')) goto errfin; return 0; errfin: if (mdata == NULL) { printf("following structures are not equal:\n"); dump_rpcent(rpc1); dump_rpcent(rpc2); } return (-1); }
static int rpcent_test_getrpcbyname(struct rpcent *rpc_model, void *mdata) { char **alias; struct rpcent *rpc; if (debug) { printf("testing getrpcbyname() with the following data:\n"); dump_rpcent(rpc_model); } rpc = getrpcbyname(rpc_model->r_name); if (rpcent_test_correctness(rpc, NULL) != 0) goto errfin; if ((compare_rpcent(rpc, rpc_model, NULL) != 0) && (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc) !=0)) goto errfin; for (alias = rpc_model->r_aliases; *alias; ++alias) { rpc = getrpcbyname(*alias); if (rpcent_test_correctness(rpc, NULL) != 0) goto errfin; if ((compare_rpcent(rpc, rpc_model, NULL) != 0) && (rpcent_check_ambiguity( (struct rpcent_test_data *)mdata, rpc) != 0)) goto errfin; } if (debug) printf("ok\n"); return (0); errfin: if (debug) printf("not ok\n"); return (-1); }
static int rpcent_test_getrpcbynumber(struct rpcent *rpc_model, void *mdata) { struct rpcent *rpc; printf("testing getrpcbyport() with the following data...\n"); dump_rpcent(rpc_model); rpc = getrpcbynumber(rpc_model->r_number); if (rpcent_test_correctness(rpc, NULL) != 0 || (compare_rpcent(rpc, rpc_model, NULL) != 0 && rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc) != 0)) { printf("not ok\n"); return (-1); } else { printf("ok\n"); return (0); } }