diff options
| author | fukachan <fukachan> | 2003-02-11 14:20:32 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2003-02-11 14:20:32 +0000 |
| commit | e6a6cbd1748b287bcb7f1feb4a6fc98a71d306a4 (patch) | |
| tree | 8bbed9af0bde2aa4d0adc186f00a3bac37df18a6 /fml/lib/IO | |
| parent | 93a3cc59074b238e30128fe93e5130e455739761 (diff) | |
| download | fml8-e6a6cbd1748b287bcb7f1feb4a6fc98a71d306a4.tar.gz fml8-e6a6cbd1748b287bcb7f1feb4a6fc98a71d306a4.tar.bz2 fml8-e6a6cbd1748b287bcb7f1feb4a6fc98a71d306a4.zip | |
basic test of get_value_as_array_ref()
Diffstat (limited to 'fml/lib/IO')
| -rwxr-xr-x | fml/lib/IO/t/get_value_as_array_ref.pl | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/fml/lib/IO/t/get_value_as_array_ref.pl b/fml/lib/IO/t/get_value_as_array_ref.pl new file mode 100755 index 00000000..f6ed80ac --- /dev/null +++ b/fml/lib/IO/t/get_value_as_array_ref.pl @@ -0,0 +1,71 @@ +#-*- perl -*- +# +# Copyright (C) 2003 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML$ +# + +use strict; +use Carp; + +my $org_file = "/var/spool/ml/elena/etc/passwd-admin"; +my $map = "file:". $org_file; +my $addr = $ENV{'USER'}; +my $key = 'fukachan@sapporo.iij.ad.jp'; +my $debug = defined $ENV{ 'debug' } ? 1 : 0; + +### MAIN ### +print "${map}->get_value_as_array_ref() ... "; + +# append +use IO::Adapter; +my $obj = new IO::Adapter $map; +$obj->open(); + +# +# 1. compare passwords. +# +my $a = $obj->get_value_as_array_ref( $key ); +my $p = $a->[0]; +my $pwd = _read($org_file); +my $pn = $pwd->{ $key }->[ 1 ]; + +if ($p eq $pn) { + print "ok\n"; +} +else { + print "not ok ('$p' ?= '$pn')\n"; +} + +if ($debug) { + my $i = 0; + for my $p (@$a) { + print STDERR ++$i, "\t=>\t", $p, "\n"; + } +} + +exit 0; + + +sub _read +{ + my ($file) = @_; + my $h = {}; + + use FileHandle; + my $fh = new FileHandle $file; + + if (defined $fh) { + my $buf; + while ($buf = <$fh>) { + my ($k, @v) = split(/\s+/, $buf); + + $h->{ $k } = [ $k, @v ]; + } + $fh->close(); + } + + return $h; +} |
