aboutsummaryrefslogtreecommitdiffstats
path: root/t/test.t
blob: a7dd2a73ceec4d5cef13c68c11eb8186ee2bc2ee (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl

use strict;
use warnings;

use English qw(-no_match_vars);
use Test::More;

# each value is an arrayref with 3 elements, indexed by file name:
# - expected output from find_edid_in_string function
# - expected output from parse_edid function
# - expected output from check_parsed_edid function
my %tests = (
    sample1 => [
        [ binary('00ffffffffffff0006af14a10000000001120103901a10780a50c59858528e2725505400000001010101010101010101010101010101ea1a007e502010303020360005a31000001aea1a007e502010303020360005a31000001a000000fe00593734374480423132314557300000000000000000000000000001010a202000a5') ],
         {
            'serial_number' => 0,
            'ratio_precision' => 'mm',
            'feature_support' => {
                'GTF_compliance' => 0,
                'sRGB_compliance' => 0,
                'rgb' => 0,
                'DPMS_suspend' => 0,
                'has_preferred_timing' => 1,
                'DPMS_active_off' => 0,
                'DPMS_standby' => 0
            },
            'checksum' => 165,
            'video_input_definition' => {
                'voltage_level' => 0,
                'digital' => 1,
                'composite_sync' => 0,
                'separate_sync' => 0,
                'sync_on_green' => 1
            },
            'established_timings' => [],
            'max_size_precision' => 'mm',
            'product_code' => 41236,
            'ratio' => '1.60122699386503',
            'standard_timings' => [],
            'monitor_details' => '',
            'week' => 1,
            'monitor_text' => [
                "Y747D\x80B121EW0"
            ],
            'detailed_timings' => [
                {
                    'vertical_dpi' => '124.662576687117',
                    'vertical_sync_offset' => 3,
                    'pixel_clock' => '68.9',
                    'horizontal_border' => 0,
                    'stereo' => 0,
                    'interlaced' => 0,
                    'horizontal_blanking' => 126,
                    'digital_composite' => 3,
                    'vertical_sync_pulse_width' => 6,
                    'horizontal_active' => 1280,
                    'vertical_sync_positive' => 1,
                    'horizontal_sync_pulse_width' => 32,
                    'horizontal_dpi' => '124.567049808429',
                    'horizontal_sync_positive' => 0,
                    'vertical_border' => 0,
                    'preferred' => 1,
                    'horizontal_sync_offset' => 48,
                    'ModeLine' => '"1280x800" 68.9 1280 1328 1360 1406 800 803 809 816 -hsync +vsync',
                    'vertical_image_size' => 163,
                    'horizontal_image_size' => 261,
                    'ModeLine_comment' => '# Monitor preferred modeline (60.1 Hz vsync, 49.0 kHz hsync, ratio 16/10, 124 dpi)',
                    'vertical_blanking' => 16,
                    'vertical_active' => 800
                },
                {
                    'vertical_dpi' => '124.662576687117',
                    'vertical_sync_offset' => 3,
                    'pixel_clock' => '68.9',
                    'horizontal_border' => 0,
                    'stereo' => 0,
                    'interlaced' => 0,
                    'horizontal_blanking' => 126,
                    'digital_composite' => 3,
                    'vertical_sync_pulse_width' => 6,
                    'horizontal_active' => 1280,
                    'vertical_sync_positive' => 1,
                    'horizontal_sync_pulse_width' => 32,
                    'horizontal_dpi' => '124.567049808429',
                    'horizontal_sync_positive' => 0,
                    'vertical_border' => 0,
                    'horizontal_sync_offset' => 48,
                    'ModeLine' => '"1280x800" 68.9 1280 1328 1360 1406 800 803 809 816 -hsync +vsync',
                    'vertical_image_size' => 163,
                    'horizontal_image_size' => 261,
                    'ModeLine_comment' => '# Monitor supported modeline (60.1 Hz vsync, 49.0 kHz hsync, ratio 16/10, 124 dpi)',
                    'vertical_blanking' => 16,
                    'vertical_active' => 800
                }
            ],
            'extension_flag' => 0,
            'gamma' => 120,
            'diagonal_size' => '12.1148583788498',
            'ratio_name' => '16/10',
            'edid_revision' => 3,
            'EISA_ID' => 'AUOa114',
            'max_size_horizontal' => '26.1',
            'max_size_vertical' => '16.3',
            'edid_version' => 1,
            'year' => 2008,
            'manufacturer_name' => 'AUO'
        },
        ''
    ]
);

plan tests => 1 + (3 * scalar keys %tests);

use_ok('Parse::EDID');

foreach my $test (keys %tests) {
    my $string = read_file("t/$test");

    my @edids = find_edid_in_string($string);
    is_deeply(
        \@edids,
        $tests{$test}->[0],
        "$test: edid extraction"
    );

    my $edid = parse_edid($edids[0]);
    is_deeply(
        $edid,
        $tests{$test}->[1],
        "$test: edid parsing"
    );

    my $message = check_parsed_edid($edid);
    is(
        $message,
        $tests{$test}->[2],
        "$test: edid checking"
    );
}

sub read_file {
    my ($file) = @_;
    local $RS;
    open (my $handle, '<', $file) or die "Can't open $file: $ERRNO";
    my $content = <$handle>;
    close $handle;
    return $content;
}

sub binary {
    my ($string) = @_;
    return pack("C*", map { hex($_) } $string =~ /(..)/g);
}