2
common.h - common test routines
3
This file is part of the nss-pam-ldapd library.
5
Copyright (C) 2011 Arthur de Jong
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public
9
License as published by the Free Software Foundation; either
10
version 2.1 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
#ifndef TEST__COMMON_H
24
#define TEST__COMMON_H 1
28
#ifndef __ASSERT_FUNCTION
29
#define __ASSERT_FUNCTION ""
30
#endif /* not __ASSERT_FUNCTION */
32
/* try to find the actual assert function */
33
#ifndef HAVE___ASSERT_FAIL
35
#define __assert_fail(assertion,file,line,function) __assert(assertion,file,line)
36
#endif /* not HAVE___ASSERT_FAIL */
38
/* extra assertion function that epxects both strings to be the same
39
(special macro because strcmp() can be a macro that turns ugly in assert) */
40
#define assertstreq(str1,str2) \
41
(assertstreq_impl(str1,str2,"strcmp(" __STRING(str1) "," __STRING(str2) ")==0", \
42
__FILE__, __LINE__, __ASSERT_FUNCTION))
44
static inline void assertstreq_impl(const char *str1,const char *str2,
45
const char *assertion,const char *file,
46
int line,const char *function)
48
if (strcmp(str1,str2)!=0)
49
__assert_fail(assertion,file,line,function);
52
/* extra assertion function that expects expr to be valid and prints an
53
error message that include errno otherwise */
54
#define assertok(expr) \
57
: __assertok_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION))
60
static inline void __assertok_fail(const char *expr,const char *file,
61
int line,const char *function)
64
snprintf(msg,sizeof(msg),"%s (errno=\"%s\")",expr,strerror(errno));
65
__assert_fail(msg,file,line,function);
69
#endif /* not TEST__COMMON_H */