From d831d9cc876c076bef850e11a0d680b27607dca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Sun, 20 Nov 2022 16:38:31 +0100 Subject: [PATCH] Calculated formula now uses the specified unit! Prepare more tests. --- src/meters.cc | 3 ++- test.sh | 4 ++-- tests/test_config1.sh | 6 +++--- tests/test_conversions.sh | 4 ++++ tests/test_elements.sh | 4 ++-- tests/test_formulas.sh | 14 ++++++++++---- tests/test_logfile.sh | 12 ++++++------ tests/test_multiple_ids.sh | 30 +++++++++++++++--------------- 8 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/meters.cc b/src/meters.cc index f806b1c..b3b603e 100644 --- a/src/meters.cc +++ b/src/meters.cc @@ -827,7 +827,8 @@ void MeterCommonImplementation::addExtraCalculatedField(string ecf) "Calculated: "+ecf, PrintProperty::JSON | PrintProperty::FIELD, quantity, - parts[1] + parts[1], + unit ); } diff --git a/test.sh b/test.sh index 61c3463..03214b0 100755 --- a/test.sh +++ b/test.sh @@ -84,8 +84,8 @@ if [ "$?" != "0" ]; then RC="1"; fi tests/test_multiple_ids.sh $PROG if [ "$?" != "0" ]; then RC="1"; fi -tests/test_conversions.sh $PROG -if [ "$?" != "0" ]; then RC="1"; fi +#tests/test_conversions.sh $PROG +#if [ "$?" != "0" ]; then RC="1"; fi tests/test_formulas.sh $PROG if [ "$?" != "0" ]; then RC="1"; fi diff --git a/tests/test_config1.sh b/tests/test_config1.sh index 93f9e10..36b37c4 100755 --- a/tests/test_config1.sh +++ b/tests/test_config1.sh @@ -7,13 +7,13 @@ mkdir -p $TEST TESTNAME="Test normal config files with C1 meters" TESTRESULT="ERROR" -cat simulations/simulation_c1.txt | grep '^{' > $TEST/test_expected.txt +cat simulations/simulation_c1.txt | grep '^{' | jq --sort-keys . > $TEST/test_expected.txt -$PROG --useconfig=tests/config1 > $TEST/test_output.txt 2> $TEST/test_stderr.txt +$PROG --useconfig=tests/config1 2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then diff --git a/tests/test_conversions.sh b/tests/test_conversions.sh index 268f2e6..9bd622a 100755 --- a/tests/test_conversions.sh +++ b/tests/test_conversions.sh @@ -1,5 +1,9 @@ #!/bin/sh +# Adding automatic conversions is deprecated! + +exit 1 + PROG="$1" rm -rf testoutput diff --git a/tests/test_elements.sh b/tests/test_elements.sh index eedd2f5..f8a2fb2 100755 --- a/tests/test_elements.sh +++ b/tests/test_elements.sh @@ -8,7 +8,7 @@ TESTNAME="Test single meter conf file matches any id" TESTRESULT="ERROR" rm -f $TEST/meter_readings3/* -cat simulations/simulation_multiple_qcalorics.txt | grep '^{' > $TEST/test_expected.txt +cat simulations/simulation_multiple_qcalorics.txt | grep '^{' | jq --sort-keys . > $TEST/test_expected.txt $PROG --useconfig=tests/config3 > $TEST/test_output.txt @@ -20,7 +20,7 @@ then echo Failure, not the expected files in meter readings directory. exit 1 fi - cat $TEST/meter_readings3/* | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/meter_readings3/* | jq --sort-keys . | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then diff --git a/tests/test_formulas.sh b/tests/test_formulas.sh index b5fc460..0f90ed6 100755 --- a/tests/test_formulas.sh +++ b/tests/test_formulas.sh @@ -12,22 +12,28 @@ TESTRESULT="ERROR" $PROG --format=json \ --calculate_sumtemp_c='external_temperature_c+flow_temperature_c' \ --calculate_addtemp_c='external_temperature_c + 1100 c' \ + --calculate_external_temperature_f='external_temperature_c' \ 23442D2C998734761B168D2087D19EAD217F1779EDA86AB6_710008190000081900007F13 \ MyTapWater multical21 76348799 "" \ - > $TEST/test_output.txt + | jq --sort-keys . > $TEST/test_output.txt -cat > $TEST/test_expected.txt < $TEST/test_expected.txt +{"media":"cold water","meter":"multical21","name":"MyTapWater","id":"76348799","status":"DRY","total_m3":6.408,"target_m3":6.408,"flow_temperature_c":127,"external_temperature_c":19,"current_status":"DRY","time_dry":"22-31 days","time_reversed":"","time_leaking":"","time_bursting":"","sumtemp_c":146,"addtemp_c":1119,"external_temperature_f":66.2,"timestamp":"1111-11-11T11:11:11Z"} EOF if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then echo "OK: $TESTNAME" TESTRESULT="OK" + else + if [ "$USE_MELD" = "true" ] + then + meld $TEST/test_expected.txt $TEST/test_responses.txt + fi fi fi diff --git a/tests/test_logfile.sh b/tests/test_logfile.sh index ef7076d..e769d9e 100755 --- a/tests/test_logfile.sh +++ b/tests/test_logfile.sh @@ -21,8 +21,8 @@ then exit 1 fi -cat simulations/simulation_t1.txt | grep '^{' | grep 12345699 | tail -n 1 > $TEST/test_expected.txt -cat $TEST/meter_readings2/MoreWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt +cat simulations/simulation_t1.txt | grep '^{' | grep 12345699 | tail -n 1 | jq --sort-keys . > $TEST/test_expected.txt +cat $TEST/meter_readings2/MoreWater | jq --sort-keys . | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ ! "$?" = "0" ] then @@ -31,8 +31,8 @@ then exit 1 fi -cat simulations/simulation_t1.txt | grep '^{' | grep supercom | grep 12345678 | tail -n 1 > $TEST/test_expected.txt -cat $TEST/meter_readings2/MyWarmWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt +cat simulations/simulation_t1.txt | grep '^{' | grep supercom | grep 12345678 | tail -n 1 | jq --sort-keys . > $TEST/test_expected.txt +cat $TEST/meter_readings2/MyWarmWater | jq --sort-keys . | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ ! "$?" = "0" ] then @@ -41,8 +41,8 @@ then exit 1 fi -cat simulations/simulation_t1.txt | grep '^{' | grep 11111111 | tail -n 1 > $TEST/test_expected.txt -cat $TEST/meter_readings2/MyColdWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt +cat simulations/simulation_t1.txt | grep '^{' | grep 11111111 | tail -n 1 | jq --sort-keys . > $TEST/test_expected.txt +cat $TEST/meter_readings2/MyColdWater | jq --sort-keys . | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ ! "$?" = "0" ] then diff --git a/tests/test_multiple_ids.sh b/tests/test_multiple_ids.sh index 8f1abbc..af236c6 100755 --- a/tests/test_multiple_ids.sh +++ b/tests/test_multiple_ids.sh @@ -10,14 +10,14 @@ TESTRESULT="ERROR" SIM=simulations/simulation_multiple_qcalorics.txt -cat $SIM | grep '^{' > $TEST/test_expected.txt +cat $SIM | grep '^{' | jq --sort-keys . > $TEST/test_expected.txt $PROG --format=json $SIM \ Element qcaloric '*' '' \ - > $TEST/test_output.txt + | jq --sort-keys . > $TEST/test_output.txt if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then @@ -31,16 +31,16 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi TESTNAME="Test listen to wildcard suffix 8856* id" TESTRESULT="ERROR" -cat $SIM | grep '^{' | grep 8856 > $TEST/test_expected.txt +cat $SIM | grep '^{' | grep 8856 | jq --sort-keys . > $TEST/test_expected.txt $PROG --format=json $SIM \ Element qcaloric '8856*' '' \ - > $TEST/test_output.txt + | jq --sort-keys . > $TEST/test_output.txt if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then @@ -54,15 +54,15 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi TESTNAME="Test listen to two comma separted ids" TESTRESULT="ERROR" -cat $SIM | grep '^{' | grep -v 88563414 > $TEST/test_expected.txt +cat $SIM | grep '^{' | grep -v 88563414 | jq --sort-keys . > $TEST/test_expected.txt $PROG --format=json $SIM \ Element qcaloric '78563412,78563413' '' \ - > $TEST/test_output.txt + | jq --sort-keys . > $TEST/test_output.txt if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then @@ -76,15 +76,15 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi TESTNAME="Test listen to three comma separted ids" TESTRESULT="ERROR" -cat $SIM | grep '^{' > $TEST/test_expected.txt +cat $SIM | grep '^{' | jq --sort-keys . > $TEST/test_expected.txt $PROG --format=json $SIM \ Element qcaloric '78563412,78563413,88563414' '' \ - > $TEST/test_output.txt + | jq --sort-keys . > $TEST/test_output.txt if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then @@ -98,15 +98,15 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi TESTNAME="Test listen with negated ids" TESTRESULT="ERROR" -cat $SIM | grep '^{' | grep -v 88563414 | grep -v 78563413 > $TEST/test_expected.txt +cat $SIM | grep '^{' | grep -v 88563414 | grep -v 78563413 | jq --sort-keys . > $TEST/test_expected.txt $PROG --format=json $SIM \ Element qcaloric '*,!88563414,!78563413' '' \ - > $TEST/test_output.txt + | jq --sort-keys . > $TEST/test_output.txt if [ "$?" = "0" ] then - cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt + cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff $TEST/test_expected.txt $TEST/test_responses.txt if [ "$?" = "0" ] then