Exemplo n.º 1
0
static int
group_fill_test_data(struct group_test_data *td)
{
	struct group *grp;

	setgroupent(1);
	while ((grp = getgrent()) != NULL) {
		if (group_test_correctness(grp, NULL) == 0)
			TEST_DATA_APPEND(group, td, grp);
		else
			return (-1);
	}
	endgrent();

	return (0);
}
Exemplo n.º 2
0
static int
protoent_fill_test_data(struct protoent_test_data *td)
{
    struct protoent *pe;

    setprotoent(1);
    while ((pe = getprotoent()) != NULL) {
        if (protoent_test_correctness(pe, NULL) == 0)
            TEST_DATA_APPEND(protoent, td, pe);
        else
            return (-1);
    }
    endprotoent();

    return (0);
}
Exemplo n.º 3
0
static int
passwd_fill_test_data(struct passwd_test_data *td)
{
	struct passwd *pwd;

	setpassent(1);
	while ((pwd = getpwent()) != NULL) {
		if (passwd_test_correctness(pwd, NULL) == 0)
			TEST_DATA_APPEND(passwd, td, pwd);
		else
			return (-1);
	}
	endpwent();

	return (0);
}
Exemplo n.º 4
0
static int
servent_fill_test_data(struct servent_test_data *td)
{
	struct servent *serv;
		
	setservent(1);
	while ((serv = getservent()) != NULL) {
		if (servent_test_correctness(serv, NULL) == 0)
			TEST_DATA_APPEND(servent, td, serv);
		else
			return (-1);
	}
	endservent();
	
	return (0);
}
Exemplo n.º 5
0
static int
rpcent_fill_test_data(struct rpcent_test_data *td)
{
	struct rpcent *rpc;

	setrpcent(1);
	while ((rpc = getrpcent()) != NULL) {
		if (rpcent_test_correctness(rpc, NULL) == 0)
			TEST_DATA_APPEND(rpcent, td, rpc);
		else
			return (-1);
	}
	endrpcent();

	return (0);
}
Exemplo n.º 6
0
static int
hostent_test_gethostbyaddr(struct hostent *he, void *mdata)
{
	struct hostent *result;
	struct hostent_test_data *addr_test_data;
	int rv;	
	
	addr_test_data = (struct hostent_test_data *)mdata;
	
	/* We should omit unresolved hostents */
	if (he->h_addr_list != NULL) {
		char **cp;
		for (cp = he->h_addr_list; *cp; ++cp) {
			if (debug)
			    printf("doing reverse lookup for %s\n", he->h_name);
			
			result = __gethostbyaddr(*cp, he->h_length,
			    he->h_addrtype);
			if (result == NULL) {
				if (debug)
				    printf("warning: reverse lookup failed\n");
				
				continue;
			}
			rv = hostent_test_correctness(result, NULL);
			if (rv != 0) {
			    __freehostent(result);
			    return (rv);
			}
			
			if (addr_test_data != NULL)
			    TEST_DATA_APPEND(hostent, addr_test_data, result);
			
			__freehostent(result);
		}
	}
	
	return (0);
}
Exemplo n.º 7
0
int
run_tests(const char *snapshot_file, enum test_methods method)
{
	struct usershell_test_data td, td_snap;
	struct usershell ushell;
	int rv;

	rv = 0;

	TEST_DATA_INIT(usershell, &td, clone_usershell, free_usershell);
	TEST_DATA_INIT(usershell, &td_snap, clone_usershell, free_usershell);

	setusershell();
	while ((ushell.path = getusershell()) != NULL) {
		printf("usershell found:\n");
		dump_usershell(&ushell);
		TEST_DATA_APPEND(usershell, &td, &ushell);
	}
	endusershell();

	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {
			if (errno == ENOENT)
				method = TEST_BUILD_SNAPSHOT;
			else {
				printf("can't access the snapshot file %s\n",
				    snapshot_file);

				rv = -1;
				goto fin;
			}
		} else {
			rv = TEST_SNAPSHOT_FILE_READ(usershell, snapshot_file,
				&td_snap, usershell_read_snapshot_func);
			if (rv != 0) {
				printf("error reading snapshot file\n");
				goto fin;
			}
		}
	}

	switch (method) {
	case TEST_GETUSERSHELL:
		rv = DO_2PASS_TEST(usershell, &td, &td_snap,
			compare_usershell, NULL);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL) {
			rv = TEST_SNAPSHOT_FILE_WRITE(usershell, snapshot_file,
			    &td, sdump_usershell);
		}
		break;
	default:
		rv = 0;
		break;
	}

fin:
	TEST_DATA_DESTROY(usershell, &td_snap);
	TEST_DATA_DESTROY(usershell, &td);

	return (rv);
}