Skip to content

Commit

Permalink
Extend subtest verify_sound_image (t/17-basetest.t)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Nov 25, 2022
1 parent 4932a78 commit 8f93400
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions basetest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Create a media fragment time from a given framenumber
=cut

sub _framenumber_to_timerange ($frame) {
return [sprintf("%.2f", $frame / 24.0), sprintf("%.2f", ($frame + 1) / 24.0)];
return defined($frame) ? [sprintf("%.2f", $frame / 24.0), sprintf("%.2f", ($frame + 1) / 24.0)] : undef;
}

sub record_screenmatch ($self, $img, $match, $tags = [], $failed_needles = [], $frame = undef) {
Expand All @@ -139,7 +139,7 @@ sub record_screenmatch ($self, $img, $match, $tags = [], $failed_needles = [], $
json => $serialized_match->{json},
tags => [@$tags], # make a copy
properties => [@$properties], # make a copy
frametime => defined($frame) ? _framenumber_to_timerange($frame) : undef,
frametime => _framenumber_to_timerange($frame),
screenshot => $self->next_resultname('png'),
result => 'ok',
};
Expand Down
14 changes: 13 additions & 1 deletion t/17-basetest.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $autotest::isotovideo = 1;

my $last_screenshot_data;
my $fake_ignore_failure;
my $suppress_match;
my @reset_consoles;
my @selected_consoles;
sub fake_send_json ($to_fd, $cmd) { push(@$cmds, $cmd) }
Expand All @@ -52,7 +53,8 @@ sub fake_read_json ($fd) {
};
}
elsif ($cmd eq 'backend_verify_image') {
return {ret => {found => {needle => {name => 'foundneedle', file => 'foundneedle.json'}, area => [{x => 1, y => 2, similarity => 100}]}, candidates => []}};
return {ret => {found => {needle => {name => 'foundneedle', file => 'foundneedle.json'}, area => [{x => 1, y => 2, similarity => 100}]}, candidates => []}} unless $suppress_match;
return {};
}
elsif ($cmd eq 'last_milestone_console') {
return {};
Expand Down Expand Up @@ -497,6 +499,16 @@ subtest verify_sound_image => sub {
is_deeply($res->{area}, [{x => 1, y => 2, similarity => 100}], 'area was returned') or diag explain $res->{area};
is($res->{needle}->{file}, 'foundneedle.json', 'needle file was returned');
is($res->{needle}->{name}, 'foundneedle', 'needle name was returned');
$suppress_match = 'yes';
my $details;
my $mock_test = Test::MockModule->new('basetest');
$mock_test->mock(record_screenfail => sub { my ($self, %args) = @_; $details = \%args; });
$res = $test->verify_sound_image("$FindBin::Bin/data/frame1.ppm", "$FindBin::Bin/data/frame2.ppm", 1);
is($res, undef, 'res is undef as expected') or diag explain $res;
is($details->{result}, 'unk', 'no needle match: unknown status correct') or diag explain $details;
$res = $test->verify_sound_image("$FindBin::Bin/data/frame1.ppm", "$FindBin::Bin/data/frame2.ppm", 0);
is($details->{result}, 'fail', 'no needle match: status fail') or diag explain $details;
is($details->{overall}, 'fail', 'no needle match: overall fail') or diag explain $details;
};

subtest rollback_activated_consoles => sub {
Expand Down

0 comments on commit 8f93400

Please sign in to comment.