File: xbm-badfile.t

package info (click to toggle)
libimage-base-bundle-perl 2%2B~1.17%2B~1.13%2B~1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: perl: 2,302; makefile: 44
file content (47 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl -w
# -*- cperl -*-

# Copyright (C) 2016 Slaven Rezic. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

use strict;
use File::Temp qw(tempfile);
use Test::More 'no_plan';

use Image::Xbm;

for my $tempfile_template (
			   'image-xbm-0x00-XXXXXXXX', # filename contains valid hex value, causing extra wrong bits
			   'image-xbm-file with spaces-XXXXXXXX', # spaces are properly transliterated
			   'image-xbm-file^-with-^special-XXXXXXXX', # other special characters are properly transliterated
			  ) {
    my(undef, $fp) = tempfile($tempfile_template, SUFFIX => '.xbm', UNLINK => 1);
    my $i1 = Image::Xbm->new_from_string("#####\n#---#\n-###-\n--#--\n--#--\n#####");
    $i1->save($fp);

    my($width_name, $height_name, $bits_name);
    {
	open my $fh, '<', $fp
	    or die $!;
	while(<$fh>) {
	    if      (/^#define\s+(.*_width)\s+5$/) {
		$width_name = $1;
	    } elsif (/^#define\s+(.*_height)\s+6$/) {
		$height_name = $1;
	    } elsif (/^static\s+unsigned\s+char\s+(.*_bits)\[\]\s+=\s+\{$/) {
		$bits_name = $1;
	    }
	}
    }
    like $width_name, qr{^image_xbm_[A-Za-z0-9_]+_width}, 'width define without strange characters';
    like $height_name, qr{^image_xbm_[A-Za-z0-9_]+_height}, 'height define without strange characters';
    like $bits_name, qr{^image_xbm_[A-Za-z0-9_]+_bits}, 'bits variable without strange characters';

    my $i2 = Image::Xbm->new(-file => $fp);
    is $i2->as_binstring, $i1->as_binstring, "loaded image from file has same bits (tempfile template: $tempfile_template)";

    unlink $fp;
}

__END__