]>
git.saurik.com Git - apple/mdnsresponder.git/blob - unittests/unittest.c
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2015 Apple Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 int _unittest_assert_i(const int condition
, const int i
, const char * const conditionStr
,
21 const char * const filename
, const unsigned int linenum
,
22 const char * const functionname
, __test_item
** __i
, int * const __success
)
26 __test_item
* tba
= malloc(sizeof(__test_item
));
30 tba
->func
= functionname
;
31 tba
->s
= conditionStr
;
46 void _unittest_print_list(__test_item
* __i
)
48 __test_item
* __tmp
= NULL
;
51 __test_item
* __o
= __i
->next
;
60 printf("%s: In function `%s':\n%s:%d: error: failed UNITTEST_ASSERT", __i
->file
, __i
->func
, __i
->file
, __i
->line
);
61 if (__i
->iter_count
!= -1) printf(" at iteration %d", __i
->iter_count
);
62 printf(": %s\n", __i
->s
);
63 __test_item
* tbd
= __i
;
69 // test by building like:
70 // gcc -g -Wall -Werror -DTEST_UNITTEST_SCAFFOLD unittest.c
71 // #define TEST_UNITTEST_SCAFFOLD 1
72 #if TEST_UNITTEST_SCAFFOLD
74 // modify this test as necessary to test the scaffold
75 UNITTEST_HEADER(test1
)
80 UNITTEST_ASSERT(i
==j
);
81 UNITTEST_ASSERTI(j
==i
, k
);
82 UNITTEST_ASSERT(i
==i
);
83 UNITTEST_ASSERTI(j
==j
, k
);
84 UNITTEST_ASSERT_RETURN(j
==j
);
85 UNITTEST_ASSERTI_RETURN(j
==j
, k
);
88 UNITTEST_HEADER(test2
)
94 UNITTEST_HEADER(unittest_tests
)
99 UNITTEST_HEADER(run_tests
)
100 UNITTEST_GROUP(unittest_tests
)
105 #endif // TEST_UNITTEST_SCAFFOLD