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

Add unitetests for get raw #650

Merged
merged 3 commits into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions UnitTest/tests/test_get_raw-definition.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
defmod test_get_raw UnitTest dummyDuino
(
{
subtest 'Test get raw intertechno switch' => sub {
plan tests => 2;
CommandAttr(undef,"$target dummy 0");
my $rawArg="is10101010101010101010101010101010";
my $ret=SIGNALduino_Get($targetHash, $target, "raw", $rawArg);
like($ret,qr/$rawArg$/,"check return contains correct arg");

$rawArg="is10101010101010101";
$ret=SIGNALduino_Get($targetHash, $target, "raw", $rawArg);
is($ret,undef,"check return is undef");
CommandAttr(undef,"$target dummy 1");

};

subtest 'Test get raw questionmark' => sub {
plan tests => 6;
CommandAttr(undef,"$target dummy 1");
my $rawArg="?";
my $ret=SIGNALduino_Get($targetHash, $target, "raw", $rawArg);
like($ret,qr/^dummy get raw.*/,"check return contains help");
like($ret,qr/raw message.*/,"check return contains raw message");
like($ret,qr/dispatch message.*/,"check return contains dispatch message");
like($ret,qr/version=.*/,"check return version=");
like($ret,qr/regexp=.*/,"check return regexp=");
like($ret,qr/file=.*/,"check return file=");
};

subtest 'Test get raw MS;P1=309;' => sub {
plan tests => 1;
my $mock = Mock::Sub->new;
my $SD_Parse = $mock->mock('SIGNALduino_Parse');
my $rawArg="MS;P1=309;";
my $ret=SIGNALduino_Get($targetHash, $target, "raw", $rawArg);

if ($SD_Parse->called)
{
is( ($SD_Parse->called_with)[3], "\002".$rawArg."\003" , 'check if SIGNALduino_Parse was called' ) || diag(explain $SD_Parse);
}
$SD_Parse->unmock;
};

subtest 'Test get raw file=something.txt;' => sub {
plan tests => 2;

my $rawArg="file=something.txt";
my $ret=SIGNALduino_Get($targetHash, $target, "raw", $rawArg);
like($ret,qr/Could not open file.*/,"Check file not opened");

TODO : {
local $TODO="file must be specified";
my $rawArg="file=./fhem_ut.txt";
my $ret=SIGNALduino_Get($targetHash, $target, "raw", $rawArg);
like($ret,qr/raw Nachrichten eingelesen$/,"Check file not opened");
}
};

}
)