2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

98_HTTPMOD: updated tests for HTTPMOD and its utils

git-svn-id: https://svn.fhem.de/fhem/trunk@23444 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2020-12-31 13:52:24 +00:00
parent 421616ff2d
commit a67305eb17
2 changed files with 25 additions and 6 deletions

View File

@ -21,7 +21,7 @@ $modVersion =~ /^([0-9]+)\./;
my $major = $1;
if ($major && $major >= 4) {
plan tests => 13;
plan tests => 14;
} else {
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
}
@ -47,6 +47,16 @@ is(FhemTestUtils_gotLog(qr/H2: reading20Regex Regex: Bad regexp/), 2, "validatio
fhem('set H3 reread');
is(FhemTestUtils_gotEvent(qr/H3:TestReading:\s466/xms), 1, "preProcessRegex");
FhemTestUtils_resetEvents();
FhemTestUtils_resetLogs();
fhem('attr H1 reading01DeleteIfUnmatched 1');
fhem('attr H1 reading01Regex \"SampleColor\",\"([^\"]+)\"');
fhem('set H1 reread');
is(FhemTestUtils_gotLog('delete reading TestReading1'), 1, "DeleteIfUnmatched");
fhem('set H4 reread');
InternalTimer(time()+1, sub() {

View File

@ -1,5 +1,5 @@
##############################################
# test evalExpr Util function
# test evalExpr and other Util functions
##############################################
use strict;
use warnings;
@ -14,22 +14,31 @@ my @array = (1,2,3);
my %tHash = (a => 10, b => 20);
my $exp = '$val * 2';
my $result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array});
my $result = EvalExpr($hash, {expr => $exp, '$val' => $val, '@array' => \@array});
#Log3 $name, 3, "$name: result of EvalExpr test 1 = $result";
is $result, 10, "simple expression with one scalar in list";
$exp = '$array[1] * 2';
$result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array});
$result = EvalExpr($hash, {expr => $exp, '$val' => $val, '@array' => \@array});
is $result, 4, "simple expression with array ref in hash";
$exp = '$hash{a} * 2';
$result = EvalExpr($hash, $exp, {'$val' => $val, '%hash' => \%tHash});
$result = EvalExpr($hash, {expr => $exp, '$val' => $val, '%hash' => \%tHash});
is $result, 20, "simple expression with hash ref in hash";
$exp = '$hash->{a} * 2';
$result = EvalExpr($hash, $exp, {'$val' => $val, '$hash' => \%tHash});
$result = EvalExpr($hash, {expr => $exp, '$val' => $val, '$hash' => \%tHash});
is $result, 20, "simple expression with hash ref as ref in hash";
my $format = '';
$val = undef;
$result = FormatVal($hash, {val => $val, format => $format});
is $result, undef, "FormatVal with empty format and undef value";
$format = '%.2f';
$result = FormatVal($hash, {val => $val, format => $format});
is $result, "0.00", "FormatVal with empty format and undef value";
done_testing;
exit(0);