OpenVPN
assert_module.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Google Inc.
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 <assert.h>
17 
18 #include "assert_module.h"
19 
20 /* If unit testing is enabled override assert with mock_assert(). */
21 #ifdef UNIT_TESTING
22 extern void mock_assert(const int result, const char* const expression,
23  const char * const file, const int line);
24 #undef assert
25 #define assert(expression) \
26  mock_assert(((expression) ? 1 : 0), #expression, __FILE__, __LINE__);
27 #endif /* UNIT_TESTING */
28 
29 void increment_value(int * const value) {
30  assert(value);
31  (*value) ++;
32 }
33 
34 void decrement_value(int * const value) {
35  if (value) {
36  (*value) --;
37  }
38 }
void mock_assert(const int result, const char *const expression, const char *const file, const int line)
Function to replace assert(3) in tested code.
Definition: cmocka.c:1520
void increment_value(int *const value)
Definition: assert_module.c:29
void decrement_value(int *const value)
Definition: assert_module.c:34