Skip to content

Commit

Permalink
t\FHEM\00_SIGNALduino\99_SIGNALduino_AsyncOutput.t
Browse files Browse the repository at this point in the history
Added test to analyse bug #870
  • Loading branch information
sidey79 committed Oct 9, 2020
1 parent a065ad3 commit 76db076
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions t/FHEM/00_SIGNALduino/99_SIGNALduino_AsyncOutput.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env perl
use strict;
use warnings;

use Test::Device::SerialPort;
use Test2::V0;
use Test2::Tools::Compare qw{is field U D match hash bag };
use Test2::Todo;
use Test2::Mock;
use Data::Dumper;

# Mock cc1101
my $PortObj = Test::Device::SerialPort->new('/dev/ttyS0');
$defs{cc1101dummyDuino}{USBDev} = $PortObj;

my ($mock);


BEGIN {

};

InternalTimer(time()+1, sub() {


$mock = Test2::Mock->new(
class => 'main',
track => 1, # enable call tracking if desired
override => [
asyncOutput => sub { return ; },
],
);


subtest "Checking read async output without eventlogging" => sub {
plan (1);

$PortObj->{'_fake_input'} = '990'."\n";
$defs{cc1101dummyDuino}{ucCmd}{asyncOut} = 'dummyCL';
$defs{cc1101dummyDuino}{ucCmd}{cmd} = 'freeram';
$defs{cc1101dummyDuino}{ucCmd}{responseSub} = \&SIGNALduino_GetResponseUpdateReading;
$defs{cc1101dummyDuino}{ucCmd}{timenow} = time();

SIGNALduino_Read($defs{cc1101dummyDuino});

my $tracking = $mock->sub_tracking;
my $args = $tracking->{asyncOutput}[0]{args};

#print Dumper($tracking);
delete $tracking->{asyncOutput} ;

is ($args,array {
item 0 => 'dummyCL' ;
item 1 => 'freeram: 990';
},
'verify called args asyncOutput');
};

subtest "Checking read async output with eventlogging" => sub {
plan (1);

$PortObj->{'_fake_input'} = '990'."\n";
SIGNALduino_Attr('set',$defs{cc1101dummyDuino}{NAME},'eventlogging',1);

$defs{cc1101dummyDuino}{ucCmd}{asyncOut} = 'dummyCL';
$defs{cc1101dummyDuino}{ucCmd}{cmd} = 'freeram';
$defs{cc1101dummyDuino}{ucCmd}{responseSub} = \&SIGNALduino_GetResponseUpdateReading;
$defs{cc1101dummyDuino}{ucCmd}{timenow} = time();
DoTrigger($defs{cc1101dummyDuino}, 'dummyEvent', 0);

SIGNALduino_Read($defs{cc1101dummyDuino});

my $tracking = $mock->sub_tracking;
my $args = $tracking->{asyncOutput}[0]{args};

print Dumper($tracking);
delete $tracking->{asyncOutput} ;

is ($args,array {
item 0 => 'dummyCL' ;
item 1 => 'freeram: 990';
},
'verify called args asyncOutput');
};


done_testing();
$mock->restore('asyncOutput');
exit(0);

}, 0);

1;

0 comments on commit 76db076

Please sign in to comment.