Permalink
Browse files

* add test Util

 * some refactoring Util
  • Loading branch information...
otsune committed Jun 15, 2008
1 parent cece8c7 commit 02d0a00b7509b3970a8b61feefe3d1cb5a8169e3
Showing with 95 additions and 3 deletions.
  1. +33 −3 lib/Foltia/Util.pm
  2. +33 −0 t/util-capture.t
  3. +29 −0 t/util-inject.t
View
@@ -22,14 +22,21 @@ our @EXPORT = qw(
getphpstyleconfig
);
+#XXX fixme for strict!
+my $startdatetime;
+my $phptoolpath;
+my $toolpath;
+#
my $__log;
sub log {
- $__log =| new Foltia::Logger;
+ if (ref($__log) ne 'Foltia::Logger') {
+ $__log = new Foltia::Logger;
+ }
return $__log;
}
sub writelog {
- log->write(@_);
+ __PACKAGE__->log->write(@_);
}
#end writelog
@@ -122,7 +129,7 @@ sub processfind{
sub filenameinjectioncheck {
- my ($self, $filename) = @_;
+ my $filename = shift;
$filename =~ s/\///gi;
$filename =~ s/\;//gi;
$filename =~ s/\&//gi;
@@ -163,6 +170,29 @@ sub getphpstyleconfig {
return $configline;
}#end sub getphpstyleconfig
+sub capture_image_filename_parse {
+ use POSIX;
+ # filenameの妥当性をチェック
+ my $filename = shift;
+ my @filenametmp = split(/\./,$filename);
+ my ($tid, $countno, $date, $time) = split(/-/,$filenametmp[0]);
+
+ # tidが数字のみかチェック
+ #print "$tid\n";
+ $tid =~ s/[^0-9]//ig;
+ $countno =~ s/[^0-9]//ig;
+ $date =~ s/[^0-9]//ig;
+
+ $date = $date ? $date : POSIX::strftime("%Y%m%d", localtime);
+ # print "DATE:$date\n";
+
+ $time = unpack('A4', $time);
+ $time =~ s/[^0-9]//ig;
+ $time = $time ? $time : POSIX::strftime("%H%M", localtime);
+
+ return ($tid, $countno, $date, $time);
+}
+
1;
__END__
View
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+
+use Foltia::Util;
+
+use Test::Base;
+filters { input => 'chomp', expected => 'yaml' };
+plan tests => 1 * blocks;
+
+run {
+ my $block = shift;
+ my @filename_capture = [Foltia::Util::capture_image_filename_parse($block->input)];
+ is_deeply @filename_capture, $block->expected, $block->name;
+}
+
+__END__
+=== 0--20080615-1324-99.m2p
+--- input
+0--20080615-1324-99.m2p
+--- expected
+- '0'
+- ''
+- '20080615'
+- '1324'
+
+=== 10-23-20080115-2468-22.m2p
+--- input
+10-23-20080115-2468-22.m2p
+--- expected
+- '10'
+- '23'
+- '20080115'
+- '2468'
View
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+use Foltia::Util;
+
+use Test::Base;
+filters { input => 'chomp', expected => 'chomp' };
+plan tests => 1 * blocks;
+
+run {
+ my $block = shift;
+ is Foltia::Util::filenameinjectioncheck($block->input), $block->expected;
+}
+
+__END__
+===
+--- input
+0--20080615-1324-99_a;b&c|d/e.m2p
+--- expected
+0--20080615-1324-99_abcde.m2p
+
+===
+--- input
+0--20080101-2468-11_ghik.m2p
+--- expected
+0--20080101-2468-11_ghik.m2p
+
+
+

0 comments on commit 02d0a00

Please sign in to comment.