cmocka  1.1.1
include/cmocka_pbc.h
00001 /*
00002  * Copyright 2014 Luis Pabon, Jr.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * Programming by Contract is a programming methodology
00019  * which binds the caller and the function called to a
00020  * contract. The contract is represented using Hoare Triple:
00021  *      {P} C {Q}
00022  * where {P} is the precondition before executing command C,
00023  * and {Q} is the postcondition.
00024  *
00025  * See also:
00026  * http://en.wikipedia.org/wiki/Design_by_contract
00027  * http://en.wikipedia.org/wiki/Hoare_logic
00028  * http://dlang.org/dbc.html
00029  */
00030 #ifndef CMOCKA_PBC_H_
00031 #define CMOCKA_PBC_H_
00032 
00033 #if defined(UNIT_TESTING) || defined (DEBUG)
00034 
00035 #include <assert.h>
00036 
00037 /*
00038  * Checks caller responsibility against contract
00039  */
00040 #define REQUIRE(cond) assert(cond)
00041 
00042 /*
00043  * Checks function reponsability against contract.
00044  */
00045 #define ENSURE(cond) assert(cond)
00046 
00047 /*
00048  * While REQUIRE and ENSURE apply to functions, INVARIANT
00049  * applies to classes/structs.  It ensures that intances
00050  * of the class/struct are consistent. In other words,
00051  * that the instance has not been corrupted.
00052  */
00053 #define INVARIANT(invariant_fnc) do{ (invariant_fnc) } while (0);
00054 
00055 #else
00056 #define REQUIRE(cond) do { } while (0);
00057 #define ENSURE(cond) do { } while (0);
00058 #define INVARIANT(invariant_fnc) do{ } while (0);
00059 
00060 #endif /* defined(UNIT_TESTING) || defined (DEBUG) */
00061 #endif /* CMOCKA_PBC_H_ */
00062