Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further extend basetest.pm code coverage #2215

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
35 changes: 34 additions & 1 deletion t/17-basetest.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ $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) }
sub fake_read_json ($fd) {
my $lcmd = $cmds->[-1];
Expand All @@ -50,11 +53,20 @@ 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 {};
}
elsif ($cmd eq 'backend_reset_console') {
push @reset_consoles, $lcmd;
return {};
}
elsif ($cmd eq 'backend_select_console') {
push @selected_consoles, $lcmd;
return {};
}
elsif ($cmd eq 'backend_stop_audiocapture') {
return {};
}
Expand Down Expand Up @@ -297,6 +309,7 @@ subtest record_screenmatch => sub {
needle => {
name => 'foo',
file => 'some/path/foo.json',
unregistered => 'yes',
},
);
my @tags = (qw(some tags));
Expand Down Expand Up @@ -486,6 +499,26 @@ 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 {
my $test = basetest->new();
$test->{activated_consoles} = ['activated_console'];
$autotest::last_milestone_console = 'last_milestone_console';
$test->rollback_activated_consoles;
is_deeply($test->{activated_consoles}, [], 'activated consoles cleared') or diag explain $test->{activated_consoles};
is_deeply(\@reset_consoles, [{cmd => 'backend_reset_console', testapi_console => 'activated_console'}], 'activated consoles reset') or diag explain \@reset_consoles;
is_deeply(\@selected_consoles, [{cmd => 'backend_select_console', testapi_console => 'last_milestone_console'}], 'last milestone console selected') or diag explain \@selected_consoles;
};

done_testing;