You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 lines
1.8 KiB

  1. /*
  2. * Copyright 2014 Luis Pabon, Jr.
  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. /*
  17. * Programming by Contract is a programming methodology
  18. * which binds the caller and the function called to a
  19. * contract. The contract is represented using Hoare Triple:
  20. * {P} C {Q}
  21. * where {P} is the precondition before executing command C,
  22. * and {Q} is the postcondition.
  23. *
  24. * See also:
  25. * http://en.wikipedia.org/wiki/Design_by_contract
  26. * http://en.wikipedia.org/wiki/Hoare_logic
  27. * http://dlang.org/dbc.html
  28. */
  29. #ifndef CMOCKA_PBC_H_
  30. #define CMOCKA_PBC_H_
  31. #if defined(UNIT_TESTING) || defined (DEBUG)
  32. #include <assert.h>
  33. /*
  34. * Checks caller responsibility against contract
  35. */
  36. #define REQUIRE(cond) assert(cond)
  37. /*
  38. * Checks function reponsability against contract.
  39. */
  40. #define ENSURE(cond) assert(cond)
  41. /*
  42. * While REQUIRE and ENSURE apply to functions, INVARIANT
  43. * applies to classes/structs. It ensures that intances
  44. * of the class/struct are consistent. In other words,
  45. * that the instance has not been corrupted.
  46. */
  47. #define INVARIANT(invariant_fnc) do{ (invariant_fnc) } while (0);
  48. #else
  49. #define REQUIRE(cond) do { } while (0);
  50. #define ENSURE(cond) do { } while (0);
  51. #define INVARIANT(invariant_fnc) do{ } while (0);
  52. #endif /* defined(UNIT_TESTING) || defined (DEBUG) */
  53. #endif /* CMOCKA_PBC_H_ */