]>
git.saurik.com Git - apple/mdnsresponder.git/blob - unittests/unittest.h
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.
23 #include "unittest_common.h"
33 typedef struct __test_item_
35 struct __test_item_
* next
;
45 #define UNITTEST_HEADER(X) int X() { int __success = 1; __test_item* __i = NULL;
47 #define UNITTEST_GROUP(X) { printf("== %s ==\n", #X); __success = X() && __success; }
48 #define UNITTEST_TEST(X) { printf("%s: ", #X); fflush(NULL); __success = X() && __success; }
50 int _unittest_assert_i(const int condition
, const int i
, const char * const conditionStr
,
51 const char * const filename
, const unsigned int linenum
,
52 const char * const functionname
, __test_item
** __i
, int * const __success
);
53 #define UNITTEST_ASSERTI(X,I) (_unittest_assert_i((X)!=0, (I), #X, __FILE__, __LINE__, __func__, &__i, &__success))
54 #define UNITTEST_ASSERT(X) UNITTEST_ASSERTI(X, -1)
55 #define UNITTEST_ASSERTI_RETURN(X,I) { if (!UNITTEST_ASSERTI(X,I)) goto __unittest_footer__; }
56 #define UNITTEST_ASSERT_RETURN(X) UNITTEST_ASSERTI_RETURN(X, -1)
58 void _unittest_print_list(__test_item
* __i
);
59 #define UNITTEST_FOOTER goto __unittest_footer__; __unittest_footer__: printf("\n"); fflush(NULL); _unittest_print_list(__i); return __success; }
61 #define UNITTEST_MAIN int main (int argc, char** argv) \
64 signal(SIGPIPE, SIG_IGN); \
66 unlink("unittest_success"); \
69 printf("unit test FAILED\n"); \
72 fp = fopen("unittest_success", "w"); \
74 fprintf(fp, "unit test %s\n", "SUCCEEDED"); \
76 printf("unit test SUCCESS\n"); \
80 printf("run leaks now\n"); \
81 read(STDIN_FILENO, &c, 1); \
85 #define UNITTEST_SENDDNSMESSAGE mStatus mDNSSendDNSMessage(mDNS *const m, DNSMessage *const msg, mDNSu8 *end, \
86 mDNSInterfaceID InterfaceID, UDPSocket *src, const mDNSAddr *dst, \
87 mDNSIPPort dstport, TCPSocket *sock, DomainAuthInfo *authInfo, \
88 mDNSBool useBackgroundTrafficClass) \
93 (void)(InterfaceID); \
99 (void)(useBackgroundTrafficClass); \
103 #define UNITTEST_SETSOCKOPT void mDNSPlatformSetSocktOpt(void *sockCxt, mDNSTransport_Type transType, \
104 mDNSAddr_Type addrType, const DNSQuestion *q) \
113 #define UNITTEST_UDPCLOSE void mDNSPlatformUDPClose(UDPSocket *sock) \
118 #define UNITTEST_FAIL_ASSERT { assert(((void*)__func__) == 0); }
124 #endif // ndef _UNITTEST_H_