mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
update unit tests
This commit is contained in:
@@ -17,13 +17,12 @@
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <unity.h>
|
||||
|
||||
#include <emsesp.h>
|
||||
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "web/WebAPIService.h"
|
||||
#include "test_shuntingYard.hpp"
|
||||
#include "test_shuntingYard.h"
|
||||
|
||||
using namespace emsesp;
|
||||
|
||||
@@ -280,6 +279,12 @@ void manual_test6() {
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/setvalue", data));
|
||||
}
|
||||
|
||||
void manual_test7() {
|
||||
auto expected_response = "[{}]"; // empty is good
|
||||
char data[] = "{\"value\":9}";
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_ram", data));
|
||||
}
|
||||
|
||||
void run_manual_tests() {
|
||||
RUN_TEST(manual_test1);
|
||||
@@ -288,6 +293,7 @@ void run_manual_tests() {
|
||||
RUN_TEST(manual_test4);
|
||||
RUN_TEST(manual_test5);
|
||||
RUN_TEST(manual_test6);
|
||||
RUN_TEST(manual_test7);
|
||||
}
|
||||
|
||||
const char * run_console_command(const char * command) {
|
||||
@@ -362,14 +368,16 @@ void create_tests() {
|
||||
// custom
|
||||
capture("/api/custom");
|
||||
capture("/api/custom/info");
|
||||
capture("/api/custom/seltemp");
|
||||
capture("/api/custom/test_seltemp");
|
||||
capture("/api/custom/test_seltemp/value");
|
||||
capture("/api/custom/test_custom");
|
||||
|
||||
// system
|
||||
capture("/api/system");
|
||||
capture("/api/system/info");
|
||||
capture("/api/system/settings/locale");
|
||||
capture("/api/system/fetch");
|
||||
capture("api/system/network/values");
|
||||
capture("/api/system/network/values");
|
||||
|
||||
// scheduler
|
||||
capture("/api/scheduler");
|
||||
@@ -389,7 +397,10 @@ void create_tests() {
|
||||
capture("/api/analogsensor/test_analogsensor1");
|
||||
capture("/api/analogsensor/test_analogsensor1/offset");
|
||||
|
||||
// these tests should all fail...
|
||||
//
|
||||
// these next tests should all fail...
|
||||
//
|
||||
|
||||
capture("/api/boiler2");
|
||||
capture("/api/boiler/bad/value");
|
||||
capture("/api/boiler/comfort/valu");
|
||||
@@ -405,8 +416,8 @@ void create_tests() {
|
||||
capture("/api/scheduler/test_scheduler2/val2");
|
||||
|
||||
// custom
|
||||
capture("/api/custom/seltemp2");
|
||||
capture("/api/custom/seltemp/val");
|
||||
capture("/api/custom/test_seltemp2");
|
||||
capture("/api/custom/test_seltemp/val");
|
||||
|
||||
// temperaturesensor
|
||||
capture("/api/temperaturesensor/test_sensor20");
|
||||
@@ -437,15 +448,17 @@ int main() {
|
||||
|
||||
application.start(); // calls begin()
|
||||
|
||||
EMSESP::webCustomEntityService.test(); // custom entities
|
||||
EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS
|
||||
EMSESP::temperaturesensor_.test(); // add temperature sensors
|
||||
EMSESP::webSchedulerService.test(); // run scheduler tests, and conditions
|
||||
// populate with data, like custom entities, fake temp sensors and scheduler items
|
||||
EMSESP::webCustomEntityService.load_test_data(); // custom entities
|
||||
EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS
|
||||
EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors
|
||||
EMSESP::webSchedulerService.load_test_data(); // run scheduler tests, and conditions
|
||||
|
||||
add_devices(); // add devices
|
||||
|
||||
#if defined(EMSESP_UNITY_CREATE)
|
||||
create_tests();
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
// **************************************************************************************************
|
||||
//
|
||||
// Compile with -DEMSESP_UNITY_CREATE to generate the test functions, copy the output and paste below.
|
||||
//
|
||||
// TODO convert output to JSON and compare, showing differences
|
||||
//
|
||||
// You can also manually compare the differences using https://www.diffchecker.com/text-compare/
|
||||
//
|
||||
// **************************************************************************************************
|
||||
|
||||
// ---------- START - CUT HERE ----------
|
||||
|
||||
void test_1() {
|
||||
auto expected_response =
|
||||
"[{\"reset\":\"\",\"heatingoff\":\"off\",\"heatingactive\":\"off\",\"tapwateractive\":\"on\",\"selflowtemp\":0,\"curflowtemp\":60.2,\"rettemp\":48.1,"
|
||||
"\"syspress\":1.4,\"burngas\":\"on\",\"burngas2\":\"off\",\"flamecurr\":37.4,\"fanwork\":\"on\",\"ignwork\":\"off\",\"oilpreheat\":\"off\","
|
||||
"\"heatingpump\":\"on\",\"selburnpow\":115,\"curburnpow\":61,\"ubauptime\":3940268,\"servicecode\":\"=H\",\"servicecodenumber\":201,\"nompower\":0,"
|
||||
"\"nrgtotal\":0.0,\"nrgheat\":0.0,\"dhw\":{\"seltemp\":52,\"comfort\":\"hot\",\"flowtempoffset\":40,\"circpump\":\"off\",\"chargetype\":\"3-way "
|
||||
"valve\",\"hyston\":-5,\"hystoff\":0,\"disinfectiontemp\":70,\"circmode\":\"off\",\"circ\":\"off\",\"storagetemp1\":53.8,\"activated\":\"on\","
|
||||
"\"3wayvalve\":\"on\",\"nrg\":0.0}}]";
|
||||
auto expected_response = "[{\"reset\":\"\",\"heatingoff\":\"off\",\"heatingactive\":\"off\",\"tapwateractive\":\"on\",\"selflowtemp\":0,\"curflowtemp\":60."
|
||||
"2,\"rettemp\":48.1,\"syspress\":1.4,\"burngas\":\"on\",\"burngas2\":\"off\",\"flamecurr\":37.4,\"fanwork\":\"on\",\"ignwork\":"
|
||||
"\"off\",\"oilpreheat\":\"off\",\"heatingpump\":\"on\",\"selburnpow\":115,\"curburnpow\":61,\"ubauptime\":3940268,\"servicecode\":"
|
||||
"\"=H\",\"servicecodenumber\":201,\"nompower\":0,\"nrgtotal\":0.0,\"nrgheat\":0.0,\"dhw\":{\"seltemp\":52,\"comfort\":\"hot\","
|
||||
"\"flowtempoffset\":40,\"chargeoptimization\":\"off\",\"circpump\":\"off\",\"chargetype\":\"3-way "
|
||||
"valve\",\"hyston\":-5,\"disinfectiontemp\":70,\"circmode\":\"off\",\"circ\":\"off\",\"storagetemp1\":53.8,\"activated\":\"on\","
|
||||
"\"3wayvalve\":\"on\",\"chargepump\":\"off\",\"nrg\":0.0}}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler"));
|
||||
}
|
||||
|
||||
@@ -46,13 +37,13 @@ void test_2() {
|
||||
}
|
||||
|
||||
void test_3() {
|
||||
auto expected_response =
|
||||
"[{\"reset\":\"\",\"heatingoff\":\"off\",\"heatingactive\":\"off\",\"tapwateractive\":\"on\",\"selflowtemp\":0,\"curflowtemp\":60.2,\"rettemp\":48.1,"
|
||||
"\"syspress\":1.4,\"burngas\":\"on\",\"burngas2\":\"off\",\"flamecurr\":37.4,\"fanwork\":\"on\",\"ignwork\":\"off\",\"oilpreheat\":\"off\","
|
||||
"\"heatingpump\":\"on\",\"selburnpow\":115,\"curburnpow\":61,\"ubauptime\":3940268,\"servicecode\":\"=H\",\"servicecodenumber\":201,\"nompower\":0,"
|
||||
"\"nrgtotal\":0.0,\"nrgheat\":0.0,\"dhw\":{\"seltemp\":52,\"comfort\":\"hot\",\"flowtempoffset\":40,\"circpump\":\"off\",\"chargetype\":\"3-way "
|
||||
"valve\",\"hyston\":-5,\"hystoff\":0,\"disinfectiontemp\":70,\"circmode\":\"off\",\"circ\":\"off\",\"storagetemp1\":53.8,\"activated\":\"on\","
|
||||
"\"3wayvalve\":\"on\",\"nrg\":0.0}}]";
|
||||
auto expected_response = "[{\"reset\":\"\",\"heatingoff\":\"off\",\"heatingactive\":\"off\",\"tapwateractive\":\"on\",\"selflowtemp\":0,\"curflowtemp\":60."
|
||||
"2,\"rettemp\":48.1,\"syspress\":1.4,\"burngas\":\"on\",\"burngas2\":\"off\",\"flamecurr\":37.4,\"fanwork\":\"on\",\"ignwork\":"
|
||||
"\"off\",\"oilpreheat\":\"off\",\"heatingpump\":\"on\",\"selburnpow\":115,\"curburnpow\":61,\"ubauptime\":3940268,\"servicecode\":"
|
||||
"\"=H\",\"servicecodenumber\":201,\"nompower\":0,\"nrgtotal\":0.0,\"nrgheat\":0.0,\"dhw\":{\"seltemp\":52,\"comfort\":\"hot\","
|
||||
"\"flowtempoffset\":40,\"chargeoptimization\":\"off\",\"circpump\":\"off\",\"chargetype\":\"3-way "
|
||||
"valve\",\"hyston\":-5,\"disinfectiontemp\":70,\"circmode\":\"off\",\"circ\":\"off\",\"storagetemp1\":53.8,\"activated\":\"on\","
|
||||
"\"3wayvalve\":\"on\",\"chargepump\":\"off\",\"nrg\":0.0}}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/values"));
|
||||
}
|
||||
|
||||
@@ -64,11 +55,12 @@ void test_4() {
|
||||
"(flamecurr)\":37.4,\"fan (fanwork)\":\"on\",\"ignition (ignwork)\":\"off\",\"oil preheating (oilpreheat)\":\"off\",\"heating pump "
|
||||
"(heatingpump)\":\"on\",\"burner selected max power (selburnpow)\":115,\"burner current power (curburnpow)\":61,\"total UBA operating time "
|
||||
"(ubauptime)\":\"2736 days 7 hours 8 minutes\",\"service code (servicecode)\":\"=H\",\"service code number (servicecodenumber)\":201,\"dhw selected "
|
||||
"temperature (seltemp)\":52,\"dhw comfort (comfort)\":\"hot\",\"dhw flow temperature offset (flowtempoffset)\":40,\"dhw circulation pump available "
|
||||
"(circpump)\":\"off\",\"dhw charging type (chargetype)\":\"3-way valve\",\"dhw hysteresis on temperature (hyston)\":-5,\"dhw hysteresis off "
|
||||
"temperature (hystoff)\":0,\"dhw disinfection temperature (disinfectiontemp)\":70,\"dhw circulation pump mode (circmode)\":\"off\",\"dhw circulation "
|
||||
"active (circ)\":\"off\",\"dhw storage intern temperature (storagetemp1)\":53.8,\"dhw activated (activated)\":\"on\",\"dhw 3-way valve active "
|
||||
"(3wayvalve)\":\"on\",\"nominal Power (nompower)\":0,\"total energy (nrgtotal)\":0.0,\"energy heating (nrgheat)\":0.0,\"dhw energy (nrg)\":0.0}]";
|
||||
"temperature (seltemp)\":52,\"dhw comfort (comfort)\":\"hot\",\"dhw flow temperature offset (flowtempoffset)\":40,\"dhw charge optimization "
|
||||
"(chargeoptimization)\":\"off\",\"dhw circulation pump available (circpump)\":\"off\",\"dhw charging type (chargetype)\":\"3-way valve\",\"dhw "
|
||||
"hysteresis on temperature (hyston)\":-5,\"dhw disinfection temperature (disinfectiontemp)\":70,\"dhw circulation pump mode (circmode)\":\"off\",\"dhw "
|
||||
"circulation active (circ)\":\"off\",\"dhw storage intern temperature (storagetemp1)\":53.8,\"dhw activated (activated)\":\"on\",\"dhw 3-way valve "
|
||||
"active (3wayvalve)\":\"on\",\"dhw charge pump (chargepump)\":\"off\",\"nominal Power (nompower)\":0,\"total energy (nrgtotal)\":0.0,\"energy heating "
|
||||
"(nrgheat)\":0.0,\"dhw energy (nrg)\":0.0}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/info"));
|
||||
}
|
||||
|
||||
@@ -93,7 +85,6 @@ void test_8() {
|
||||
auto expected_response = "[{\"name\":\"outdoortemp\",\"fullname\":\"outside "
|
||||
"temperature\",\"circuit\":\"\",\"type\":\"number\",\"uom\":\"°C\",\"state_class\":\"measurement\",\"device_class\":"
|
||||
"\"temperature\",\"readable\":true,\"writeable\":false,\"visible\":true}]";
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/outdoortemp"));
|
||||
}
|
||||
|
||||
@@ -140,22 +131,34 @@ void test_15() {
|
||||
}
|
||||
|
||||
void test_16() {
|
||||
auto expected_response = "[{\"test_custom\":0.00,\"test_read_only\":0.00,\"test_ram\":\"14\",\"seltemp\":\"14\"}]";
|
||||
auto expected_response = "[{\"test_custom\":0.00,\"test_read_only\":70.00,\"test_ram\":\"14\",\"test_seltemp\":\"14\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom"));
|
||||
}
|
||||
|
||||
void test_17() {
|
||||
auto expected_response = "[{\"test_custom\":0.00,\"test_read_only\":0.00,\"test_ram\":\"14\",\"seltemp\":\"14\"}]";
|
||||
auto expected_response = "[{\"test_custom\":0.00,\"test_read_only\":70.00,\"test_ram\":\"14\",\"test_seltemp\":\"14\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/info"));
|
||||
}
|
||||
|
||||
void test_18() {
|
||||
auto expected_response = "[{\"name\":\"seltemp\",\"fullname\":\"seltemp\",\"storage\":\"ram\",\"type\":\"number\",\"readable\":true,\"writeable\":true,"
|
||||
"\"visible\":true,\"value\":\"14\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/seltemp"));
|
||||
auto expected_response = "[{\"name\":\"test_seltemp\",\"fullname\":\"test_seltemp\",\"storage\":\"ram\",\"type\":\"number\",\"readable\":true,"
|
||||
"\"writeable\":true,\"visible\":true,\"ent_cat\":\"diagnostic\",\"value\":\"14\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_seltemp"));
|
||||
}
|
||||
|
||||
void test_19() {
|
||||
auto expected_response = "[{\"api_data\":\"14\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_seltemp/value"));
|
||||
}
|
||||
|
||||
void test_20() {
|
||||
auto expected_response = "[{\"name\":\"test_custom\",\"fullname\":\"test_custom\",\"storage\":\"ems\",\"type\":\"number\",\"readable\":true,\"writeable\":"
|
||||
"true,\"visible\":true,\"device_id\":\"0x08\",\"type_id\":\"0x18\",\"offset\":0,\"factor\":1,\"ent_cat\":\"diagnostic\",\"uom\":"
|
||||
"\"°C\",\"state_class\":\"measurement\",\"device_class\":\"temperature\",\"value\":0.00}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_custom"));
|
||||
}
|
||||
|
||||
void test_21() {
|
||||
auto expected_response =
|
||||
"[{\"system\":{\"version\":\"dev\",\"uptime\":\"000+00:00:00.000\",\"uptimeSec\":0,\"resetReason\":\"Unknown / "
|
||||
"Unknown\"},\"network\":{\"network\":\"WiFi\",\"hostname\":\"ems-esp\",\"RSSI\":-23,\"TxPowerSetting\":0,\"staticIP\":false,\"lowBandwidth\":false,"
|
||||
@@ -170,10 +173,10 @@ void test_19() {
|
||||
"\"busRxLineQuality\":100,\"busTxLineQuality\":100},\"settings\":{\"boardProfile\":\"S32\",\"locale\":\"en\",\"txMode\":8,\"emsBusID\":11,"
|
||||
"\"showerTimer\":false,\"showerMinDuration\":180,\"showerAlert\":false,\"hideLed\":false,\"noTokenApi\":false,\"readonlyMode\":false,\"fahrenheit\":"
|
||||
"false,\"dallasParasite\":false,\"boolFormat\":1,\"boolDashboard\":1,\"enumFormat\":1,\"analogEnabled\":true,\"telnetEnabled\":true,"
|
||||
"\"maxWebLogBuffer\":25,\"modbusEnabled\":false,\"forceHeatingOff\":false,\"developerMode\":false},\"devices\":[{\"type\":"
|
||||
"\"boiler\",\"name\":\"My Custom "
|
||||
"Boiler\",\"deviceID\":\"0x08\",\"productID\":123,\"brand\":\"\",\"version\":\"01.00\",\"entities\":37,\"handlersReceived\":\"0x18\","
|
||||
"\"handlersFetched\":\"0x14 0x33\",\"handlersPending\":\"0xBF 0x10 0x11 0xC2 0x15 0x1C 0x19 0x1A 0x35 0x34 0x2A 0xD1 0xE3 0xE4 0xE5 0xE9 0x2E "
|
||||
"\"maxWebLogBuffer\":25,\"modbusEnabled\":false,\"forceHeatingOff\":false,\"developerMode\":false},\"devices\":[{\"type\":\"boiler\",\"name\":\"My "
|
||||
"Custom "
|
||||
"Boiler\",\"deviceID\":\"0x08\",\"productID\":123,\"brand\":\"\",\"version\":\"01.00\",\"entities\":38,\"handlersReceived\":\"0x18\","
|
||||
"\"handlersFetched\":\"0x14 0x33\",\"handlersPending\":\"0xBF 0x10 0x11 0xC2 0xC6 0x15 0x1C 0x19 0x1A 0x35 0x34 0x2A 0xD1 0xE3 0xE4 0xE5 0xE9 0x2E "
|
||||
"0x3B\"},{\"type\":\"thermostat\",\"name\":\"FW120\",\"deviceID\":\"0x10\",\"productID\":192,\"brand\":\"\",\"version\":\"01.00\",\"entities\":15,"
|
||||
"\"handlersReceived\":\"0x016F\",\"handlersFetched\":\"0x0170 0x0171\",\"handlersPending\":\"0xA3 0x06 0xA2 0x12 0x13 0x0172 0x0165 "
|
||||
"0x0168\"},{\"type\":\"temperaturesensor\",\"name\":\"temperaturesensor\",\"entities\":2},{\"type\":\"analogsensor\",\"name\":\"analogsensor\","
|
||||
@@ -181,7 +184,7 @@ void test_19() {
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system"));
|
||||
}
|
||||
|
||||
void test_20() {
|
||||
void test_22() {
|
||||
auto expected_response =
|
||||
"[{\"system\":{\"version\":\"dev\",\"uptime\":\"000+00:00:00.000\",\"uptimeSec\":0,\"resetReason\":\"Unknown / "
|
||||
"Unknown\"},\"network\":{\"network\":\"WiFi\",\"hostname\":\"ems-esp\",\"RSSI\":-23,\"TxPowerSetting\":0,\"staticIP\":false,\"lowBandwidth\":false,"
|
||||
@@ -196,10 +199,10 @@ void test_20() {
|
||||
"\"busRxLineQuality\":100,\"busTxLineQuality\":100},\"settings\":{\"boardProfile\":\"S32\",\"locale\":\"en\",\"txMode\":8,\"emsBusID\":11,"
|
||||
"\"showerTimer\":false,\"showerMinDuration\":180,\"showerAlert\":false,\"hideLed\":false,\"noTokenApi\":false,\"readonlyMode\":false,\"fahrenheit\":"
|
||||
"false,\"dallasParasite\":false,\"boolFormat\":1,\"boolDashboard\":1,\"enumFormat\":1,\"analogEnabled\":true,\"telnetEnabled\":true,"
|
||||
"\"maxWebLogBuffer\":25,\"modbusEnabled\":false,\"forceHeatingOff\":false,\"developerMode\":false},\"devices\":[{\"type\":"
|
||||
"\"boiler\",\"name\":\"My Custom "
|
||||
"Boiler\",\"deviceID\":\"0x08\",\"productID\":123,\"brand\":\"\",\"version\":\"01.00\",\"entities\":37,\"handlersReceived\":\"0x18\","
|
||||
"\"handlersFetched\":\"0x14 0x33\",\"handlersPending\":\"0xBF 0x10 0x11 0xC2 0x15 0x1C 0x19 0x1A 0x35 0x34 0x2A 0xD1 0xE3 0xE4 0xE5 0xE9 0x2E "
|
||||
"\"maxWebLogBuffer\":25,\"modbusEnabled\":false,\"forceHeatingOff\":false,\"developerMode\":false},\"devices\":[{\"type\":\"boiler\",\"name\":\"My "
|
||||
"Custom "
|
||||
"Boiler\",\"deviceID\":\"0x08\",\"productID\":123,\"brand\":\"\",\"version\":\"01.00\",\"entities\":38,\"handlersReceived\":\"0x18\","
|
||||
"\"handlersFetched\":\"0x14 0x33\",\"handlersPending\":\"0xBF 0x10 0x11 0xC2 0xC6 0x15 0x1C 0x19 0x1A 0x35 0x34 0x2A 0xD1 0xE3 0xE4 0xE5 0xE9 0x2E "
|
||||
"0x3B\"},{\"type\":\"thermostat\",\"name\":\"FW120\",\"deviceID\":\"0x10\",\"productID\":192,\"brand\":\"\",\"version\":\"01.00\",\"entities\":15,"
|
||||
"\"handlersReceived\":\"0x016F\",\"handlersFetched\":\"0x0170 0x0171\",\"handlersPending\":\"0xA3 0x06 0xA2 0x12 0x13 0x0172 0x0165 "
|
||||
"0x0168\"},{\"type\":\"temperaturesensor\",\"name\":\"temperaturesensor\",\"entities\":2},{\"type\":\"analogsensor\",\"name\":\"analogsensor\","
|
||||
@@ -207,168 +210,168 @@ void test_20() {
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/info"));
|
||||
}
|
||||
|
||||
void test_21() {
|
||||
void test_23() {
|
||||
auto expected_response =
|
||||
"[{\"name\":\"locale\",\"circuit\":\"settings\",\"readable\":true,\"writeable\":false,\"visible\":true,\"value\":\"en\",\"type\":\"string\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings/locale"));
|
||||
}
|
||||
|
||||
void test_22() {
|
||||
void test_24() {
|
||||
auto expected_response = "[{}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/fetch"));
|
||||
}
|
||||
|
||||
void test_23() {
|
||||
void test_25() {
|
||||
auto expected_response = "[{\"network\":\"WiFi\",\"hostname\":\"ems-esp\",\"RSSI\":\"-23\",\"TxPowerSetting\":\"0\",\"staticIP\":\"false\","
|
||||
"\"lowBandwidth\":\"false\",\"disableSleep\":\"true\",\"enableMDNS\":\"true\",\"enableCORS\":\"false\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("api/system/network/values"));
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/network/values"));
|
||||
}
|
||||
|
||||
void test_24() {
|
||||
void test_26() {
|
||||
auto expected_response = "[{\"test_scheduler\":\"on\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler"));
|
||||
}
|
||||
|
||||
void test_25() {
|
||||
void test_27() {
|
||||
auto expected_response = "[{\"test_scheduler\":\"on\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/info"));
|
||||
}
|
||||
|
||||
void test_26() {
|
||||
void test_28() {
|
||||
auto expected_response = "[{\"name\":\"test_scheduler\",\"fullname\":\"test_scheduler\",\"type\":\"boolean\",\"value\":\"on\",\"time\":\"12:00\","
|
||||
"\"command\":\"system/fetch\",\"cmd_data\":\"10\",\"readable\":true,\"writeable\":true,\"visible\":true}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler"));
|
||||
}
|
||||
|
||||
void test_27() {
|
||||
void test_29() {
|
||||
auto expected_response = "[{\"test_tempsensor1\":12.3,\"test_tempsensor2\":45.6}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor"));
|
||||
}
|
||||
|
||||
void test_28() {
|
||||
void test_30() {
|
||||
auto expected_response = "[{\"test_tempsensor1\":12.3,\"test_tempsensor2\":45.6}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/info"));
|
||||
}
|
||||
|
||||
void test_29() {
|
||||
void test_31() {
|
||||
auto expected_response = "[{\"id\":\"0B_0C0D_0E0F_1011\",\"name\":\"test_tempsensor2\",\"fullname\":\"test_tempsensor2\",\"value\":45.6,\"type\":"
|
||||
"\"number\",\"uom\":\"°C\",\"readable\":true,\"writeable\":false,\"visible\":true}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/test_tempsensor2"));
|
||||
}
|
||||
|
||||
void test_30() {
|
||||
void test_32() {
|
||||
auto expected_response = "[{\"id\":\"0B_0C0D_0E0F_1011\",\"name\":\"test_tempsensor2\",\"fullname\":\"test_tempsensor2\",\"value\":45.6,\"type\":"
|
||||
"\"number\",\"uom\":\"°C\",\"readable\":true,\"writeable\":false,\"visible\":true}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/0B_0C0D_0E0F_1011"));
|
||||
}
|
||||
|
||||
void test_31() {
|
||||
void test_33() {
|
||||
auto expected_response = "[{\"api_data\":\"45.6\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/test_tempsensor2/value"));
|
||||
}
|
||||
|
||||
void test_32() {
|
||||
void test_34() {
|
||||
auto expected_response = "[{\"test_analogsensor1\":0,\"test_analogsensor2\":1,\"test_analogsensor3\":0,\"test_analogsensor4\":0}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor"));
|
||||
}
|
||||
|
||||
void test_33() {
|
||||
void test_35() {
|
||||
auto expected_response = "[{\"test_analogsensor1\":0,\"test_analogsensor2\":1,\"test_analogsensor3\":0,\"test_analogsensor4\":0}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/info"));
|
||||
}
|
||||
|
||||
void test_34() {
|
||||
void test_36() {
|
||||
auto expected_response = "[{\"name\":\"test_analogsensor1\",\"fullname\":\"test_analogsensor1\",\"gpio\":36,\"type\":\"number\",\"analog\":\"adc\","
|
||||
"\"value\":0,\"readable\":true,\"writeable\":false,\"visible\":true,\"offset\":0,\"factor\":0.1,\"uom\":\"mV\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analogsensor1"));
|
||||
}
|
||||
|
||||
void test_35() {
|
||||
void test_37() {
|
||||
auto expected_response = "[{\"api_data\":\"0\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analogsensor1/offset"));
|
||||
}
|
||||
|
||||
void test_36() {
|
||||
void test_38() {
|
||||
auto expected_response = "[{\"message\":\"unknown device boiler2\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler2"));
|
||||
}
|
||||
|
||||
void test_37() {
|
||||
void test_39() {
|
||||
auto expected_response = "[{}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/bad/value"));
|
||||
}
|
||||
|
||||
void test_38() {
|
||||
void test_40() {
|
||||
auto expected_response = "[{\"message\":\"no attribute 'valu' in comfort\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/comfort/valu"));
|
||||
}
|
||||
|
||||
void test_39() {
|
||||
void test_41() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'settings' in system\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings/locale2"));
|
||||
}
|
||||
|
||||
void test_40() {
|
||||
void test_42() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'settings2' in system\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings2"));
|
||||
}
|
||||
|
||||
void test_41() {
|
||||
void test_43() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'settings2' in system\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings2/locale2"));
|
||||
}
|
||||
|
||||
void test_42() {
|
||||
void test_44() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_scheduler2' in scheduler\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler2"));
|
||||
}
|
||||
|
||||
void test_43() {
|
||||
void test_45() {
|
||||
auto expected_response = "[{\"message\":\"no attribute 'val' in test_scheduler\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler/val"));
|
||||
}
|
||||
|
||||
void test_44() {
|
||||
void test_46() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_scheduler2' in scheduler\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler2/val2"));
|
||||
}
|
||||
|
||||
void test_45() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'seltemp2' in custom\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/seltemp2"));
|
||||
}
|
||||
|
||||
void test_46() {
|
||||
auto expected_response = "[{\"message\":\"no attribute 'val' in seltemp\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/seltemp/val"));
|
||||
}
|
||||
|
||||
void test_47() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_seltemp2' in custom\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_seltemp2"));
|
||||
}
|
||||
|
||||
void test_48() {
|
||||
auto expected_response = "[{\"message\":\"Command test_seltemp failed (Error)\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/test_seltemp/val"));
|
||||
}
|
||||
|
||||
void test_49() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_sensor20' in temperaturesensor\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/test_sensor20"));
|
||||
}
|
||||
|
||||
void test_48() {
|
||||
void test_50() {
|
||||
auto expected_response = "[{\"message\":\"no entity '0b_0c0d_0e0f_xxxx' in temperaturesensor\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/0B_0C0D_0E0F_XXXX"));
|
||||
}
|
||||
|
||||
void test_49() {
|
||||
void test_51() {
|
||||
auto expected_response = "[{\"message\":\"no attribute 'bad' in test_tempsensor2\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/test_tempsensor2/bad"));
|
||||
}
|
||||
|
||||
void test_50() {
|
||||
void test_52() {
|
||||
auto expected_response = "[{\"message\":\"no attribute 'bad' in test_analogsensor1\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analogsensor1/bad"));
|
||||
}
|
||||
|
||||
void test_51() {
|
||||
void test_53() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_analog10' in analogsensor\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analog10"));
|
||||
}
|
||||
|
||||
void test_52() {
|
||||
void test_54() {
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_analog10' in analogsensor\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analog10/bad2"));
|
||||
}
|
||||
@@ -426,6 +429,8 @@ void run_tests() {
|
||||
RUN_TEST(test_50);
|
||||
RUN_TEST(test_51);
|
||||
RUN_TEST(test_52);
|
||||
RUN_TEST(test_53);
|
||||
RUN_TEST(test_54);
|
||||
}
|
||||
|
||||
// ---------- END - CUT HERE ----------
|
||||
// ---------- END - CUT HERE ----------
|
||||
126
test/test_api/test_shuntingYard.h
Normal file
126
test/test_api/test_shuntingYard.h
Normal file
@@ -0,0 +1,126 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
#include "core/shuntingYard.h"
|
||||
|
||||
void run_shuntingYard_test(const std::string & expected, const std::string & actual) {
|
||||
TEST_ASSERT_EQUAL_STRING(expected.c_str(), compute(actual).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test1() {
|
||||
run_shuntingYard_test("locale is en", "\"locale is \"system/settings/locale");
|
||||
}
|
||||
|
||||
void shuntingYard_test2() {
|
||||
run_shuntingYard_test("rssi is -23", "\"rssi is \"0+system/network/rssi");
|
||||
}
|
||||
|
||||
void shuntingYard_test3() {
|
||||
run_shuntingYard_test("rssi is -23 dBm", "\"rssi is \"(system/network/rssi)\" dBm\"");
|
||||
}
|
||||
|
||||
void shuntingYard_test4() {
|
||||
run_shuntingYard_test("14", "(custom/test_seltemp/value)");
|
||||
}
|
||||
|
||||
void shuntingYard_test5() {
|
||||
run_shuntingYard_test("seltemp=14", "\"seltemp=\"(custom/test_seltemp/value)");
|
||||
}
|
||||
|
||||
void shuntingYard_test6() {
|
||||
run_shuntingYard_test("14", "custom/test_seltemp");
|
||||
}
|
||||
|
||||
void shuntingYard_test7() {
|
||||
run_shuntingYard_test("40", "boiler/flowtempoffset");
|
||||
}
|
||||
|
||||
void shuntingYard_test8() {
|
||||
run_shuntingYard_test("40", "(boiler/flowtempoffset/value)");
|
||||
}
|
||||
|
||||
void shuntingYard_test9() {
|
||||
run_shuntingYard_test("53.8", "(boiler/storagetemp1/value)");
|
||||
}
|
||||
|
||||
void shuntingYard_test10() {
|
||||
run_shuntingYard_test("-67.8", "(custom/test_seltemp - boiler/flowtempoffset) * 2.8 + 5");
|
||||
}
|
||||
|
||||
void shuntingYard_test11() {
|
||||
run_shuntingYard_test("4", "1 > 2 ? 3 : 4");
|
||||
}
|
||||
|
||||
void shuntingYard_test12() {
|
||||
run_shuntingYard_test("3", "1 < 2 ? 3 : 4");
|
||||
}
|
||||
|
||||
void shuntingYard_test13() {
|
||||
run_shuntingYard_test("5", "1<2?(3<4?5:6):7");
|
||||
}
|
||||
|
||||
void shuntingYard_test14() {
|
||||
run_shuntingYard_test("7", "1>2?(3<4?5:6):7");
|
||||
}
|
||||
|
||||
void shuntingYard_test15() {
|
||||
run_shuntingYard_test("6", "1<2?(3>4?5:6):7");
|
||||
}
|
||||
|
||||
void shuntingYard_test16() {
|
||||
run_shuntingYard_test("3", "1<2?3:(4<5?6:7)");
|
||||
}
|
||||
|
||||
void shuntingYard_test17() {
|
||||
run_shuntingYard_test("6", "1>2?3:(4<5?6:7)");
|
||||
}
|
||||
|
||||
void shuntingYard_test18() {
|
||||
run_shuntingYard_test("7", "1>2?3:(4>5?6:7)");
|
||||
}
|
||||
|
||||
void shuntingYard_test19() {
|
||||
run_shuntingYard_test("44", "(1>2?3:4)+(10>20?30:40)");
|
||||
}
|
||||
|
||||
void shuntingYard_test20() {
|
||||
run_shuntingYard_test("8", "1<2 ? 3>4 ? 5 : 6<7 ? 8 : 9 : 10");
|
||||
}
|
||||
|
||||
void shuntingYard_test21() {
|
||||
run_shuntingYard_test("1", "boiler/storagetemp2 == \"\"");
|
||||
}
|
||||
|
||||
void shuntingYard_test22() {
|
||||
run_shuntingYard_test("1", "boiler/storagetemp2 == ''");
|
||||
}
|
||||
|
||||
void shuntingYard_test23() {
|
||||
run_shuntingYard_test("9", "custom/test_ram");
|
||||
}
|
||||
|
||||
void run_shuntingYard_tests() {
|
||||
RUN_TEST(shuntingYard_test1);
|
||||
RUN_TEST(shuntingYard_test2);
|
||||
RUN_TEST(shuntingYard_test3);
|
||||
RUN_TEST(shuntingYard_test4);
|
||||
RUN_TEST(shuntingYard_test5);
|
||||
RUN_TEST(shuntingYard_test6);
|
||||
RUN_TEST(shuntingYard_test7);
|
||||
RUN_TEST(shuntingYard_test8);
|
||||
RUN_TEST(shuntingYard_test9);
|
||||
RUN_TEST(shuntingYard_test10);
|
||||
RUN_TEST(shuntingYard_test11);
|
||||
RUN_TEST(shuntingYard_test12);
|
||||
RUN_TEST(shuntingYard_test13);
|
||||
RUN_TEST(shuntingYard_test14);
|
||||
RUN_TEST(shuntingYard_test15);
|
||||
RUN_TEST(shuntingYard_test16);
|
||||
RUN_TEST(shuntingYard_test17);
|
||||
RUN_TEST(shuntingYard_test18);
|
||||
RUN_TEST(shuntingYard_test19);
|
||||
RUN_TEST(shuntingYard_test20);
|
||||
RUN_TEST(shuntingYard_test21);
|
||||
RUN_TEST(shuntingYard_test22);
|
||||
RUN_TEST(shuntingYard_test23);
|
||||
}
|
||||
Reference in New Issue
Block a user