Add mock Arduino for x86_64 host-side testing
Complete Arduino API mock (mock_arduino.h/cpp) enabling application code to compile and run on PC without hardware. Includes MockSerial, String class, GPIO/analog/timing/interrupt mocks with state tracking and test control API. - Arduino.h, Wire.h, SPI.h shims intercept includes in test builds - System test template (test_system.cpp) using SimHal - CMakeLists.txt builds mock_arduino as static lib, links both suites - Root test.sh/test.bat with --unit/--system/--clean/--verbose flags - test.bat auto-detects MSVC via vswhere + vcvarsall.bat - Doctor reports nuanced compiler status (on PATH vs installed) - Refresh pulls mock infrastructure into existing projects - 15 tests passing: 7 unit (MockHal) + 8 system (SimHal)
This commit is contained in:
55
templates/basic/test/mocks/SPI.h
Normal file
55
templates/basic/test/mocks/SPI.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SPI.h -- shim for host-side test builds.
|
||||
*
|
||||
* Intercepts #include <SPI.h> so that code referencing SPI compiles
|
||||
* on x86_64. Provides a minimal mock of the Arduino SPI library.
|
||||
*
|
||||
* Generated by Anvil.
|
||||
*/
|
||||
#ifndef SPI_H_MOCK_SHIM
|
||||
#define SPI_H_MOCK_SHIM
|
||||
|
||||
#include "mock_arduino.h"
|
||||
|
||||
#define SPI_MODE0 0x00
|
||||
#define SPI_MODE1 0x04
|
||||
#define SPI_MODE2 0x08
|
||||
#define SPI_MODE3 0x0C
|
||||
|
||||
#define SPI_CLOCK_DIV2 0x04
|
||||
#define SPI_CLOCK_DIV4 0x00
|
||||
#define SPI_CLOCK_DIV8 0x05
|
||||
#define SPI_CLOCK_DIV16 0x01
|
||||
#define SPI_CLOCK_DIV32 0x06
|
||||
#define SPI_CLOCK_DIV64 0x02
|
||||
#define SPI_CLOCK_DIV128 0x03
|
||||
|
||||
#define MSBFIRST 1
|
||||
#define LSBFIRST 0
|
||||
|
||||
struct SPISettings {
|
||||
uint32_t clock;
|
||||
uint8_t bitOrder;
|
||||
uint8_t dataMode;
|
||||
SPISettings() : clock(4000000), bitOrder(MSBFIRST), dataMode(SPI_MODE0) {}
|
||||
SPISettings(uint32_t c, uint8_t o, uint8_t m)
|
||||
: clock(c), bitOrder(o), dataMode(m) {}
|
||||
};
|
||||
|
||||
class MockSPI {
|
||||
public:
|
||||
void begin() {}
|
||||
void end() {}
|
||||
void beginTransaction(SPISettings) {}
|
||||
void endTransaction() {}
|
||||
uint8_t transfer(uint8_t data) { (void)data; return 0; }
|
||||
uint16_t transfer16(uint16_t data) { (void)data; return 0; }
|
||||
void transfer(void* buf, size_t count) { (void)buf; (void)count; }
|
||||
void setBitOrder(uint8_t) {}
|
||||
void setClockDivider(uint8_t) {}
|
||||
void setDataMode(uint8_t) {}
|
||||
};
|
||||
|
||||
extern MockSPI SPI;
|
||||
|
||||
#endif // SPI_H_MOCK_SHIM
|
||||
Reference in New Issue
Block a user