diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 00:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 00:06:44 +0000 |
commit | 44cf8ec67278bd1ab6c7f83a9993f7a5686a9541 (patch) | |
tree | 5eec4b0d1a3f163d279c3c27c03324ba49fa235a /perl/t | |
parent | Initial commit. (diff) | |
download | zbar-44cf8ec67278bd1ab6c7f83a9993f7a5686a9541.tar.xz zbar-44cf8ec67278bd1ab6c7f83a9993f7a5686a9541.zip |
Adding upstream version 0.23.93.upstream/0.23.93upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'perl/t')
-rwxr-xr-x | perl/t/Decoder.t | 111 | ||||
-rwxr-xr-x | perl/t/Image.t | 186 | ||||
-rwxr-xr-x | perl/t/Processor.t | 140 | ||||
-rwxr-xr-x | perl/t/Scanner.t | 23 | ||||
-rwxr-xr-x | perl/t/ZBar.t | 68 | ||||
-rw-r--r-- | perl/t/barcode.png | bin | 0 -> 1182 bytes | |||
-rw-r--r-- | perl/t/pod-coverage.t | 12 | ||||
-rw-r--r-- | perl/t/pod.t | 12 |
8 files changed, 552 insertions, 0 deletions
diff --git a/perl/t/Decoder.t b/perl/t/Decoder.t new file mode 100755 index 0000000..12ba86f --- /dev/null +++ b/perl/t/Decoder.t @@ -0,0 +1,111 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Decoder.t' + +use warnings; +use strict; +use Test::More tests => 17; + +######################### + +BEGIN { use_ok('Barcode::ZBar') } + +######################### + +my $decoder = Barcode::ZBar::Decoder->new(); +isa_ok($decoder, 'Barcode::ZBar::Decoder', 'decoder'); + +$decoder->parse_config('enable'); + +######################### + +can_ok($decoder, qw(set_config parse_config reset new_scan decode_width + get_color get_configs get_direction get_data get_modifiers + get_type set_handler)); + +######################### + +my $sym = $decoder->decode_width(5); +is($sym, Barcode::ZBar::Symbol::NONE, 'enum/enum compare'); + +######################### + +ok($sym == 0, 'enum/numeric compare'); + +######################### + +is($sym, 'None', 'enum/string compare'); + +######################### + +my $handler_type = 0; +my $explicit_closure = 0; + +$decoder->set_handler(sub { + if(!$handler_type) { + is($_[0], $decoder, 'handler decoder'); + } + + my $type = $_[0]->get_type(); + $handler_type = $type + if(!$handler_type or $type > Barcode::ZBar::Symbol::PARTIAL); + + ${$_[1]} += 1 +}, \$explicit_closure); + +######################### + +$decoder->reset(); +is($decoder->get_color(), Barcode::ZBar::SPACE, 'reset color'); + +######################### + +is($decoder->get_direction(), 0, 'reset direction'); + +######################### + +$decoder->set_config(Barcode::ZBar::Symbol::QRCODE, + Barcode::ZBar::Config::ENABLE, 0); + +my $encoded = + '9 111 212241113121211311141132 11111 311213121312121332111132 111 9'; + +foreach my $width (split(/ */, $encoded)) { + my $tmp = $decoder->decode_width($width); + if($tmp > Barcode::ZBar::Symbol::PARTIAL) { + $sym = ($sym == Barcode::ZBar::Symbol::NONE) ? $tmp : -1; + } +} +is($sym, Barcode::ZBar::Symbol::EAN13, 'EAN-13 type'); + +######################### + +is_deeply([$decoder->get_configs($sym)], + [Barcode::ZBar::Config::ENABLE, + Barcode::ZBar::Config::EMIT_CHECK], + 'read configs'); + +######################### + +is_deeply([$decoder->get_modifiers()], [], 'read modifiers'); + +######################### + +is($decoder->get_data(), '6268964977804', 'EAN-13 data'); + +######################### + +is($decoder->get_color(), Barcode::ZBar::BAR, 'post-scan color'); + +######################### + +is($decoder->get_direction(), 1, 'decode direction'); + +######################### + +is($handler_type, Barcode::ZBar::Symbol::EAN13, 'handler type'); + +######################### + +is($explicit_closure, 2, 'handler explicit closure'); + +######################### diff --git a/perl/t/Image.t b/perl/t/Image.t new file mode 100755 index 0000000..a63b985 --- /dev/null +++ b/perl/t/Image.t @@ -0,0 +1,186 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Image.t' + +use warnings; +use strict; +use Test::More tests => 29; + +######################### + +BEGIN { use_ok('Barcode::ZBar') } + +Barcode::ZBar::set_verbosity(16); + +######################### + +my $image = Barcode::ZBar::Image->new(); +isa_ok($image, 'Barcode::ZBar::Image', 'image'); + +######################### + +my $scanner = Barcode::ZBar::ImageScanner->new(); +isa_ok($scanner, 'Barcode::ZBar::ImageScanner', 'image scanner'); + +######################### + +can_ok($image, qw(convert convert_resize + get_format get_size get_data + set_format set_size set_data)); + +######################### + +can_ok($scanner, qw(set_config parse_config enable_cache scan_image)); + +######################### + +$image->set_format('422P'); +my $fmt = $image->get_format(); +is($fmt, '422P', 'string format accessors'); + +######################### + +ok($fmt == 0x50323234, 'numeric format accessors'); + +######################### + +$image->set_size(114, 80); +is_deeply([$image->get_size()], [114, 80], 'size accessors'); + +######################### + +$image->set_crop(20, 20, 74, 40); +is_deeply([$image->get_crop()], [20, 20, 74, 40], 'crop accessors'); + +######################### + +$image->set_crop(-57, -40, 228, 160); +is_deeply([$image->get_crop()], [0, 0, 114, 80], 'crop clipping'); + +######################### + +$image->set_crop(10, 10, 94, 60); +is_deeply([$image->get_crop()], [10, 10, 94, 60], 'crop accessors'); + +######################### + +$image->set_size(114, 80); +is_deeply([$image->get_crop()], [0, 0, 114, 80], 'crop reset'); + +######################### + +# FIXME avoid skipping these (eg embed image vs ImageMagick) +SKIP: { + eval { require Image::Magick }; + skip "Image::Magick not installed", 16 if $@; + + my $im = Image::Magick->new(); + my $err = $im->Read('t/barcode.png'); + die($err) if($err); + + $image->set_size($im->Get(qw(columns rows))); + + { + my $data = $im->ImageToBlob( + magick => 'YUV', + 'sampling-factor' => '4:2:2', + interlace => 'Plane'); + $image->set_data($data); + } + + $image = $image->convert('Y800'); + isa_ok($image, 'Barcode::ZBar::Image', 'image'); + + ######################### + + is($image->get_format(), 'Y800', 'converted image format'); + + ######################### + + is_deeply([$image->get_size()], [114, 80], 'converted image size'); + + ######################### + + is($scanner->scan_image($image), 1, 'scan result'); + + ######################### + + my @symbols = $image->get_symbols(); + is(scalar(@symbols), 1, 'result size'); + + ######################### + + my $sym = $symbols[0]; + isa_ok($sym, 'Barcode::ZBar::Symbol', 'symbol'); + + ######################### + + can_ok($sym, qw(get_type get_configs get_modifiers get_data get_quality + get_count get_loc get_orientation)); + + ######################### + + is($sym->get_type(), Barcode::ZBar::Symbol::EAN13, 'result type'); + + ######################### + + is_deeply([$sym->get_configs()], + [Barcode::ZBar::Config::ENABLE, + Barcode::ZBar::Config::EMIT_CHECK], + 'result configs'); + + ######################### + + is_deeply([$sym->get_modifiers()], [], 'result modifiers'); + + ######################### + + is($sym->get_data(), '9876543210128', 'result data'); + + ######################### + + ok($sym->get_quality() > 0, 'quality'); + + ######################### + + my @loc = $sym->get_loc(); + ok(scalar(@loc) >= 4, 'location size'); + + ######################### + + my $failure = undef; + foreach my $pt (@loc) { + if(ref($pt) ne 'ARRAY') { + $failure = ("location entry is wrong type:" . + " expecting ARRAY ref, got " . ref($pt)); + last; + } + if(scalar(@{$pt}) != 2) { + $failure = ("location coordinate has too many entries:" . + " expecting 2, got " . scalar(@{$pt})); + last; + } + } + ok(!defined($failure), 'location structure') or + diag($failure); + + ######################### + + is($sym->get_orientation(), Barcode::ZBar::Orient::UP, 'orientation'); + + ######################### + + my @comps = $sym->get_components(); + is(scalar(@comps), 0, 'components size'); + + ######################### +} + +$scanner->recycle_image($image); + +my @symbols = $image->get_symbols(); +is(scalar(@symbols), 0, 'recycled result size'); + +######################### + + +# FIXME more image tests diff --git a/perl/t/Processor.t b/perl/t/Processor.t new file mode 100755 index 0000000..92bf6fe --- /dev/null +++ b/perl/t/Processor.t @@ -0,0 +1,140 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Processor.t' + +use warnings; +use strict; +use Test::More tests => 20; + +######################### + +BEGIN { use_ok('Barcode::ZBar') } + +Barcode::ZBar::set_verbosity(32); + +######################### + +my $proc = Barcode::ZBar::Processor->new(); +isa_ok($proc, 'Barcode::ZBar::Processor', 'processor'); + +######################### + +can_ok($proc, qw(init set_config parse_config)); + +######################### + +ok(!$proc->parse_config('enable'), 'configuration'); + +######################### + +my $cnt = 0; +my $explicit_closure = 0; + +$proc->set_data_handler(sub { + + ok(!$cnt, 'handler invocations'); + $cnt += 1; + + ######################### + + is($_[0], $proc, 'handler processor'); + + ######################### + + my $image = $_[1]; + isa_ok($image, 'Barcode::ZBar::Image', 'image'); + + ######################### + + my @symbols = $image->get_symbols(); + is(scalar(@symbols), 1, 'result size'); + + ######################### + + my $sym = $symbols[0]; + isa_ok($sym, 'Barcode::ZBar::Symbol', 'symbol'); + + ######################### + + is($sym->get_type(), Barcode::ZBar::Symbol::EAN13, 'result type'); + + ######################### + + is($sym->get_data(), '9876543210128', 'result data'); + + ######################### + + ok($sym->get_quality() > 0, 'quality'); + + ######################### + + my @loc = $sym->get_loc(); + ok(scalar(@loc) >= 4, 'location size'); + + # structure checked by Image.t + + ${$_[2]} += 1 +}, \$explicit_closure); + +######################### + +SKIP: { + skip "no display", 3 unless defined $ENV{'DISPLAY'}; + + $proc->init($ENV{VIDEO_DEVICE}); + ok(!$proc->is_visible(), 'initial visibility'); + + ######################### + + $proc->set_visible(); + ok($proc->is_visible(), 'enabled visiblity'); + + ######################### + + ok($proc->user_wait(1.1) >= 0, 'wait w/timeout'); + + ######################### +} + +SKIP: { + # FIXME factor out image read utility + eval { require Image::Magick }; + skip "Image::Magick not installed", 11 if $@; + my $im = Image::Magick->new(); + my $err = $im->Read('t/barcode.png'); + die($err) if($err); + my $image = Barcode::ZBar::Image->new(); + $image->set_format('422P'); + $image->set_size($im->Get(qw(columns rows))); + $image->set_data($im->ImageToBlob( + magick => 'YUV', + 'sampling-factor' => '4:2:2', + interlace => 'Plane') + ); + +SKIP: { + skip "no display", 11 unless defined $ENV{'DISPLAY'}; + + my $rc = $proc->process_image($image); + ok(!$rc, 'process result'); + + $proc->user_wait(.9); + + ######################### + + is($explicit_closure, 1, 'handler explicit closure'); + } +} + +######################### + +$proc->set_data_handler(); +pass('unset handler'); + +######################### + +# FIXME more processor tests + +$proc = undef; +pass('cleanup'); + +######################### diff --git a/perl/t/Scanner.t b/perl/t/Scanner.t new file mode 100755 index 0000000..99b8942 --- /dev/null +++ b/perl/t/Scanner.t @@ -0,0 +1,23 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Scanner.t' + +use warnings; +use strict; +use Test::More tests => 3; + +######################### + +BEGIN { use_ok('Barcode::ZBar') } + +######################### + +my $scanner = Barcode::ZBar::Scanner->new(); +isa_ok($scanner, 'Barcode::ZBar::Scanner', 'scanner'); + +######################### + +can_ok($scanner, qw(reset new_scan scan_y get_width get_color)); + +######################### + +# FIXME more scanner tests diff --git a/perl/t/ZBar.t b/perl/t/ZBar.t new file mode 100755 index 0000000..0e3a867 --- /dev/null +++ b/perl/t/ZBar.t @@ -0,0 +1,68 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl ZBar.t' + +use warnings; +use strict; +use Test::More tests => 37; + +######################### + +BEGIN { use_ok('Barcode::ZBar') } + +######################### + +like(Barcode::ZBar::version(), qr<\d.\d>, 'version'); + +######################### + +Barcode::ZBar::set_verbosity(16); +Barcode::ZBar::increase_verbosity(); +pass('verbosity'); + +######################### + +# performs (2 * n) tests +sub test_enum { + my $name = shift; + foreach my $test (@_) { + my $enum = $test->[0]; + + is($enum, $test->[1], "$name enum/string compare"); + + ######################### + + ok($enum == $test->[2], "$name enum/numeric compare"); + } +} + +test_enum('config', + [Barcode::ZBar::Config::ENABLE, 'enable', 0], + [Barcode::ZBar::Config::ADD_CHECK, 'add-check', 1], + [Barcode::ZBar::Config::EMIT_CHECK, 'emit-check', 2], + [Barcode::ZBar::Config::ASCII, 'ascii', 3], + [Barcode::ZBar::Config::MIN_LEN, 'min-length', 32], + [Barcode::ZBar::Config::MAX_LEN, 'max-length', 33], + [Barcode::ZBar::Config::UNCERTAINTY, 'uncertainty', 64], + [Barcode::ZBar::Config::POSITION, 'position', 128], + [Barcode::ZBar::Config::X_DENSITY, 'x-density', 256], + [Barcode::ZBar::Config::Y_DENSITY, 'y-density', 257], +); + +######################### + +test_enum('modifier', + [Barcode::ZBar::Modifier::GS1, 'GS1', 0], + [Barcode::ZBar::Modifier::AIM, 'AIM', 1], +); + +######################### + +test_enum('orientation', + [Barcode::ZBar::Orient::UNKNOWN, 'UNKNOWN', -1], + [Barcode::ZBar::Orient::UP, 'UP', 0], + [Barcode::ZBar::Orient::RIGHT, 'RIGHT', 1], + [Barcode::ZBar::Orient::DOWN, 'DOWN', 2], + [Barcode::ZBar::Orient::LEFT, 'LEFT', 3], +); + +######################### diff --git a/perl/t/barcode.png b/perl/t/barcode.png Binary files differnew file mode 100644 index 0000000..72846ce --- /dev/null +++ b/perl/t/barcode.png diff --git a/perl/t/pod-coverage.t b/perl/t/pod-coverage.t new file mode 100644 index 0000000..97c2df8 --- /dev/null +++ b/perl/t/pod-coverage.t @@ -0,0 +1,12 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl pod.t' + +use warnings; +use strict; +use Test::More; + +eval "use Test::Pod::Coverage"; +plan skip_all => "Test::Pod::Coverage required for testing pod coverage" + if $@; + +all_pod_coverage_ok(); diff --git a/perl/t/pod.t b/perl/t/pod.t new file mode 100644 index 0000000..bc0af34 --- /dev/null +++ b/perl/t/pod.t @@ -0,0 +1,12 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl pod.t' + +use warnings; +use strict; +use Test::More; + +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" + if $@; + +all_pod_files_ok(); |