mirror of https://github.com/meshcore-dev/MeshCore
5 changed files with 113 additions and 62 deletions
@ -0,0 +1,36 @@ |
|||
#pragma once |
|||
|
|||
#include <cstdint> |
|||
|
|||
#include "Dispatcher.h" |
|||
|
|||
// Fake radio for native tests.
|
|||
// Provides successful no-op send/receive behavior without hardware access.
|
|||
class FakeRadio final : public mesh::Radio { |
|||
public: |
|||
int recvRaw(uint8_t*, int) override { |
|||
return 0; |
|||
} |
|||
|
|||
uint32_t getEstAirtimeFor(int) override { |
|||
return 1; |
|||
} |
|||
|
|||
float packetScore(float, int) override { |
|||
return 1.0f; |
|||
} |
|||
|
|||
bool startSendRaw(const uint8_t*, int) override { |
|||
return true; |
|||
} |
|||
|
|||
bool isSendComplete() override { |
|||
return true; |
|||
} |
|||
|
|||
void onSendFinished() override {} |
|||
|
|||
bool isInRecvMode() const override { |
|||
return true; |
|||
} |
|||
}; |
|||
@ -0,0 +1,25 @@ |
|||
#pragma once |
|||
|
|||
#if defined(__has_include_next) |
|||
#if __has_include_next(<random.h>) |
|||
#include_next <random.h> |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef __cplusplus |
|||
|
|||
#include <cstddef> |
|||
#include <cstring> |
|||
|
|||
#include "Utils.h" |
|||
|
|||
// Fake random generator for native tests.
|
|||
// Fills buffers with deterministic bytes so generated packets are repeatable.
|
|||
class FakeRng final : public mesh::RNG { |
|||
public: |
|||
void random(uint8_t* dest, size_t sz) override { |
|||
memset(dest, 0x5A, sz); |
|||
} |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,42 @@ |
|||
#pragma once |
|||
|
|||
#if defined(__has_include_next) |
|||
#if __has_include_next(<time.h>) |
|||
#include_next <time.h> |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef __cplusplus |
|||
|
|||
#include <cstdint> |
|||
|
|||
#include "Dispatcher.h" |
|||
|
|||
// Fake millisecond clock for native tests.
|
|||
// Returns a stable timestamp so timer-dependent code stays deterministic.
|
|||
class FakeMillis final : public mesh::MillisecondClock { |
|||
public: |
|||
unsigned long getMillis() override { |
|||
return 0; |
|||
} |
|||
}; |
|||
|
|||
// Fake RTC clock for native tests.
|
|||
// Stores caller-controlled Unix time without depending on hardware RTC APIs.
|
|||
class FakeRtc final : public mesh::RTCClock { |
|||
public: |
|||
explicit FakeRtc(uint32_t initial_time) : _time(initial_time) {} |
|||
|
|||
uint32_t getCurrentTime() override { |
|||
return _time; |
|||
} |
|||
|
|||
void setCurrentTime(uint32_t time) override { |
|||
_time = time; |
|||
} |
|||
|
|||
private: |
|||
uint32_t _time; |
|||
}; |
|||
|
|||
#endif |
|||
Loading…
Reference in new issue