eoktest.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. #pragma once
  12. // Macros for asserting and checking whether an Acad::ErrorStatus is eOk.
  13. //
  14. // eOkVerify always checks for whether the expression is eOk and
  15. // returns TRUE if it is, FALSE if it isn't.
  16. //
  17. // In addition, in debug builds, eOkVerify puts up a message box when
  18. // the expression does not equal eOk.
  19. //
  20. // You might be thinking it would be nice to have an eOkAssert()
  21. // macro, which doesn't evaluate the expression in release builds,
  22. // similar to the ASSERT macro. That would avoid the overhead of
  23. // computing the boolean result when it's not needed. But this
  24. // seemed dangerous, in that it would be easy for someone to put
  25. // needed code inside eOkAssert, and that code would not get called
  26. // in release builds. Also, the compiler already "optimizes out"
  27. // expressions whose results are not used. So eOkVerify() doesn't
  28. // add overhead in release builds anyway.
  29. #include "adesk.h"
  30. #include "acadstrc.h"
  31. #include "acestext.h"
  32. #include "acutasrt.h"
  33. #if defined(_ADESK_WINDOWS_)
  34. #include <tchar.h>
  35. #endif
  36. #ifdef NDEBUG
  37. #define eOkTest(x) ((x) == Acad::eOk)
  38. #define eOkCheck(x) (x)
  39. #define eOkVerify(x) ((x) == Acad::eOk)
  40. #else // else not NDEBUG
  41. // For use by eoktest.h only!
  42. inline Acad::ErrorStatus eOkCheck_imp(
  43. const ACHAR *condition,
  44. const ACHAR *fname,
  45. int lineno,
  46. Acad::ErrorStatus es)
  47. {
  48. if (es != Acad::eOk) {
  49. acutAssertMessage(condition, fname, lineno,
  50. acadErrorStatusText(es));
  51. }
  52. return es;
  53. }
  54. /// <summary>
  55. /// Evaluates to true if value is Acad::eOk, otherwise evaluates to false.
  56. /// </summary>
  57. #define eOkTest(x) ((x) == Acad::eOk)
  58. /// <summary>
  59. /// Asserts if value is not Acad::eOk. Evaluates to the value.
  60. /// </summary>
  61. #define eOkCheck(x) eOkCheck_imp(_T(# x), _T(__FILE__), __LINE__, (x))
  62. /// <summary>
  63. /// Asserts if value is not Acad::eOk. Evaluates to true if value is Acad::eOk
  64. /// otherwise evalutes to false.
  65. /// </summary>
  66. #define eOkVerify(x) (eOkCheck(x) == Acad::eOk)
  67. #endif // NDEBUG