mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
v3.7.2
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
# The response will be shown in the right panel
|
||||
|
||||
# @host = http://ems-esp.local
|
||||
@host = http://192.168.1.206
|
||||
@host = http://192.168.1.225
|
||||
@host_dev = http://10.10.10.175
|
||||
@host_standalone = http://localhost:3080
|
||||
@host_standalone2 = http://localhost:3082
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
# Command line test for the API
|
||||
#
|
||||
|
||||
# EMS_ESP API
|
||||
emsesp_url="http://192.168.1.225"
|
||||
|
||||
emsesp_url="http://192.168.1.206"
|
||||
# get the token from the Security page. This is the token for the admin user, unless changed it'll always be the same
|
||||
emsesp_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWV9.2bHpWya2C7Q12WjNUBD6_7N3RCD7CMl-EGhyQVzFdDg"
|
||||
|
||||
# This example will get the system info, via a GET request
|
||||
curl -X GET ${emsesp_url}/api/system/info
|
||||
echo "\n"
|
||||
|
||||
# This example will execute a read command on product ID 8 and type ID 1
|
||||
curl -X POST \
|
||||
-H "Authorization: Bearer ${emsesp_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
@@ -20,12 +22,22 @@ curl -X POST \
|
||||
|
||||
echo "\n"
|
||||
|
||||
# HA API
|
||||
# This example will export all values to a json file, including custom entities, sensors and schedules
|
||||
curl -X POST \
|
||||
-H "Authorization: Bearer ${emsesp_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"action":"export", "param":"allvalues"}' \
|
||||
${emsesp_url}/rest/action
|
||||
|
||||
echo "\n"
|
||||
|
||||
# This example is how to call a service in Home Assistant via the API
|
||||
# Which can be added to an EMS-EPS schedule
|
||||
|
||||
ha_url="http://192.168.1.42:8123"
|
||||
ha_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMzMyZjU1MjhlZmM0NGIyOTgyMjIxNThiODU1NDkyNSIsImlhdCI6MTcyMTMwNDg2NSwiZXhwIjoyMDM2NjY0ODY1fQ.Q-Y7E_i7clH3ff4Ma-OMmhZfbN7aMi_CahKwmoar"
|
||||
|
||||
# curl -X POST \
|
||||
# ${ha_url}/api/services/script/test_notify \
|
||||
# -H "Authorization: Bearer ${ha_token}" \
|
||||
# -H "Content-Type: application/json"
|
||||
curl -X POST \
|
||||
${ha_url}/api/services/script/test_notify \
|
||||
-H "Authorization: Bearer ${ha_token}" \
|
||||
-H "Content-Type: application/json"
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include <emsesp.h>
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "ESP8266React.h"
|
||||
#include "web/WebAPIService.h"
|
||||
#include "test_shuntingYard.hpp"
|
||||
|
||||
using namespace emsesp;
|
||||
|
||||
@@ -32,7 +32,7 @@ void run_tests();
|
||||
const char * call_url(const char * url);
|
||||
|
||||
AsyncWebServer * webServer;
|
||||
ESP8266React * esp8266React;
|
||||
ESP32React * esp32React;
|
||||
WebAPIService * webAPIService;
|
||||
EMSESP application;
|
||||
FS dummyFS;
|
||||
@@ -67,13 +67,13 @@ static TestStream stream;
|
||||
// load the tests
|
||||
// this is generated from this file when compiled with -DEMSESP_UNITY_CREATE
|
||||
// copy the output to the test_api.h file
|
||||
#include "test_api.h" // generated test functions
|
||||
#include "test_api.h"
|
||||
|
||||
// Unity's setup call - is called before each test
|
||||
// Unity's setup call - is called before each test - empty for now
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
// Unity's teardown call - is called after each test
|
||||
// Unity's teardown call - is called after each test - empty for now
|
||||
void tearDown() {
|
||||
}
|
||||
|
||||
@@ -171,7 +171,6 @@ const char * call_url(const char * url) {
|
||||
request.method(HTTP_GET);
|
||||
request.url(url);
|
||||
webAPIService->webAPIService(&request);
|
||||
|
||||
return webAPIService->getResponse();
|
||||
}
|
||||
|
||||
@@ -187,7 +186,6 @@ const char * call_url(const char * url, const char * data) {
|
||||
request.method(HTTP_POST);
|
||||
request.url(url);
|
||||
webAPIService->webAPIService(&request, json);
|
||||
|
||||
return webAPIService->getResponse();
|
||||
}
|
||||
|
||||
@@ -268,23 +266,43 @@ void manual_test4() {
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/thermostat", data));
|
||||
}
|
||||
|
||||
void manual_test5() {
|
||||
auto expected_response = "[{}]"; // empty is good
|
||||
char data[] = "{\"value\":11}";
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analogsensor4", data));
|
||||
}
|
||||
|
||||
void manual_test6() {
|
||||
auto expected_response = "[{}]"; // empty is good
|
||||
char data[] = "{\"value\":10,\"id\":33}";
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/setvalue", data));
|
||||
}
|
||||
|
||||
|
||||
void run_manual_tests() {
|
||||
RUN_TEST(manual_test1);
|
||||
RUN_TEST(manual_test2);
|
||||
RUN_TEST(manual_test3);
|
||||
RUN_TEST(manual_test4);
|
||||
RUN_TEST(manual_test5);
|
||||
RUN_TEST(manual_test6);
|
||||
}
|
||||
|
||||
const char * run_console_command(const char * command) {
|
||||
output_buffer[0] = '\0'; // empty the temp buffer
|
||||
shell->invoke_command(command);
|
||||
// remove everything before \r\n
|
||||
|
||||
// The buffer now contains a prompt, the command, the output and a \r\n
|
||||
// remove the \r\n at the end
|
||||
char * p = strstr(output_buffer, "\r\n");
|
||||
if (p) {
|
||||
p += 2; // skip the \r\n
|
||||
*p = '\0';
|
||||
}
|
||||
// remove the \r\n at the end
|
||||
p[strlen(p) - 2] = '\0';
|
||||
|
||||
// Now go to just after the prompt and command
|
||||
p = output_buffer + 7 + strlen(command);
|
||||
|
||||
// Serial.println("Output:");
|
||||
// Serial.print(p);
|
||||
@@ -318,8 +336,10 @@ void run_console_tests() {
|
||||
|
||||
// auto-generate the tests
|
||||
void create_tests() {
|
||||
// These tests should all pass....
|
||||
// These match the calls in test_api.h
|
||||
// They are all READ calls, no POST or PUT. We use the manual tests for those.
|
||||
|
||||
// this first section should all pass
|
||||
capture("/api/boiler");
|
||||
capture("/api/boiler/commands");
|
||||
capture("/api/boiler/values");
|
||||
@@ -406,8 +426,8 @@ void create_tests() {
|
||||
// Main entry point
|
||||
int main() {
|
||||
webServer = new AsyncWebServer(80);
|
||||
esp8266React = new ESP8266React(webServer, &dummyFS);
|
||||
webAPIService = new WebAPIService(webServer, esp8266React->getSecurityManager());
|
||||
esp32React = new ESP32React(webServer, &dummyFS);
|
||||
webAPIService = new WebAPIService(webServer, esp32React->getSecurityManager());
|
||||
|
||||
// Serial console for commands
|
||||
Serial.begin(115200);
|
||||
@@ -433,9 +453,10 @@ int main() {
|
||||
//
|
||||
UNITY_BEGIN();
|
||||
|
||||
run_tests(); // execute the generated tests
|
||||
run_manual_tests(); // execute some other manual tests from this file
|
||||
run_console_tests(); // execute some console tests
|
||||
run_tests(); // execute the generated tests
|
||||
run_manual_tests(); // execute some other manual tests from this file
|
||||
run_console_tests(); // execute some console tests
|
||||
run_shuntingYard_tests(); // execute the shuntingYard tests
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// **************************************************************************************************
|
||||
//
|
||||
// Compile with -DEMSESP_UNITY_CREATE to generate the test functions
|
||||
// and copy the output and paste below.
|
||||
// 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
|
||||
//
|
||||
@@ -92,7 +91,9 @@ void test_7() {
|
||||
|
||||
void test_8() {
|
||||
auto expected_response = "[{\"name\":\"outdoortemp\",\"fullname\":\"outside "
|
||||
"temperature\",\"circuit\":\"\",\"type\":\"number\",\"uom\":\"°C\",\"readable\":true,\"writeable\":false,\"visible\":true}]";
|
||||
"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"));
|
||||
}
|
||||
|
||||
@@ -126,15 +127,15 @@ void test_13() {
|
||||
|
||||
void test_14() {
|
||||
auto expected_response = "[{\"name\":\"seltemp\",\"fullname\":\"hc1 selected room "
|
||||
"temperature\",\"circuit\":\"hc1\",\"value\":20.5,\"type\":\"number\",\"min\":0,\"max\":30,\"uom\":\"°C\",\"readable\":true,"
|
||||
"\"writeable\":true,\"visible\":true}]";
|
||||
"temperature\",\"circuit\":\"hc1\",\"value\":20.5,\"type\":\"number\",\"min\":0,\"max\":30,\"uom\":\"°C\",\"state_class\":"
|
||||
"\"measurement\",\"device_class\":\"temperature\",\"readable\":true,\"writeable\":true,\"visible\":true}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/thermostat/hc1/seltemp"));
|
||||
}
|
||||
|
||||
void test_15() {
|
||||
auto expected_response = "[{\"name\":\"seltemp\",\"fullname\":\"hc2 selected room "
|
||||
"temperature\",\"circuit\":\"hc2\",\"value\":20.6,\"type\":\"number\",\"min\":0,\"max\":30,\"uom\":\"°C\",\"readable\":true,"
|
||||
"\"writeable\":true,\"visible\":true}]";
|
||||
"temperature\",\"circuit\":\"hc2\",\"value\":20.6,\"type\":\"number\",\"min\":0,\"max\":30,\"uom\":\"°C\",\"state_class\":"
|
||||
"\"measurement\",\"device_class\":\"temperature\",\"readable\":true,\"writeable\":true,\"visible\":true}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/thermostat/hc2/seltemp"));
|
||||
}
|
||||
|
||||
@@ -163,20 +164,20 @@ void test_19() {
|
||||
"\"entityFormat\":1,\"base\":\"ems-esp\",\"discoveryPrefix\":\"homeassistant\",\"discoveryType\":0,\"nestedFormat\":1,\"haEnabled\":true,\"mqttQos\":0,"
|
||||
"\"mqttRetain\":false,\"publishTimeHeartbeat\":60,\"publishTimeBoiler\":10,\"publishTimeThermostat\":10,\"publishTimeSolar\":10,\"publishTimeMixer\":"
|
||||
"10,\"publishTimeWater\":0,\"publishTimeOther\":10,\"publishTimeSensor\":10,\"publishSingle\":false,\"publish2command\":false,\"sendResponse\":false},"
|
||||
"\"syslog\":{\"enabled\":false},\"sensor\":{\"temperatureSensors\":2,\"temperatureSensorReads\":0,\"temperatureSensorFails\":0,\"analogSensors\":3,"
|
||||
"\"syslog\":{\"enabled\":false},\"sensor\":{\"temperatureSensors\":2,\"temperatureSensorReads\":0,\"temperatureSensorFails\":0,\"analogSensors\":4,"
|
||||
"\"analogSensorReads\":0,\"analogSensorFails\":0},\"api\":{\"APICalls\":0,\"APIFails\":0},\"bus\":{\"busStatus\":\"connected\",\"busProtocol\":"
|
||||
"\"Buderus\",\"busTelegramsReceived\":8,\"busReads\":0,\"busWrites\":0,\"busIncompleteTelegrams\":0,\"busReadsFailed\":0,\"busWritesFailed\":0,"
|
||||
"\"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,\"webLogBuffer\":0,\"modbusEnabled\":false,\"forceHeatingOff\":false,\"developerMode\":false},\"devices\":[{\"type\":"
|
||||
"\"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 "
|
||||
"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\","
|
||||
"\"entities\":3},{\"type\":\"scheduler\",\"name\":\"scheduler\",\"entities\":2},{\"type\":\"custom\",\"name\":\"custom\",\"entities\":4}]}]";
|
||||
"\"entities\":4},{\"type\":\"scheduler\",\"name\":\"scheduler\",\"entities\":2},{\"type\":\"custom\",\"name\":\"custom\",\"entities\":4}]}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system"));
|
||||
}
|
||||
|
||||
@@ -189,26 +190,26 @@ void test_20() {
|
||||
"\"entityFormat\":1,\"base\":\"ems-esp\",\"discoveryPrefix\":\"homeassistant\",\"discoveryType\":0,\"nestedFormat\":1,\"haEnabled\":true,\"mqttQos\":0,"
|
||||
"\"mqttRetain\":false,\"publishTimeHeartbeat\":60,\"publishTimeBoiler\":10,\"publishTimeThermostat\":10,\"publishTimeSolar\":10,\"publishTimeMixer\":"
|
||||
"10,\"publishTimeWater\":0,\"publishTimeOther\":10,\"publishTimeSensor\":10,\"publishSingle\":false,\"publish2command\":false,\"sendResponse\":false},"
|
||||
"\"syslog\":{\"enabled\":false},\"sensor\":{\"temperatureSensors\":2,\"temperatureSensorReads\":0,\"temperatureSensorFails\":0,\"analogSensors\":3,"
|
||||
"\"syslog\":{\"enabled\":false},\"sensor\":{\"temperatureSensors\":2,\"temperatureSensorReads\":0,\"temperatureSensorFails\":0,\"analogSensors\":4,"
|
||||
"\"analogSensorReads\":0,\"analogSensorFails\":0},\"api\":{\"APICalls\":0,\"APIFails\":0},\"bus\":{\"busStatus\":\"connected\",\"busProtocol\":"
|
||||
"\"Buderus\",\"busTelegramsReceived\":8,\"busReads\":0,\"busWrites\":0,\"busIncompleteTelegrams\":0,\"busReadsFailed\":0,\"busWritesFailed\":0,"
|
||||
"\"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,\"webLogBuffer\":0,\"modbusEnabled\":false,\"forceHeatingOff\":false,\"developerMode\":false},\"devices\":[{\"type\":"
|
||||
"\"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 "
|
||||
"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\","
|
||||
"\"entities\":3},{\"type\":\"scheduler\",\"name\":\"scheduler\",\"entities\":2},{\"type\":\"custom\",\"name\":\"custom\",\"entities\":4}]}]";
|
||||
"\"entities\":4},{\"type\":\"scheduler\",\"name\":\"scheduler\",\"entities\":2},{\"type\":\"custom\",\"name\":\"custom\",\"entities\":4}]}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/info"));
|
||||
}
|
||||
|
||||
void test_21() {
|
||||
auto expected_response =
|
||||
"[{\"name\":\"locale\",\"circuit\":\"settings\",\"readable\":true,\"writable\":false,\"visible\":true,\"value\":\"en\",\"type\":\"string\"}]";
|
||||
"[{\"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"));
|
||||
}
|
||||
|
||||
@@ -267,12 +268,12 @@ void test_31() {
|
||||
}
|
||||
|
||||
void test_32() {
|
||||
auto expected_response = "[{\"test_analogsensor1\":0,\"test_analogsensor2\":1,\"test_analogsensor3\":0}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"test_analogsensor1\":0,\"test_analogsensor2\":1,\"test_analogsensor3\":0}]";
|
||||
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"));
|
||||
}
|
||||
|
||||
@@ -293,82 +294,82 @@ void test_36() {
|
||||
}
|
||||
|
||||
void test_37() {
|
||||
auto expected_response = "[{\"message\":\"no bad/value in boiler\"}]";
|
||||
auto expected_response = "[{}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/bad/value"));
|
||||
}
|
||||
|
||||
void test_38() {
|
||||
auto expected_response = "[{\"message\":\"no valu in comfort\"}]";
|
||||
auto expected_response = "[{\"message\":\"no attribute 'valu' in comfort\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/comfort/valu"));
|
||||
}
|
||||
|
||||
void test_39() {
|
||||
auto expected_response = "[{\"message\":\"no settings in system\"}]";
|
||||
auto expected_response = "[{\"message\":\"no entity 'settings' in system\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings/locale2"));
|
||||
}
|
||||
|
||||
void test_40() {
|
||||
auto expected_response = "[{\"message\":\"no settings2 in system\"}]";
|
||||
auto expected_response = "[{\"message\":\"no entity 'settings2' in system\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings2"));
|
||||
}
|
||||
|
||||
void test_41() {
|
||||
auto expected_response = "[{\"message\":\"no settings2 in system\"}]";
|
||||
auto expected_response = "[{\"message\":\"no entity 'settings2' in system\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings2/locale2"));
|
||||
}
|
||||
|
||||
void test_42() {
|
||||
auto expected_response = "[{\"message\":\"no test_scheduler2 in scheduler\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no val in test_scheduler\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no test_scheduler2 in scheduler\"}]";
|
||||
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 seltemp2 in custom\"}]";
|
||||
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 val in seltemp\"}]";
|
||||
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 test_sensor20 in temperaturesensor\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no 0b_0c0d_0e0f_xxxx in temperaturesensor\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no bad in test_tempsensor2\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no bad in test_analogsensor1\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no test_analog10 in analogsensor\"}]";
|
||||
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() {
|
||||
auto expected_response = "[{\"message\":\"no test_analog10 in analogsensor\"}]";
|
||||
auto expected_response = "[{\"message\":\"no entity 'test_analog10' in analogsensor\"}]";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analog10/bad2"));
|
||||
}
|
||||
|
||||
|
||||
157
test/test_api/test_shuntingYard.hpp
Normal file
157
test/test_api/test_shuntingYard.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
#include <HTTPClient.h>
|
||||
#include "core/shuntingYard.hpp"
|
||||
|
||||
void shuntingYard_test1() {
|
||||
std::string expected_result = "locale is en";
|
||||
std::string test_value = "\"locale is \"system/settings/locale";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test2() {
|
||||
// test with negative value
|
||||
std::string expected_result = "rssi is -23";
|
||||
std::string test_value = "\"rssi is \"0+system/network/rssi";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test3() {
|
||||
std::string expected_result = "rssi is -23 dBm";
|
||||
std::string test_value = "\"rssi is \"(system/network/rssi)\" dBm\"";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test4() {
|
||||
std::string expected_result = "14";
|
||||
std::string test_value = "(custom/seltemp/value)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test5() {
|
||||
std::string expected_result = "seltemp=14";
|
||||
std::string test_value = "\"seltemp=\"(custom/seltemp/value)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test6() {
|
||||
std::string expected_result = "14";
|
||||
std::string test_value = "(custom/seltemp)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test7() {
|
||||
std::string expected_result = "40";
|
||||
std::string test_value = "boiler/flowtempoffset";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test8() {
|
||||
std::string expected_result = "40";
|
||||
std::string test_value = "(boiler/flowtempoffset/value)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test9() {
|
||||
std::string expected_result = "53.8";
|
||||
std::string test_value = "(boiler/storagetemp1/value)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test10() {
|
||||
// (14 - 40) * 2.8 + 5 = -67.8
|
||||
std::string expected_result = "-67.8";
|
||||
std::string test_value = "(custom/seltemp - boiler/flowtempoffset) * 2.8 + 5";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test11() {
|
||||
std::string expected_result = "4";
|
||||
std::string test_value = "1 > 2 ? 3 : 4";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test12() {
|
||||
std::string expected_result = "3";
|
||||
std::string test_value = "1 < 2 ? 3 : 4";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test13() {
|
||||
std::string expected_result = "5";
|
||||
std::string test_value = "1<2?(3<4?5:6):7";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test14() {
|
||||
std::string expected_result = "7";
|
||||
std::string test_value = "1>2?(3<4?5:6):7";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test15() {
|
||||
std::string expected_result = "6";
|
||||
std::string test_value = "1<2?(3>4?5:6):7";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test16() {
|
||||
std::string expected_result = "3";
|
||||
std::string test_value = "1<2?3:(4<5?6:7)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test17() {
|
||||
std::string expected_result = "6";
|
||||
std::string test_value = "1>2?3:(4<5?6:7)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test18() {
|
||||
std::string expected_result = "7";
|
||||
std::string test_value = "1>2?3:(4>5?6:7)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test19() {
|
||||
std::string expected_result = "44";
|
||||
std::string test_value = "(1>2?3:4)+(10>20?30:40)";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test20() {
|
||||
std::string expected_result = "8";
|
||||
std::string test_value = "1<2 ? 3>4 ? 5 : 6<7 ? 8 : 9 : 10";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
void shuntingYard_test21() {
|
||||
std::string expected_result = "1";
|
||||
std::string test_value = "boiler/storagetemp2 == \"\"";
|
||||
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user