From 7b533be0f01ac4e8bd740054312d8f681ef3d1c7 Mon Sep 17 00:00:00 2001 From: HomeAutoUser Date: Fri, 1 Nov 2019 16:42:07 +0100 Subject: [PATCH 1/4] Update test_DeviceData_rmsg-definition.txt - adaptation test for JSON --- .../tests/test_DeviceData_rmsg-definition.txt | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/UnitTest/tests/test_DeviceData_rmsg-definition.txt b/UnitTest/tests/test_DeviceData_rmsg-definition.txt index 257ef88a8..201bf331f 100644 --- a/UnitTest/tests/test_DeviceData_rmsg-definition.txt +++ b/UnitTest/tests/test_DeviceData_rmsg-definition.txt @@ -61,18 +61,23 @@ defmod test_DeviceData_rmsg UnitTest dummyDuino ( $dmsg_matched=0; $SD_Dispatch_calledCounter=0; SIGNALduino_Parse($targetHash, $targetHash, $targetHash->{NAME}, "\002".$tData->{rmsg}."\003") if (defined($tData->{rmsg})); - if ($SD_Dispatch->called() >0 ) { - $noTestRun=0; - my $expected_repeat=min(4,$tData->{repeat}+1); - - TODO: { - local $TODO = "Checking for repeats is not finishes, because number of repeats is not always number of dispatches"; - is($SD_Dispatch_calledCounter, $expected_repeat, "check number of dispatch attempts") if (defined($tData->{repeat})); - }; - - ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); - ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); - + if ($SD_Dispatch->called() >0 ) { + $noTestRun=0; + + ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); + ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); + + if (defined($tData->{dispatch_repeats})) { + ok( $tData->{dispatch_repeats} , "JSON dispatch_repeats entry available"); + ## some tests please added in separate Travistest on SIGNALduino_TOOL ## + ok( $tData->{dispatch_repeats} =~ /\d+/ , "JSON dispatch_repeats entry check numeric"); + } + + my $expected_repeat=min(1,$tData->{dispatch_repeats}); + TODO: { + local $TODO = "Checking dispatches (all dispatches are counted across all modules)"; + is($tData->{dispatch_repeats}, $SD_Dispatch_calledCounter-1, "JSON dispatch_repeats accuracy") if (defined($tData->{dispatch_repeats})); + }; } else { diag "SIGNALduno_Dispatch was not called, this must be an error"; } }; From d3bb46ea47e113631b48d6901ff3347b00ce650d Mon Sep 17 00:00:00 2001 From: HomeAutoUser Date: Wed, 6 Nov 2019 19:45:34 +0100 Subject: [PATCH 2/4] Update test_DeviceData_rmsg-definition.txt - remove test https://github.com/RFD-FHEM/RFFHEM/pull/677#pullrequestreview-312005052 --- UnitTest/tests/test_DeviceData_rmsg-definition.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/UnitTest/tests/test_DeviceData_rmsg-definition.txt b/UnitTest/tests/test_DeviceData_rmsg-definition.txt index 201bf331f..c9632acb1 100644 --- a/UnitTest/tests/test_DeviceData_rmsg-definition.txt +++ b/UnitTest/tests/test_DeviceData_rmsg-definition.txt @@ -67,12 +67,6 @@ defmod test_DeviceData_rmsg UnitTest dummyDuino ( ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); - if (defined($tData->{dispatch_repeats})) { - ok( $tData->{dispatch_repeats} , "JSON dispatch_repeats entry available"); - ## some tests please added in separate Travistest on SIGNALduino_TOOL ## - ok( $tData->{dispatch_repeats} =~ /\d+/ , "JSON dispatch_repeats entry check numeric"); - } - my $expected_repeat=min(1,$tData->{dispatch_repeats}); TODO: { local $TODO = "Checking dispatches (all dispatches are counted across all modules)"; From defe475fbce73e6c3935672eb9c515133bb6412c Mon Sep 17 00:00:00 2001 From: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Sun, 10 Nov 2019 11:03:12 +0100 Subject: [PATCH 3/4] Get maxMuMsgRepeat via attrVal to specify min number of repeats --- .../tests/test_DeviceData_rmsg-definition.txt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/UnitTest/tests/test_DeviceData_rmsg-definition.txt b/UnitTest/tests/test_DeviceData_rmsg-definition.txt index c9632acb1..548b96eef 100644 --- a/UnitTest/tests/test_DeviceData_rmsg-definition.txt +++ b/UnitTest/tests/test_DeviceData_rmsg-definition.txt @@ -61,18 +61,18 @@ defmod test_DeviceData_rmsg UnitTest dummyDuino ( $dmsg_matched=0; $SD_Dispatch_calledCounter=0; SIGNALduino_Parse($targetHash, $targetHash, $targetHash->{NAME}, "\002".$tData->{rmsg}."\003") if (defined($tData->{rmsg})); - if ($SD_Dispatch->called() >0 ) { - $noTestRun=0; + if ($SD_Dispatch->called() >0 ) { + $noTestRun=0; - ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); - ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); + ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); + ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); - my $expected_repeat=min(1,$tData->{dispatch_repeats}); - TODO: { - local $TODO = "Checking dispatches (all dispatches are counted across all modules)"; - is($tData->{dispatch_repeats}, $SD_Dispatch_calledCounter-1, "JSON dispatch_repeats accuracy") if (defined($tData->{dispatch_repeats})); - }; - } else { diag "SIGNALduno_Dispatch was not called, this must be an error"; } + my $expected_repeat=min(AttrVal($target,"maxMuMsgRepeat",4),$tData->{dispatch_repeats}); + TODO: { + local $TODO = "Checking dispatches (all dispatches are counted across all modules)"; + is($tData->{dispatch_repeats}, $SD_Dispatch_calledCounter-1, "JSON dispatch_repeats accuracy") if (defined($tData->{dispatch_repeats})); + }; + } else { diag "SIGNALduno_Dispatch was not called, this must be an error"; } }; } From a3e829c5b004abd4b5c572ef7c9ed3056426408c Mon Sep 17 00:00:00 2001 From: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Sun, 10 Nov 2019 11:22:54 +0100 Subject: [PATCH 4/4] Test pre-release / SD_Device_ProtocolList Added addinal non failing todo subtest for SD_Device_ProtocolList in pre-release to see if new entrys rise errors --- .../tests/test_DeviceData_rmsg-definition.txt | 143 ++++++++++++------ 1 file changed, 95 insertions(+), 48 deletions(-) diff --git a/UnitTest/tests/test_DeviceData_rmsg-definition.txt b/UnitTest/tests/test_DeviceData_rmsg-definition.txt index 548b96eef..b38474a69 100644 --- a/UnitTest/tests/test_DeviceData_rmsg-definition.txt +++ b/UnitTest/tests/test_DeviceData_rmsg-definition.txt @@ -5,27 +5,13 @@ defmod test_DeviceData_rmsg UnitTest dummyDuino ( use JSON; use List::Util qw[min max]; - - my $jsonStr = GetFileFromURL("https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/master/FHEM/lib/SD_Device_ProtocolList.json",4,"",1,4); - my $testDataArray; - $testDataArray = eval { decode_json($jsonStr) }; - - if($@){ - diag("open json file SD_Device_ProtocolList was not possible $?"); - diag explain $jsonStr; - } - my $testSet; - my $pID; - + my $testDataArray; my $tData; - my $tID; - my $id_matched=undef; my $dmsg_matched=undef; my $SD_Dispatch_calledCounter=undef; - - my $SD_Dispatch = $mock->mock("SIGNALduno_Dispatch"); + sub VerifyDispatch { #Log3 "Testdev", 5, "rmsg=".$_[1]." DMSG=".$_[2]; if (defined($testSet->{id}) && !$id_matched && $_[4] eq $testSet->{id}) @@ -41,43 +27,104 @@ defmod test_DeviceData_rmsg UnitTest dummyDuino ( undef; } - my $noTestRun=1; - use lib::SD_Protocols; - #my $SD_Protos = lib::SD_Protocols::new("$attr{global}{modpath}/FHEM/lib/SD_ProtocolData.pm"); - while ( ($pID, $testSet) = each (@{$testDataArray}) ) + sub loadJson { - #next if ($testSet->{name} ne "NC-3911-675" ); - next if (!lib::SD_Protocols::exists($testSet->{id})); - next if (lib::SD_Protocols::checkProperty($testSet->{id},'developId',undef)); - while ( ($tID, $tData) = each (@{$testSet->{data}}) ) - { - next if (!defined($tData->{rmsg}) || !defined($tData->{dmsg}) || !defined($tData->{internals}) ); + my $jsonStr=GetFileFromURL($_[0],4,"",1,4); + $testDataArray = eval { decode_json($jsonStr) }; + if($@){ + diag("open json file SD_Device_ProtocolList was not possible $?"); + diag explain $jsonStr; + } + + } + subtest 'Test with pre-release SD_Device_ProtocolList' => sub { + TODO: { + local $TODO = "Checking with prerelease Version of SD_Device_ProtocolList which can fail"; + + loadJson("https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/pre-release/FHEM/lib/SD_Device_ProtocolList.json"); + + my $pID; + my $tID; - subtest "[$pID]: $testSet->{name}: [$tID] " => sub { - $SD_Dispatch->reset(); - $SD_Dispatch->side_effect(\&VerifyDispatch); - #SIGNALduino_Log3 $target, 5, Dumper($tData); - $id_matched=0; - $dmsg_matched=0; - $SD_Dispatch_calledCounter=0; - SIGNALduino_Parse($targetHash, $targetHash, $targetHash->{NAME}, "\002".$tData->{rmsg}."\003") if (defined($tData->{rmsg})); - if ($SD_Dispatch->called() >0 ) { - $noTestRun=0; + my $SD_Dispatch = $mock->mock("SIGNALduno_Dispatch"); + my $noTestRun=1; + use lib::SD_Protocols; + while ( ($pID, $testSet) = each (@{$testDataArray}) ) + { + next if (!lib::SD_Protocols::exists($testSet->{id})); + while ( ($tID, $tData) = each (@{$testSet->{data}}) ) + { + next if (!defined($tData->{rmsg}) || !defined($tData->{dmsg}) || !defined($tData->{internals}) ); + + subtest "[$pID]: $testSet->{name}: [$tID] " => sub { + $SD_Dispatch->reset(); + $SD_Dispatch->side_effect(\&VerifyDispatch); + $id_matched=0; + $dmsg_matched=0; + $SD_Dispatch_calledCounter=0; + SIGNALduino_Parse($targetHash, $targetHash, $targetHash->{NAME}, "\002".$tData->{rmsg}."\003") if (defined($tData->{rmsg})); + if ($SD_Dispatch->called() >0 ) { + $noTestRun=0; + + ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); + ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); + + my $expected_repeat=min(AttrVal($target,"maxMuMsgRepeat",4),$tData->{dispatch_repeats}); + is($tData->{dispatch_repeats}, $SD_Dispatch_calledCounter-1, "JSON dispatch_repeats accuracy") if (defined($tData->{dispatch_repeats})); + } else { diag "SIGNALduno_Dispatch was not called, this must be an error"; } + }; + } + }; + is($noTestRun,0,"Verify if a test was performed "); + $SD_Dispatch->unmock; + }; + + }; - ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); - ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); + subtest 'Test with master SD_Device_ProtocolList' => sub { + loadJson("https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/master/FHEM/lib/SD_Device_ProtocolList.json"); - my $expected_repeat=min(AttrVal($target,"maxMuMsgRepeat",4),$tData->{dispatch_repeats}); - TODO: { - local $TODO = "Checking dispatches (all dispatches are counted across all modules)"; - is($tData->{dispatch_repeats}, $SD_Dispatch_calledCounter-1, "JSON dispatch_repeats accuracy") if (defined($tData->{dispatch_repeats})); - }; + my $pID; + my $tID; + + my $SD_Dispatch = $mock->mock("SIGNALduno_Dispatch"); + my $noTestRun=1; + use lib::SD_Protocols; + while ( ($pID, $testSet) = each (@{$testDataArray}) ) + { + #next if ($testSet->{name} ne "NC-3911-675" ); + next if (!lib::SD_Protocols::exists($testSet->{id})); + next if (lib::SD_Protocols::checkProperty($testSet->{id},'developId',undef)); + while ( ($tID, $tData) = each (@{$testSet->{data}}) ) + { + next if (!defined($tData->{rmsg}) || !defined($tData->{dmsg}) || !defined($tData->{internals}) ); + + subtest "[$pID]: $testSet->{name}: [$tID] " => sub { + $SD_Dispatch->reset(); + $SD_Dispatch->side_effect(\&VerifyDispatch); + #SIGNALduino_Log3 $target, 5, Dumper($tData); + $id_matched=0; + $dmsg_matched=0; + $SD_Dispatch_calledCounter=0; + SIGNALduino_Parse($targetHash, $targetHash, $targetHash->{NAME}, "\002".$tData->{rmsg}."\003") if (defined($tData->{rmsg})); + if ($SD_Dispatch->called() >0 ) { + $noTestRun=0; + + ok($id_matched,"SIGNALduno_Dispatch check id ") || note explain (($SD_Dispatch->called_with())[4] , " vs ", $testSet->{id}); + ok($dmsg_matched,"SIGNALduno_Dispatch check dmsg ") || note explain (($SD_Dispatch->called_with())[2] , " vs ", $testSet->{dmsg}); + + my $expected_repeat=min(AttrVal($target,"maxMuMsgRepeat",4),$tData->{dispatch_repeats}); + TODO: { + local $TODO = "Checking dispatches (all dispatches are counted across all modules)"; + is($tData->{dispatch_repeats}, $SD_Dispatch_calledCounter-1, "JSON dispatch_repeats accuracy") if (defined($tData->{dispatch_repeats})); + }; } else { diag "SIGNALduno_Dispatch was not called, this must be an error"; } - }; + }; + } + }; + is($noTestRun,0,"Verify if a test was performed "); + $SD_Dispatch->unmock; + }; - } - }; - is($noTestRun,0,"Verify if a test was performed "); - $SD_Dispatch->unmock; } );