File: leak-check.t

package info (click to toggle)
libmaxmind-db-reader-xs-perl 1.000007-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,784 kB
  • sloc: perl: 3,202; ansic: 260; makefile: 3; sh: 2
file content (53 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::LeakTrace;
use Test::More 0.88;

use MaxMind::DB::Reader 0.050000;

my $reader = MaxMind::DB::Reader->new(
    file => 'maxmind-db/test-data/MaxMind-DB-test-ipv4-24.mmdb' );

{
    my ( $orig, $ref_to_orig, $copy_of_orig );
    no_leaks_ok {
        ( $orig, $ref_to_orig, $copy_of_orig ) = get_record();
    }
    'no leaks when getting a record';

    is_deeply(
        $orig,
        { ip => '1.1.1.1' },
        'got expected data in record'
    );

    is_deeply(
        $ref_to_orig->{ref},
        { ip => '1.1.1.1' },
        'got expected data in ref to record'
    );

    is_deeply(
        $copy_of_orig->{copy},
        { ip => '1.1.1.1' },
        'got expected data in copy of record'
    );

    no_leaks_ok {
        undef $reader;
    }
    'no leaks when destroying reader object';
}

done_testing();

sub get_record {
    my $orig = $reader->record_for_address('1.1.1.1');

    return (
        $orig,
        { ref  => $orig },
        { copy => { %{$orig} } },
    );
}