cmake: Do not build the chef_wrap example on OSX.
[platform/upstream/cmocka.git] / example / assert_module_test.c
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 <stdarg.h>
17 #include <stddef.h>
18 #include <setjmp.h>
19 #include <cmocka.h>
20
21 #include "assert_module.h"
22
23 extern void increment_value(int * const value);
24
25 /* This test case will fail but the assert is caught by run_tests() and the
26  * next test is executed. */
27 static void increment_value_fail(void **state) {
28     (void) state;
29
30     increment_value(NULL);
31 }
32
33 /* This test case succeeds since increment_value() asserts on the NULL
34  * pointer. */
35 static void increment_value_assert(void **state) {
36     (void) state;
37
38     expect_assert_failure(increment_value(NULL));
39 }
40
41 /* This test case fails since decrement_value() doesn't assert on a NULL
42  * pointer. */
43 static void decrement_value_fail(void **state) {
44     (void) state;
45
46     expect_assert_failure(decrement_value(NULL));
47 }
48
49 int main(void) {
50     const UnitTest tests[] = {
51         unit_test(increment_value_fail),
52         unit_test(increment_value_assert),
53         unit_test(decrement_value_fail),
54     };
55     return run_tests(tests);
56 }