test: cover the frame codec and command names

Builds SomfyFrame.cpp in the native env, with a minimal String and
no-op ESP_LOGx in the stubs, and tests:

- a fixed 56-bit frame, byte for byte, so what goes on air is pinned
- encode/decode round trips for 56-bit, 80-bit (repeats, Favorite,
  Stop, steps, Toggle), RTW and RTV frames
- rejection of bad checksums, addresses, rolling codes, keys and
  80-bit parity
- repeat/synonym tracking in copy()
- parsing and naming of commands

The command-name round trip fails: names the firmware reports, such as
"Step Up" and "My+Up", parse back to the wrong command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-11 13:20:39 +02:00
parent bb16c90a5a
commit 3774aba45c
4 changed files with 304 additions and 1 deletions

View file

@ -9,6 +9,10 @@
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <type_traits>
typedef uint8_t byte;
// Fixed so anything formatted from it is deterministic.
inline unsigned long millis() { return 0; }
@ -17,4 +21,27 @@ inline bool getLocalTime(struct tm *info, uint32_t ms = 5000) {
time_t now = time(nullptr);
return localtime_r(&now, info) != nullptr;
}
// The parts of Arduino's String the firmware code under test uses.
class String {
std::string _s;
public:
String() {}
String(const char *s) : _s(s ? s : "") {}
String(const std::string &s) : _s(s) {}
// Arduino formats integers in decimal.
template<typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
explicit String(T val) : _s(std::to_string(val)) {}
const char *c_str() const { return _s.c_str(); }
unsigned int length() const { return (unsigned int)_s.length(); }
bool equalsIgnoreCase(const String &other) const {
if(_s.length() != other._s.length()) return false;
for(size_t i = 0; i < _s.length(); i++)
if(tolower((unsigned char)_s[i]) != tolower((unsigned char)other._s[i])) return false;
return true;
}
bool startsWith(const String &prefix) const { return _s.compare(0, prefix._s.length(), prefix._s) == 0; }
friend String operator+(const String &a, const String &b) { return String(a._s + b._s); }
friend bool operator==(const String &a, const String &b) { return a._s == b._s; }
};
#endif

10
test/stubs/esp_log.h Normal file
View file

@ -0,0 +1,10 @@
// Logging stand-in for the native test env. The format arguments are never
// evaluated so tests stay quiet and logging can't affect what they check.
#ifndef esp_log_stub_h
#define esp_log_stub_h
#define ESP_LOGE(tag, ...) ((void)(tag))
#define ESP_LOGW(tag, ...) ((void)(tag))
#define ESP_LOGI(tag, ...) ((void)(tag))
#define ESP_LOGD(tag, ...) ((void)(tag))
#define ESP_LOGV(tag, ...) ((void)(tag))
#endif