Sun-Solaris-Project

 view release on metacpan or  search on metacpan

t/Project.t  view on Meta::CPAN

# Read in the /etc/project file, & build the same datastructure as will be
# returned by getprojent et al.  Poor pickings as by default most of the fields
# are empty
open($fh, "<" . &PROJF_PATH) || fatal($!);
$pf1 = read_pfile($fh);
close($fh);
my %pf_byname = map({ $_->[0] => $_} @$pf1);
my %pf_byid = map({ $_->[1] => $_} @$pf1);
my (%h, @a1, @a2, $k, $v);

# Test getprojent.  Don't assume anything about the order it returns stuff in
%h = %pf_byname;
$pass = 1;
@a2 = ();
while (@a1 = getprojent()) {
	@a2 = @a1 if (! scalar(@a2));
	if (exists($h{$a1[0]})) {
		$pass = 0 if (! cmp_recs(\@a1, $h{$a1[0]}));
		delete($h{$a1[0]});
	} else {
		$pass = 0;
	}
}
$pass && ! %h ? pass() : fail();
@a1 = getprojent();
cmp_recs(\@a1, []) ? pass() : fail();

# Test setprojent/endprojent
endprojent();
@a1 = getprojent();
cmp_recs(\@a1, \@a2) ? pass() : fail();
setprojent();
@a1 = getprojent();
cmp_recs(\@a1, \@a2) ? pass() : fail();
setprojent();

# Test getprojbyname
$pass = 1;
while (($k, $v) = each(%pf_byname)) {
	@a1 = getprojbyname($k);
	$pass = 0 if (! cmp_recs(\@a1, $v));
}
$pass ? pass() : fail();

# Test getprojbyid
$pass = 1;
while (($k, $v) = each(%pf_byid)) {
	@a1 = getprojbyid($k);
	$pass = 0 if (! cmp_recs(\@a1, $v));
}
$pass ? pass() : fail();

# Test getprojidbyname
$pass = 1;
while (($k, $v) = each(%pf_byname)) {
	$pass = 0 if (getprojidbyname($k) != $v->[1]);
}
$pass ? pass() : fail();

# Test getdefaultproj
$s = '/usr/xpg4/bin/id -p ' . getpwuid($>);
($s) = `$s` =~ /projid=\d+\(([^)]+)\)/;
defined($s) && $s eq getdefaultproj(getpwuid($>)) ? pass() : fail();

# Test inproj
$pass = 1;
if (! open($fh, "<" . "/etc/passwd")) {
	fatal($!);
}
close($fh);

# Cleanup
unlink("/tmp/project.$$");



( run in 0.460 second using v1.01-cache-2.11-cpan-39bf76dae61 )