This commit is contained in:
Tester23
2025-11-11 00:01:22 +01:00
parent 8146bfcda3
commit cc91574551
6 changed files with 62 additions and 0 deletions

View File

@@ -795,6 +795,7 @@
<ClCompile Include="src\selftest\selftest_max72xx.c" />
<ClCompile Include="src\selftest\selftest_mqtt_get.c" />
<ClCompile Include="src\selftest\selftest_ntp_sunsetSunrise.c" />
<ClCompile Include="src\selftest\selftest_openWeatherMap.c" />
<ClCompile Include="src\selftest\selftest_pir.c" />
<ClCompile Include="src\selftest\selftest_role_toggleAll_2.c" />
<ClCompile Include="src\selftest\selftest_cfg_via_http.c" />

View File

@@ -416,6 +416,7 @@
<ClCompile Include="src\driver\drv_bkPartitions.c" />
<ClCompile Include="src\selftest\selftest_max72xx.c" />
<ClCompile Include="src\driver\drv_multiPinI2CScanner.c" />
<ClCompile Include="src\selftest\selftest_openWeatherMap.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\base64\base64.h" />

View File

@@ -36,6 +36,10 @@ static char g_reply[1024];
weatherData_t g_weather;
weatherChannels_t g_channels;
weatherData_t *Weather_GetData() {
return &g_weather;
}
void Weather_SetReply(const char *s) {
const char *json_start = strstr(s, "\r\n\r\n");
if (json_start) {

View File

@@ -152,6 +152,7 @@ void Test_Demo_ConditionalRelay();
void Test_PIR();
void Test_Driver_TCL_AC();
void Test_MAX72XX();
void Test_OpenWeatherMap();
void Test_GetJSONValue_Setup(const char *text);
void Test_FakeHTTPClientPacket_GET(const char *tg);

View File

@@ -0,0 +1,54 @@
#ifdef WINDOWS
#include "selftest_local.h"
#include "../driver/drv_openWeatherMap.h"
const char *sample_reply =
"HTTP/1.1 200 OK\r\n"
"Date: Sat, 09 Nov 2025 12:00:00 GMT\r\n"
"Server: openweathermap.org\r\n"
"Content-Type: application/json; charset=utf-8\r\n"
"Content-Length: 123\r\n"
"Connection: close\r\n"
"\r\n"
"{"
" \"coord\": {\"lon\": 10.0, \"lat\": 50.0},"
" \"weather\": [{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],"
" \"base\": \"stations\","
" \"main\": {"
" \"temp\": 23.0,"
" \"pressure\": 998,"
" \"humidity\": 85,"
" \"temp_min\": 20.0,"
" \"temp_max\": 25.0"
" },"
" \"visibility\": 10000,"
" \"wind\": {\"speed\": 3.6,\"deg\": 180},"
" \"clouds\": {\"all\": 0},"
" \"dt\": 1604995200,"
" \"sys\": {\"type\":1,\"id\":1234,\"country\":\"US\",\"sunrise\":1604965200,\"sunset\":1605001200},"
" \"timezone\": -18000,"
" \"id\": 123456,"
" \"name\": \"Test City\","
" \"cod\": 200"
"}";
void Test_OpenWeatherMap() {
// HTTP header + json
Weather_SetReply(sample_reply);
weatherData_t *w = Weather_GetData();
SELFTEST_ASSERT_FLOATCOMPARE(w->humidity, 85);
SELFTEST_ASSERT_FLOATCOMPARE(w->pressure, 998);
SELFTEST_ASSERT_FLOATCOMPARE(w->temp, 23);
SELFTEST_ASSERT_STRING(w->main_weather, "Clear");
SELFTEST_ASSERT_STRING(w->description, "clear sky");
SELFTEST_ASSERT_FLOATCOMPARE(w->lat, 50);
SELFTEST_ASSERT_FLOATCOMPARE(w->lon, 10);
}
#endif

View File

@@ -204,6 +204,7 @@ void Win_DoUnitTests()
// SELFTEST_ASSERT_EXPRESSION("sqrt(4)", 2)
// Test_PartitionSearch();
Test_OpenWeatherMap();
Test_MAX72XX();
Test_LEDstrips();