File: complete-interface.t

package info (click to toggle)
libfile-libmagic-perl 1.02-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 524 kB
  • ctags: 849
  • sloc: perl: 1,616; pascal: 88; ansic: 54; makefile: 13
file content (80 lines) | stat: -rw-r--r-- 2,184 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use strict;
use warnings;

use lib 't/lib';

use Test::AnyOf;
use Test::More 0.88;

use File::LibMagic qw( :complete );

# check for constants
my $fail  = 0;
my @names = qw(
    MAGIC_CHECK MAGIC_COMPRESS MAGIC_CONTINUE MAGIC_DEBUG MAGIC_DEVICES
    MAGIC_ERROR MAGIC_MIME MAGIC_NONE MAGIC_PRESERVE_ATIME MAGIC_RAW
    MAGIC_SYMLINK
);
foreach my $constname (@names) {
    next if ( eval "my \$a = $constname; 1" );
    if ( $@ =~ /^Your vendor has not defined constants macro $constname/ ) {
        diag "pass: $@";
    }
    else {
        diag "fail: $@";
        $fail = 1;
    }

}
ok( $fail == 0, 'Constants' );

# try loading a non-standard magic file
{
    my $handle = magic_open(MAGIC_NONE);
    magic_load( $handle, 't/samples/magic' );
    is( magic_buffer( $handle, "Hello World\n" ), 'ASCII text' );
    is( magic_buffer( $handle, "Footastic\n" ),   'A foo file' );

    is( magic_file( $handle, 't/samples/foo.txt' ), 'ASCII text' );
    is_any_of(
        magic_file( $handle, 't/samples/foo.c' ),
        [ 'ASCII text', 'ASCII C program text', 'C source, ASCII text' ]
    );
    is( magic_file( $handle, 't/samples/foo.foo' ), 'A foo file' );

    magic_close($handle);
}

# test the traditional empty string for magic_load
{
    my $handle = magic_open(MAGIC_NONE);
    magic_load( $handle, q{} );
    is( magic_buffer( $handle, "Hello World\n" ), 'ASCII text' );

    is( magic_file( $handle, 't/samples/foo.txt' ), 'ASCII text' );
    is_any_of(
        magic_file( $handle, 't/samples/foo.c' ),
        [ 'ASCII C program text', 'C source, ASCII text' ]
    );
    is( magic_file( $handle, 't/samples/foo.foo' ), 'ASCII text' );

    magic_close($handle);
}

# test undef as the filename for magic_load
{
    my $handle = magic_open(MAGIC_NONE);
    magic_load( $handle, undef );
    is( magic_buffer( $handle, "Hello World\n" ), 'ASCII text' );

    is( magic_file( $handle, 't/samples/foo.txt' ), 'ASCII text' );
    is_any_of(
        magic_file( $handle, 't/samples/foo.c' ),
        [ 'ASCII C program text', 'C source, ASCII text' ]
    );
    is( magic_file( $handle, 't/samples/foo.foo' ), 'ASCII text' );

    magic_close($handle);
}

done_testing();