From 49032447f3d5c5ce3d37d392da92b163640ce323 Mon Sep 17 00:00:00 2001 From: StefanStrobel <> Date: Sat, 13 Mar 2021 10:07:19 +0000 Subject: [PATCH] 98_HTTPMOD: update Tests git-svn-id: https://svn.fhem.de/fhem/trunk@23941 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg | 18 ++++++++ fhem/t/FHEM/98_HTTPMOD/12_Chains.t | 40 ++++++++++++++++ fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg | 8 ++++ fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t | 21 ++++++++- fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 | 14 ++++++ fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 | 48 ++++++++++++++++++++ 6 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg create mode 100644 fhem/t/FHEM/98_HTTPMOD/12_Chains.t create mode 100644 fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 create mode 100644 fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 diff --git a/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg b/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg new file mode 100644 index 000000000..f5aaa4e1d --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg @@ -0,0 +1,18 @@ +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 +attr H1 verbose 5 +attr H1 fileHeaderSplit --end-of-http-header-- +attr H1 queueDelay 0 +attr H1 minSendDelay 0 + +attr H1 get01Name O1 +attr H1 get01Regex
(.*)
+attr H1 get01FollowGet O2 + +attr H1 get02Name O2 +attr H1 get02Regex +attr H1 get02FollowGet O3 + +attr H1 get03Name O3 +attr H1 get03Regex + +attr H1 maxGetChain 5 diff --git a/fhem/t/FHEM/98_HTTPMOD/12_Chains.t b/fhem/t/FHEM/98_HTTPMOD/12_Chains.t new file mode 100644 index 000000000..e452fa285 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/12_Chains.t @@ -0,0 +1,40 @@ +############################################## +# test cookies +############################################## +use strict; +use warnings; +use Test::More; +#use Data::Dumper; + +my $hash = $defs{'H1'}; +my $modVersion = $hash->{ModuleVersion}; +$modVersion =~ /^([0-9]+)\./; +my $major = $1; + +if ($major && $major >= 4) { + plan tests => 7; +} else { + plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; +} + +fhem 'get H1 O1'; + +is(FhemTestUtils_gotEvent("O1:

Test

"), 1, "got O1"); +is(FhemTestUtils_gotEvent("O2: ter>"), 1, "got O2"); +is(FhemTestUtils_gotEvent("O3: enter>"), 1, "got O3"); + +fhem 'attr H1 maxGetChain 1'; +FhemTestUtils_resetLogs(); +FhemTestUtils_resetEvents(); + +fhem 'get H1 O1'; + +is(FhemTestUtils_gotEvent("O1:

Test

"), 1, "got O1"); +is(FhemTestUtils_gotEvent("O2: ter>"), 1, "got O2"); +is(FhemTestUtils_gotEvent("O3: enter>"), 0, "no O3, chain too long"); +is(FhemTestUtils_gotLog("chain would get longer "), 1, "chain too long"); + +done_testing; +exit(0); + +1; diff --git a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg index b5dbe140a..8e9562acf 100644 --- a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg @@ -7,3 +7,11 @@ attr H2 minSendDelay 0 attr H2 reading01Name TestReading1 attr H2 reading01Regex erraschung mit (.*) +define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata2 0 +attr H3 verbose 5 +attr H3 fileHeaderSplit --end-of-http-header-- +attr H3 minSendDelay 0 +attr H3 bodyDecode auto +attr H3 reading01Name Test +attr H3 reading01Regex >([^ ]+) auf neue +attr H3 reading01Encode none \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t index 1a1b74f01..70f7ee7af 100644 --- a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t +++ b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use FHEM::Modbus::TestUtils qw(:all); my $hash = $defs{'H2'}; my $modVersion = $hash->{ModuleVersion}; @@ -11,7 +12,7 @@ $modVersion =~ /^([0-9]+)\./; my $major = $1; if ($major && $major >= 4) { - plan tests => 3; + plan tests => 9; } else { plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; } @@ -27,12 +28,28 @@ SKIP: { is(FhemTestUtils_gotEvent("H2:TestReading1: \x8e\x6e"), 1, "TestReading without bodyDecode"); +CheckAndReset(); fhem('attr H2 bodyDecode auto'); fhem('attr H2 readingEncode utf8'); fhem('set H2 reread'); - is(FhemTestUtils_gotEvent("H2:TestReading1: \xc3\x84\x6e"), 1, "TestReading with body decode"); +CheckAndReset(); +fhem('attr H2 dumpBuffers .'); +fhem('attr H2 verbose 5'); +fhem('set H2 reread'); + +# todo: check + +CheckAndReset(); +fhem 'set H3 reread'; +is(FhemTestUtils_gotEvent("H3:Test: Pr\xfcfe"), 1, "TestReading with body decode and Encode none"); + +CheckAndReset(); +fhem 'deleteattr H3 bodyDecode'; +fhem 'set H3 reread'; +is(FhemTestUtils_gotEvent("H3:Test: Pr\xc3\xbcfe"), 1, "TestReading with body decode and Encode none"); + done_testing; exit(0); diff --git a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 new file mode 100644 index 000000000..6d6fdaa93 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 @@ -0,0 +1,14 @@ +HTTP/1.1 200 OK +Content-Type: text/html; charset=cp437 +--end-of-http-header-- + +Test + +

Test Data

+
for HTTPMOD Test
+ +Überraschung mit Änderungen éè +kleine Umlaute: äöü + + + diff --git a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 new file mode 100644 index 000000000..928691a62 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 @@ -0,0 +1,48 @@ +HTTP/1.1 200 OK +Content-Type: text/html; charset=utf-8 +Cache-Control: no-cache, no-store, must-revalidate +Pragma: no-cache +Expires: 0 +Length: unspecified +--end-of-http-header-- + + + +BSB-LAN + + + + +

BSB-LAN

+ + + + +
+ HeizungsfunktionenSensoren + Zeichne LogdateiPrüfe auf neue Parameter
+ Einstellungen + URL-BefehleHandbuchFAQ

+
+
712 Heizkreis 1 - Reduziertsollwert: 21.0 °C +
+ + \ No newline at end of file