FSTAssert.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. // Fails the current Objective-C method if the given condition is false.
  19. //
  20. // Unlike NSAssert, this macro is never compiled out if assertions are disabled.
  21. #define FSTAssert(condition, format, ...) \
  22. do { \
  23. if (!(condition)) { \
  24. FSTFail((format), ##__VA_ARGS__); \
  25. } \
  26. } while (0)
  27. // Fails the current C function if the given condition is false.
  28. //
  29. // Unlike NSCAssert, this macro is never compiled out if assertions are disabled.
  30. #define FSTCAssert(condition, format, ...) \
  31. do { \
  32. if (!(condition)) { \
  33. FSTCFail((format), ##__VA_ARGS__); \
  34. } \
  35. } while (0)
  36. // Unconditionally fails the current Objective-C method.
  37. //
  38. // This macro fails by calling [[NSAssertionHandler currentHandler] handleFailureInMethod]. It
  39. // also calls abort(3) in order to make this macro appear to never return, even though the call
  40. // to handleFailureInMethod itself never returns.
  41. #define FSTFail(format, ...) \
  42. do { \
  43. NSString *_file = [NSString stringWithUTF8String:__FILE__]; \
  44. NSString *_description = [NSString stringWithFormat:(format), ##__VA_ARGS__]; \
  45. [[NSAssertionHandler currentHandler] \
  46. handleFailureInMethod:_cmd \
  47. object:self \
  48. file:_file \
  49. lineNumber:__LINE__ \
  50. description:@"FIRESTORE INTERNAL ASSERTION FAILED: %@", _description]; \
  51. abort(); \
  52. } while (0)
  53. // Unconditionally fails the current C function.
  54. //
  55. // This macro fails by calling [[NSAssertionHandler currentHandler] handleFailureInFunction]. It
  56. // also calls abort(3) in order to make this macro appear to never return, even though the call
  57. // to handleFailureInFunction itself never returns.
  58. #define FSTCFail(format, ...) \
  59. do { \
  60. NSString *_file = [NSString stringWithUTF8String:__FILE__]; \
  61. NSString *_function = [NSString stringWithUTF8String:__PRETTY_FUNCTION__]; \
  62. NSString *_description = [NSString stringWithFormat:(format), ##__VA_ARGS__]; \
  63. [[NSAssertionHandler currentHandler] \
  64. handleFailureInFunction:_function \
  65. file:_file \
  66. lineNumber:__LINE__ \
  67. description:@"FIRESTORE INTERNAL ASSERTION FAILED: %@", _description]; \
  68. abort(); \
  69. } while (0)
  70. NS_ASSUME_NONNULL_END