hv_comm_Assert.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef __SDK_COMMON_DEBUG_INC_HV_ASSSERT_H_
  2. #define __SDK_COMMON_DEBUG_INC_HV_ASSSERT_H_
  3. #include "Common/hv_comm_DataType.h"
  4. #include "hv_comm_Log.h"
  5. #include "hv_comm_Define.h"
  6. /*如果使用HV_LOG_ASSERT 或者HV_LOG_ERROR打印过多,生成的bin占用近200K,所以使用INFO打印在release版本不打印任何ASSERT断言*/
  7. #define HV_ASSERT_VALID_PTR(ptr) \
  8. do \
  9. { \
  10. if (NULL == ptr) \
  11. { \
  12. HV_LOG_INFO(DEFAULT,"%s == NULL assert failure!!!", #ptr);\
  13. return HV_FAILURE; \
  14. } \
  15. }while(0)
  16. #define HV_ASSERT_VALID_PTR_VOID(ptr) \
  17. do \
  18. { \
  19. if (NULL == ptr) \
  20. { \
  21. HV_LOG_INFO(DEFAULT,"%s == NULL assert failure!!!", #ptr);\
  22. return; \
  23. } \
  24. }while(0)
  25. #define HV_ASSERT_VALID_PTR_VOID_NO_LOG(ptr) \
  26. do \
  27. { \
  28. if (NULL == ptr) \
  29. { \
  30. return; \
  31. } \
  32. }while(0)
  33. #define HV_ASSERT_VALID_PTR_RET(ptr, ret) \
  34. do \
  35. { \
  36. if (NULL == ptr) \
  37. { \
  38. HV_LOG_INFO(DEFAULT,"%s == NULL assert failure!!! return %s!!!", #ptr, #ret);\
  39. return ret; \
  40. } \
  41. }while(0)
  42. #define HV_ASSERT_VALID_PTR_RET_NO_LOG(ptr, ret)\
  43. do \
  44. { \
  45. if (NULL == ptr) \
  46. { \
  47. return ret; \
  48. } \
  49. }while(0)
  50. #define HV_ASSERT_TRUE(expression) \
  51. do \
  52. { \
  53. if (HV_TRUE != (expression)) \
  54. { \
  55. HV_LOG_INFO(DEFAULT,"(%s) != HV_TRUE assert failure!!!", #expression);\
  56. return HV_FAILURE; \
  57. } \
  58. }while(0)
  59. #define HV_ASSERT_PEEK_TRUE(expression) \
  60. do \
  61. { \
  62. if (HV_TRUE != (expression)) \
  63. { \
  64. HV_LOG_INFO(DEFAULT,"peek HV_TRUE but (%s) != HV_TRUE assert failure!!!", #expression);\
  65. } \
  66. }while(0)
  67. #define HV_ASSERT_TRUE_VOID(expression) \
  68. do \
  69. { \
  70. if (HV_TRUE != (expression)) \
  71. { \
  72. HV_LOG_INFO(DEFAULT,"(%s) != HV_TRUE assert failure!!!", #expression);\
  73. return; \
  74. } \
  75. }while(0)
  76. #define HV_ASSERT_TRUE_RET(expression, ret) \
  77. do \
  78. { \
  79. if (HV_TRUE != (expression)) \
  80. { \
  81. HV_LOG_INFO(DEFAULT,"(%s) != HV_TRUE assert failure!!! return %s!!!", #expression, #ret);\
  82. return ret; \
  83. } \
  84. }while(0)
  85. #define HV_ASSERT_TRUE_RET_NO_LOG(expression, ret)\
  86. do \
  87. { \
  88. if (HV_TRUE != (expression)) \
  89. { \
  90. return ret; \
  91. } \
  92. }while(0)
  93. #define HV_ASSERT_SUCCESS(expression) \
  94. do \
  95. { \
  96. if (HV_SUCCESS != (expression)) \
  97. { \
  98. HV_LOG_INFO(DEFAULT,"(%s) != HV_SUCCESS assert failure!!!", #expression);\
  99. return HV_FAILURE; \
  100. } \
  101. }while(0)
  102. #define HV_ASSERT_PEEK_SUCCESS(expression) \
  103. do \
  104. { \
  105. if (HV_SUCCESS != (expression)) \
  106. { \
  107. HV_LOG_INFO(DEFAULT,"peek HV_SUCCESS but (%s) != HV_SUCCESS assert failure!!!", #expression);\
  108. } \
  109. }while(0)
  110. #define HV_ASSERT_SUCCESS_RET(expression, ret) \
  111. do \
  112. { \
  113. if (HV_SUCCESS != (expression)) \
  114. { \
  115. HV_LOG_INFO(DEFAULT,"(%s) != HV_SUCCESS assert failure!!! return %s!!!", #expression, #ret);\
  116. return ret; \
  117. } \
  118. }while(0)
  119. #define HV_ASSERT_SUCCESS_VOID(expression) \
  120. do \
  121. { \
  122. if (HV_SUCCESS != (expression)) \
  123. { \
  124. HV_LOG_INFO(DEFAULT,"(%s) != HV_SUCCESS assert failure!!!", #expression);\
  125. return; \
  126. } \
  127. }while(0)
  128. #define HV_ASSERT_PEEK_SUCCESS_VOID(expression) \
  129. do \
  130. { \
  131. if (HV_SUCCESS != (expression)) \
  132. { \
  133. HV_LOG_INFO(DEFAULT,"peek HV_SUCCESS but (%s) != HV_SUCCESS assert failure!!!", #expression);\
  134. } \
  135. }while(0)
  136. #endif