testCommon.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef RYANJSON_TEST_COMMON_H
  2. #define RYANJSON_TEST_COMMON_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #include <time.h>
  11. #include <ctype.h>
  12. #include <inttypes.h>
  13. #include "FreeRTOS.h"
  14. #include "task.h"
  15. #include "unity.h"
  16. #include "valloc.h"
  17. #include "RyanJson.h"
  18. #include "cJSON.h"
  19. #include "yyjson.h"
  20. #include "testPlatform.h"
  21. #ifndef RyanJsonTestAllocHeaderSize
  22. #define RyanJsonTestAllocHeaderSize RyanJsonMallocHeaderSize
  23. #endif
  24. #ifndef RyanJsonTestAllocAlignSize
  25. #define RyanJsonTestAllocAlignSize RyanJsonMallocAlign
  26. #endif
  27. static inline void delay(uint32_t ms)
  28. {
  29. testPlatformSleepMs(ms);
  30. }
  31. #define getArraySize(arr) ((int32_t)(sizeof(arr) / sizeof((arr)[0])))
  32. // 定义枚举类型
  33. extern void *unityTestMalloc(size_t size);
  34. extern void unityTestFree(void *block);
  35. extern void *unityTestRealloc(void *block, size_t size);
  36. extern void unityTestSetAllocSimulation(uint8_t isEnable);
  37. extern uint8_t unityTestGetAllocSimulation(void);
  38. extern void unityTestOomBegin(int32_t failAfter, RyanJsonBool_e disableRealloc);
  39. extern void unityTestOomEnd(void);
  40. extern int32_t unityTestGetUse(void);
  41. extern void showMemoryInfo(void);
  42. extern void logTaskStackRuntimeInfoByHandle(const char *tag, const char *taskName, TaskHandle_t taskHandle);
  43. // 定义结构体类型
  44. extern uint64_t platformUptimeMs(void);
  45. extern RyanJsonBool_e RyanJsonExample(void);
  46. extern RyanJsonBool_e RyanJsonTestFun(void);
  47. extern void ryanJsonTestSetup(void);
  48. extern void ryanJsonTestTeardown(void);
  49. #define UNITY_TEST_OOM_BEGIN(failAfter) unityTestOomBegin((failAfter), RyanJsonFalse)
  50. #define UNITY_TEST_OOM_BEGIN_NO_REALLOC(failAfter) unityTestOomBegin((failAfter), RyanJsonTrue)
  51. #define UNITY_TEST_OOM_END() unityTestOomEnd()
  52. typedef struct
  53. {
  54. int32_t baseline;
  55. } unityTestLeakScope_t;
  56. static inline unityTestLeakScope_t unityTestLeakScopeBegin(void)
  57. {
  58. unityTestLeakScope_t scope = {unityTestGetUse()};
  59. return scope;
  60. }
  61. static inline void unityTestLeakScopeEnd(unityTestLeakScope_t scope, const char *msg)
  62. {
  63. TEST_ASSERT_EQUAL_INT_MESSAGE(scope.baseline, unityTestGetUse(), msg);
  64. }
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif