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