From c574fdbe820aef1dc61f46e1528ff7705301b48b Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Wed, 27 Nov 2019 15:18:32 +0100 Subject: [PATCH] Make possible to mock internal code --- dmahelper.c | 19 +++++++++++++++++++ dmahelper.h | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/dmahelper.c b/dmahelper.c index 867cdf4..5f1d0c7 100644 --- a/dmahelper.c +++ b/dmahelper.c @@ -6,6 +6,25 @@ */ #include +#ifdef UNITTEST +MOCKME_IMPL(volatile uint32_t*, Dma_GetIsReg, DMA_TypeDef*, uint32_t) +MOCKME_IMPL(volatile uint32_t*, Dma_GetIfcReg, DMA_TypeDef*, uint32_t) +MOCKME_IMPL(uint32_t, Dma_GetDmeMask, uint32_t) +MOCKME_IMPL(uint32_t, Dma_GetTeMask, uint32_t) +MOCKME_IMPL(uint32_t, Dma_GetHtMask, uint32_t) +MOCKME_IMPL(uint32_t, Dma_GetTcMask, uint32_t) +MOCKME_IMPL(uint32_t, Dma_GetFeMask, uint32_t) +MOCKME_IMPL(void, Dma_Init, struct dmainfo_t*, DMA_TypeDef*, uint32_t) + +#define Dma_GetIsReg(...) Dma_GetIsReg_(__VA_ARGS__) +#define Dma_GetIfcReg(...) Dma_GetIfcReg_(__VA_ARGS__) +#define Dma_GetDmeMask(...) Dma_GetDmeMask_(__VA_ARGS__) +#define Dma_GetTeMask(...) Dma_GetTeMask_(__VA_ARGS__) +#define Dma_GetHtMask(...) Dma_GetHtMask_(__VA_ARGS__) +#define Dma_GetTcMask(...) Dma_GetTcMask_(__VA_ARGS__) +#define Dma_GetFeMask(...) Dma_GetFeMask_(__VA_ARGS__) +#define Dma_Init(...) Dma_Init_(__VA_ARGS__) +#endif // UNITTEST volatile uint32_t* Dma_GetIsReg(DMA_TypeDef *dma, uint32_t stream) { diff --git a/dmahelper.h b/dmahelper.h index ed7fb26..f6285ca 100644 --- a/dmahelper.h +++ b/dmahelper.h @@ -26,6 +26,31 @@ struct dmainfo_t { uint32_t tcMask; }; +//>>>>>>>>>> MOCK <<<<<<<<<< +#ifdef UNITTEST +MOCKME_PREP(volatile uint32_t*, Dma_GetIsReg, DMA_TypeDef*, uint32_t) +MOCKME_PREP(volatile uint32_t*, Dma_GetIfcReg, DMA_TypeDef*, uint32_t) +MOCKME_PREP(uint32_t, Dma_GetDmeMask, uint32_t) +MOCKME_PREP(uint32_t, Dma_GetTeMask, uint32_t) +MOCKME_PREP(uint32_t, Dma_GetHtMask, uint32_t) +MOCKME_PREP(uint32_t, Dma_GetTcMask, uint32_t) +MOCKME_PREP(uint32_t, Dma_GetFeMask, uint32_t) +MOCKME_PREP(void, Dma_Init, struct dmainfo_t*, DMA_TypeDef*, uint32_t) + +#define Dma_GetIsReg(...) Dma_GetIsReg_(__VA_ARGS__) +#define Dma_GetIfcReg(...) Dma_GetIfcReg_(__VA_ARGS__) +#define Dma_GetDmeMask(...) Dma_GetDmeMask_(__VA_ARGS__) +#define Dma_GetTeMask(...) Dma_GetTeMask_(__VA_ARGS__) +#define Dma_GetHtMask(...) Dma_GetHtMask_(__VA_ARGS__) +#define Dma_GetTcMask(...) Dma_GetTcMask_(__VA_ARGS__) +#define Dma_GetFeMask(...) Dma_GetFeMask_(__VA_ARGS__) +#define Dma_Init(...) Dma_Init_(__VA_ARGS__) +//#define (...) _(__VA_ARGS__) +#endif // UNITTEST +//>>>>>>>>>> MOCK end <<<<<<<<<< + +//>>>>>> Real Stuff (tm) <<<<<<<< + volatile uint32_t* Dma_GetIsReg(DMA_TypeDef *dma, uint32_t stream); volatile uint32_t* Dma_GetIfcReg(DMA_TypeDef *dma, uint32_t stream); uint32_t Dma_GetDmeMask(uint32_t stream); @@ -33,9 +58,22 @@ uint32_t Dma_GetTeMask(uint32_t stream); uint32_t Dma_GetHtMask(uint32_t stream); uint32_t Dma_GetTcMask(uint32_t stream); uint32_t Dma_GetFeMask(uint32_t stream); - void Dma_Init(struct dmainfo_t *info, DMA_TypeDef *dma, uint32_t stream); +//>>>>>> Real Stuff (tm) end <<<<<<<< + +//>>>>>>>>>> MOCK <<<<<<<<<< +#ifdef UNITTEST +#undef Dma_GetIsReg +#undef Dma_GetIfcReg +#undef Dma_GetDmeMask +#undef Dma_GetHtMask +#undef Dma_GetTcMask +#undef Dma_GetFeMask +#undef Dma_Init +#endif // UNITTEST +//>>>>>>>>>> MOCK end <<<<<<<<<< + #ifdef __cplusplus } #endif