-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
t\FHEM\00_SIGNALduino\99_SIGNALduino_AsyncOutput.t
Added test to analyse bug #870
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |