From: Graham B. <gb...@us...> - 2002-02-04 19:16:54
|
Update of /cvsroot/perl-ldap/ldap/t In directory usw-pr-cvs1:/tmp/cvs-serv5355/t Modified Files: 00ldif-entry.t 50populate.t 51search.t 52modify.t 53schema.t 54dse.t 55ssl.t common.pl Log Message: Some testcase tweaks Index: 00ldif-entry.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/00ldif-entry.t,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- 00ldif-entry.t 2001/10/29 16:48:12 1.5 +++ 00ldif-entry.t 2002/02/04 18:58:53 1.6 @@ -5,21 +5,29 @@ } -print "1..9\n"; +print "1..11\n"; use Net::LDAP::LDIF; -my $infile = "data/00-in.ldif"; -my $outfile = "$TEMPDIR/00-out1.ldif"; -my $cmpfile = $infile; +my $infile = "data/00-in.ldif"; +my $outfile1 = "$TEMPDIR/00-out1.ldif"; +my $outfile2 = "$TEMPDIR/00-out2.ldif"; +my $cmpfile1 = "data/00-cmp.ldif"; +my $cmpfile2 = $infile; -@entry = Net::LDAP::LDIF->new($infile,"r")->read; +my $ldif = Net::LDAP::LDIF->new($infile,"r"); -Net::LDAP::LDIF->new($outfile,"w")->write(@entry); +@entry = $ldif->read; -print "not " if compare($cmpfile,$outfile); -print "ok 1\n"; +ok($ldif->version == 1, "version == 1"); + +Net::LDAP::LDIF->new($outfile1,"w")->write(@entry); +Net::LDAP::LDIF->new($outfile2,"w", version => 1)->write(@entry); + +ok(!compare($cmpfile1,$outfile1), $cmpfile1); +ok(!compare($cmpfile2,$outfile2), $cmpfile2); + $e = $entry[0]; $e->changetype('modify'); @@ -36,33 +44,35 @@ $ldif->write($e); $ldif->write_cmd($e); $ldif->done; -print "not " if compare($cmpfile,$outfile); -print "ok 2\n"; +ok(!compare($cmpfile,$outfile), $cmpfile); $e->add('name' => 'Graham Barr'); $e->add('name;en-us' => 'Bob'); -print "not " unless join(":",sort $e->attributes) eq "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber"; -print "ok 3\n"; +print "not " unless +ok( + join(":",sort $e->attributes) + eq + "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber", + "attributes"); -print "not " unless join(":",sort $e->attributes(nooptions => 1)) eq "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber"; -print "ok 4\n"; +print "not " unless +ok( + join(":",sort $e->attributes(nooptions => 1)) + eq + "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber", + "attributes - nooptions"); $r = $e->get_value('name', asref => 1); -print "not " unless $r and @$r == 1 and $r->[0] eq 'Graham Barr'; -print "ok 5\n"; +ok(($r and @$r == 1 and $r->[0] eq 'Graham Barr'), "name eq Graham Barr"); $r = $e->get_value('name;en-us', asref => 1); -print "not " unless $r and @$r == 1 and $r->[0] eq 'Bob'; -print "ok 6\n"; +ok(($r and @$r == 1 and $r->[0] eq 'Bob'), "name;en-us eq Bob"); $r = $e->get_value('name', alloptions => 1, asref => 1); -print "not " unless $r and join("*", sort keys %$r) eq "*;en-us"; -print "ok 7\n"; +ok(($r and join("*", sort keys %$r) eq "*;en-us"), "name keys"); -print "not " unless $r and $r->{''} and @{$r->{''}} == 1 and $r->{''}[0] eq 'Graham Barr'; -print "ok 8\n"; +ok(($r and $r->{''} and @{$r->{''}} == 1 and $r->{''}[0] eq 'Graham Barr'), "name alloptions"); -print "not " unless $r and $r->{';en-us'} and @{$r->{';en-us'}} == 1 and $r->{';en-us'}[0] eq 'Bob'; -print "ok 9\n"; +ok(($r and $r->{';en-us'} and @{$r->{';en-us'}} == 1 and $r->{';en-us'}[0] eq 'Bob'), "name alloptions Bob"); Index: 50populate.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/50populate.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- 50populate.t 2001/06/14 20:13:58 1.3 +++ 50populate.t 2002/02/04 18:58:53 1.4 @@ -8,18 +8,16 @@ print "1..7\n"; $ldap = client(); -print "ok 1\n"; +ok($ldap, "client"); $mesg = $ldap->bind($MANAGERDN, password => $PASSWD); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 2\n"; +ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error); -print "not " unless ldif_populate($ldap, "data/50-in.ldif"); -print "ok 3\n"; +ok(ldif_populate($ldap, "data/50-in.ldif"), "data/50-in.ldif"); + $mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*'); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 4\n"; +ok(!$mesg->code, "search: " . $mesg->code . ": " . $mesg->error); -compare_ldif("50",5,$mesg,$mesg->sorted); +compare_ldif("50",$mesg,$mesg->sorted); Index: 51search.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/51search.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- 51search.t 2001/06/14 20:13:58 1.3 +++ 51search.t 2002/02/04 18:58:56 1.4 @@ -5,38 +5,33 @@ start_server(); } -my $i = 4; - - print "1..15\n"; $ldap = client(); -print "ok 1\n"; +ok($ldap, "client"); $mesg = $ldap->bind($MANAGERDN, password => $PASSWD); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 2\n"; +ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error); -print "not " unless ldif_populate($ldap, "data/51-in.ldif"); -print "ok 3\n"; +ok(ldif_populate($ldap, "data/51-in.ldif"), "data/51-in.ldif"); # now search the database # Exact searching $mesg = $ldap->search(base => $BASEDN, filter => 'sn=jensen'); -$i += compare_ldif("51a",$i,$mesg,$mesg->sorted); +compare_ldif("51a",$mesg,$mesg->sorted); # Or searching $mesg = $ldap->search(base => $BASEDN, filter => '(|(objectclass=groupofnames)(sn=jones))'); -$i += compare_ldif("51b",$i,$mesg,$mesg->sorted); +compare_ldif("51b",$mesg,$mesg->sorted); # And searching $mesg = $ldap->search(base => $BASEDN, filter => '(&(objectclass=groupofnames)(cn=A*))'); -$i += compare_ldif("51c",$i,$mesg,$mesg->sorted); +compare_ldif("51c",$mesg,$mesg->sorted); # Not searching $mesg = $ldap->search(base => $BASEDN, filter => '(!(objectclass=person))'); -$i += compare_ldif("51d",$i,$mesg,$mesg->sorted); +compare_ldif("51d",$mesg,$mesg->sorted); Index: 52modify.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/52modify.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- 52modify.t 2001/06/14 20:13:58 1.3 +++ 52modify.t 2002/02/04 18:58:57 1.4 @@ -8,23 +8,20 @@ print "1..7\n"; $ldap = client(); -print "ok 1\n"; +ok($ldap, "client"); $mesg = $ldap->bind($MANAGERDN, password => $PASSWD); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 2\n"; +ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error); -print "not " unless ldif_populate($ldap, "data/52-in.ldif"); -print "ok 3\n"; +ok(ldif_populate($ldap, "data/52-in.ldif"), "data/52-in.ldif"); # load modify LDIF -print "not " unless ldif_populate($ldap, "data/52-mod.ldif", 'modify'); -print "ok 4\n"; +ok(ldif_populate($ldap, "data/52-mod.ldif", 'modify'), "data/52-mod.ldif"); # now search the database $mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*'); -compare_ldif("52",5,$mesg,$mesg->sorted); +compare_ldif("52",$mesg,$mesg->sorted); Index: 53schema.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/53schema.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- 53schema.t 2001/08/17 16:20:58 1.3 +++ 53schema.t 2002/02/04 18:59:02 1.4 @@ -6,32 +6,35 @@ my $schema = Net::LDAP::Schema->new( "data/schema.in" ) or die "Cannot open schema"; print "ok 1\n"; -my @atts = sort $schema->attributes(); +my @atts = $schema->all_attributes(); print "not " unless @atts == 55; print "ok 2\n"; print "The schema contains ", scalar @atts, " attributes\n"; -my @ocs = $schema->objectclasses(); +my @ocs = $schema->all_objectclasses(); print "not " unless @ocs == 22; print "ok 3\n"; print "The schema contains ", scalar @ocs, " object classes\n"; @atts = $schema->must( "person" ); -print "not " unless join(' ',@atts) eq join(' ',qw(cn sn)); +print "not " unless join(' ', sort map $_->{name}, @atts) eq join(' ',sort qw(cn sn objectClass)); print "ok 4\n"; print "The 'person' OC must have these attributes [", - join( ",", @atts ), + join( ",", map $_->{name}, @atts ), "]\n"; @atts = $schema->may( "mhsOrganizationalUser" ); print "not " if @atts; print "ok 5\n"; -print "The 'mhsOrganizationalUser' OC must have these attributes [", - join( ",", @atts ), +print "The 'mhsOrganizationalUser' OC may have these attributes [", + join( ",", map $_->{name}, @atts ), "]\n"; -print "not " if defined $schema->item('distinguishedName','max_length'); +print "not " if defined $schema->attribute('distinguishedName')->{max_length}; print "ok 6\n"; -print "not " unless $schema->item('userPassword','max_length') == 128; +print "not " unless $schema->attribute('userPassword')->{max_length} == 128; print "ok 7\n"; + +use Data::Dumper; +print Dumper($schema); Index: 54dse.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/54dse.t,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- 54dse.t 2001/07/06 10:55:21 1.1 +++ 54dse.t 2002/02/04 18:59:03 1.2 @@ -8,10 +8,10 @@ print "1..2\n"; $ldap = client(); -print "ok 1\n"; +ok($ldap, "client"); -$dse = $ldap->root_dse or print "not "; -print "ok 2\n"; +$dse = $ldap->root_dse; +ok($dse, "dse"); use Net::LDAP::LDIF; Net::LDAP::LDIF->new(qw(- w))->write_entry($dse) if $dse; Index: 55ssl.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/55ssl.t,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- 55ssl.t 2001/08/24 19:10:54 1.2 +++ 55ssl.t 2002/02/04 18:59:03 1.3 @@ -8,40 +8,33 @@ print "1..15\n"; $ldap = client(); -print "ok 1\n"; +ok($ldap, "client"); $mesg = $ldap->bind($MANAGERDN, password => $PASSWD, version => 3); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 2\n"; +ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error); -print "not " unless ldif_populate($ldap, "data/50-in.ldif"); -print "ok 3\n"; +ok(ldif_populate($ldap, "data/50-in.ldif"), "data/50-in.ldif"); $mesg = $ldap->start_tls; -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 4\n"; +ok(!$mesg->code, "start_stl: " . $mesg->code . ": " . $mesg->error); $mesg = $ldap->start_tls; -print "# ",$mesg->code,": ",$mesg->error,"\nnot " unless $mesg->code; -print "ok 5\n"; +ok($mesg->code, "start_stl: " . $mesg->code . ": " . $mesg->error); $mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*'); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 6\n"; +ok(!$mesg->code, "search: " . $mesg->code . ": " . $mesg->error); -compare_ldif("50",7,$mesg,$mesg->sorted); +compare_ldif("50",$mesg,$mesg->sorted); -$ldap = client(ssl => 1) or print "not "; -print "ok 10\n"; +$ldap = client(ssl => 1); +ok($ldap, "ssl client"); $mesg = $ldap->start_tls; -print "# ",$mesg->code,": ",$mesg->error,"\nnot " unless $mesg->code; -print "ok 11\n"; +ok($mesg->code, "start_stl: " . $mesg->code . ": " . $mesg->error); $mesg = $ldap->search(base => $BASEDN, filter => 'objectclass=*'); -print "# ",$mesg->code,": ",$mesg->error,"\nnot " if $mesg->code; -print "ok 12\n"; +ok(!$mesg->code, "search: " . $mesg->code . ": " . $mesg->error); -compare_ldif("50",13,$mesg,$mesg->sorted); +compare_ldif("50",$mesg,$mesg->sorted); Index: common.pl =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/common.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- common.pl 2001/07/06 10:55:21 1.4 +++ common.pl 2002/02/04 18:59:04 1.5 @@ -88,7 +88,7 @@ open(STDOUT,">&STDERR"); close(STDIN); - exec(@LDAPD); + exec(@LDAPD) or die "cannot exec @LDAPD"; } sleep 2; # wait for server to start @@ -128,24 +128,18 @@ } sub compare_ldif { - my($test,$test_num,$mesg) = splice(@_,0,3); + my($test,$mesg) = splice(@_,0,2); - if ($mesg->code) { - print $mesg->error,"\n"; - print "not ok ",$test_num++,"\n"; - print "not ok ",$test_num++,"\n"; - print "not ok ",$test_num++,"\n"; - return 3; + unless (ok(!$mesg->code, $mesg->error)) { + skip(2, $mesg->error); + return; } - print "ok ",$test_num++,"\n"; my $ldif = Net::LDAP::LDIF->new("$TEMPDIR/${test}-out.ldif","w", lowercase => 1); - unless ($ldif) { - print "not ok",$test_num++,"\n"; - print "not ok",$test_num++,"\n"; - return 3; + unless (ok($ldif, "Read ${test}-out.ldif")) { + skip(1,"Read error"); + return; } - print "ok ",$test_num++,"\n"; foreach $entry (@_) { foreach $attr ($entry->attributes) { @@ -156,9 +150,7 @@ $ldif->done; # close the file; - compare("$TEMPDIR/${test}-out.ldif","data/${test}-cmp.ldif") && print "not "; - print "ok ",$test_num++,"\n"; - 3; + ok(!compare("$TEMPDIR/${test}-out.ldif","data/${test}-cmp.ldif"), "data/${test}-cmp.ldif"); } require File::Compare; @@ -188,5 +180,41 @@ } $ok; } + +my $number = 0; +sub ok { + my ($condition, $name) = @_; + + my $message = $condition ? "ok " : "not ok "; + $message .= ++$number; + $message .= " # $name" if defined $name; + print $message, "\n"; + return $condition; +} + +sub is { + my ($got, $expected, $name) = @_; + + for ($got, $expected) { + $_ = 'undef' unless defined $_; + } + + unless (ok($got eq $expected, $name)) { + warn "Got: '$got'\nExpected: '$expected'\n" . join(' ', caller) . "\n"; + } +} + +sub skip { + my ($reason, $num) = @_; + $reason ||= ''; + $number ||= 1; + + for (1 .. $num) { + $number++; + print "ok $number # skip $reason\n"; + } +} + +1; 1; |