diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2011-03-17 22:02:45 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2011-03-17 22:02:45 +0100 |
commit | 2927aaa0b3796443821fff5b9043faafe2ffd542 (patch) | |
tree | 51a473df88935b47d0d02acf9b3a18db835517c3 | |
parent | 6e8eef9c1636bfbeeed1a46c4af8221f285c6a90 (diff) |
put all assertion functions and compatibility code into one header file
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1397 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/common.h | 69 | ||||
-rw-r--r-- | tests/test_cfg.c | 24 | ||||
-rw-r--r-- | tests/test_common.c | 11 | ||||
-rw-r--r-- | tests/test_expr.c | 24 | ||||
-rw-r--r-- | tests/test_getpeercred.c | 21 | ||||
-rw-r--r-- | tests/test_myldap.c | 24 | ||||
-rw-r--r-- | tests/test_tio.c | 23 |
9 files changed, 90 insertions, 111 deletions
diff --git a/configure.ac b/configure.ac index 5b4644a..2a0cede 100644 --- a/configure.ac +++ b/configure.ac @@ -292,6 +292,7 @@ AC_SEARCH_LIBS(socket,socket) AC_CHECK_FUNCS([strcasecmp strncasecmp strchr strcspn strspn strtol]) AC_CHECK_FUNCS([malloc realloc]) AC_FUNC_FORK +AC_CHECK_FUNCS(__assert_fail) # checks for types AC_TYPE_MODE_T diff --git a/tests/Makefile.am b/tests/Makefile.am index 696600d..cc5042a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -76,6 +76,6 @@ test_common_LDADD = ../nslcd/log.o ../nslcd/common.o ../nslcd/cfg.o \ ../nslcd/alias.o ../nslcd/ether.o ../nslcd/group.o \ ../nslcd/host.o ../nslcd/netgroup.o ../nslcd/network.o \ ../nslcd/passwd.o ../nslcd/protocol.o ../nslcd/rpc.o \ - ../nslcd/service.o ../nslcd/shadow.o \ + ../nslcd/service.o ../nslcd/shadow.o ../nslcd/attmap.o \ ../nslcd/myldap.o @nslcd_LIBS@ ../common/libtio.a \ - ../common/libdict.a ../compat/libcompat.a + ../common/libdict.a ../common/libexpr.a ../compat/libcompat.a diff --git a/tests/common.h b/tests/common.h new file mode 100644 index 0000000..68490e6 --- /dev/null +++ b/tests/common.h @@ -0,0 +1,69 @@ +/* + common.h - common test routines + This file is part of the nss-pam-ldapd library. + + Copyright (C) 2011 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#ifndef TEST__COMMON_H +#define TEST__COMMON_H 1 + +#include <errno.h> + +#ifndef __ASSERT_FUNCTION +#define __ASSERT_FUNCTION "" +#endif /* not __ASSERT_FUNCTION */ + +/* try to find the actual assert function */ +#ifndef HAVE___ASSERT_FAIL +/* for Solaris: */ +#define __assert_fail(assertion,file,line,function) __assert(assertion,file,line) +#endif /* not HAVE___ASSERT_FAIL */ + +/* extra assertion function that epxects both strings to be the same + (special macro because strcmp() can be a macro that turns ugly in assert) */ +#define assertstreq(str1,str2) \ + (assertstreq_impl(str1,str2,"strcmp(" __STRING(str1) "," __STRING(str2) ")==0", \ + __FILE__, __LINE__, __ASSERT_FUNCTION)) + +static inline void assertstreq_impl(const char *str1,const char *str2, + const char *assertion,const char *file, + int line,const char *function) +{ + if (strcmp(str1,str2)!=0) + __assert_fail(assertion,file,line,function); +} + +/* extra assertion function that expects expr to be valid and prints an + error message that include errno otherwise */ +#define assertok(expr) \ + ((expr) \ + ? (void) (0) \ + : __assertok_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION)) + + +static inline void __assertok_fail(const char *expr,const char *file, + int line,const char *function) +{ + char msg[120]; + snprintf(msg,sizeof(msg),"%s (errno=\"%s\")",expr,strerror(errno)); + __assert_fail(msg,file,line,function); +} + + +#endif /* not TEST__COMMON_H */ diff --git a/tests/test_cfg.c b/tests/test_cfg.c index dc558c2..810d024 100644 --- a/tests/test_cfg.c +++ b/tests/test_cfg.c @@ -2,7 +2,7 @@ test_cfg.c - simple test for the cfg module This file is part of the nss-pam-ldapd library. - Copyright (C) 2007, 2009 Arthur de Jong + Copyright (C) 2007, 2009, 2011 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -26,29 +26,11 @@ #include <string.h> #include <assert.h> +#include "common.h" + /* we include cfg.c because we want to test the static methods */ #include "nslcd/cfg.c" -#ifndef __ASSERT_FUNCTION -#define __ASSERT_FUNCTION "" -#endif /* not __ASSERT_FUNCTION */ - -#define assertstreq(str1,str2) \ - (assertstreq_impl(str1,str2,"strcmp(" __STRING(str1) "," __STRING(str2) ")==0", \ - __FILE__, __LINE__, __ASSERT_FUNCTION)) - -/* for Solaris: */ -#define __assert_fail(assertion,file,line,function) __assert(assertion,file,line) - -/* method for determening string equalness */ -static void assertstreq_impl(const char *str1,const char *str2, - const char *assertion,const char *file, - int line,const char *function) -{ - if (strcmp(str1,str2)!=0) - __assert_fail(assertion,file,line,function); -} - static void test_xstrdup(void) { static const char *foo="testString123"; diff --git a/tests/test_common.c b/tests/test_common.c index 4831815..092867b 100644 --- a/tests/test_common.c +++ b/tests/test_common.c @@ -2,7 +2,7 @@ test_common.c - simple test for the common module This file is part of the nss-pam-ldapd library. - Copyright (C) 2008, 2009 Arthur de Jong + Copyright (C) 2008, 2009, 2011 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -27,15 +27,6 @@ #include "nslcd/common.h" -/* this is a simple way to get this into an executable */ -const char **base_get_var(int UNUSED(map)) {return NULL;} -int *scope_get_var(int UNUSED(map)) {return NULL;} -const char **filter_get_var(int UNUSED(map)) {return NULL;} -const char **attmap_get_var(int UNUSED(map),const char UNUSED(*name)) {return NULL;} -const char *attmap_get_value(MYLDAP_ENTRY UNUSED(*entry),const char UNUSED(*attr),char UNUSED(*buffer),size_t UNUSED(buflen)) {return "";} -void *attmap_add_attributes(void UNUSED(*set),const char UNUSED(*attr)) {return NULL;} -const char *attmap_set_mapping(const char UNUSED(**var),const char UNUSED(*value)) {return NULL;} - static void test_isvalidname(void) { assert(isvalidname("arthur")); diff --git a/tests/test_expr.c b/tests/test_expr.c index dfc00cb..2032296 100644 --- a/tests/test_expr.c +++ b/tests/test_expr.c @@ -2,7 +2,7 @@ test_expr.c - simple tests for the expr module This file is part of the nss-pam-ldapd library. - Copyright (C) 2009 Arthur de Jong + Copyright (C) 2009, 2011 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -26,29 +26,11 @@ #include <string.h> #include <assert.h> +#include "common.h" + /* we include expr.c because we want to test the static methods */ #include "common/expr.c" -#ifndef __ASSERT_FUNCTION -#define __ASSERT_FUNCTION "" -#endif /* not __ASSERT_FUNCTION */ - -#define assertstreq(str1,str2) \ - (assertstreq_impl(str1,str2,"strcmp(" __STRING(str1) "," __STRING(str2) ")==0", \ - __FILE__, __LINE__, __ASSERT_FUNCTION)) - -/* for Solaris: */ -#define __assert_fail(assertion,file,line,function) __assert(assertion,file,line) - -/* method for determening string equalness */ -static void assertstreq_impl(const char *str1,const char *str2, - const char *assertion,const char *file, - int line,const char *function) -{ - if (strcmp(str1,str2)!=0) - __assert_fail(assertion,file,line,function); -} - static void test_parse_name(void) { char buffer[20]; diff --git a/tests/test_getpeercred.c b/tests/test_getpeercred.c index 13edf97..56bd611 100644 --- a/tests/test_getpeercred.c +++ b/tests/test_getpeercred.c @@ -2,7 +2,7 @@ test_getpeercred.c - simple test for the peercred module This file is part of the nss-pam-ldapd library. - Copyright (C) 2008 Arthur de Jong + Copyright (C) 2008, 2011 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -35,26 +35,11 @@ #endif /* HAVE_GRP_H */ #include <errno.h> +#include "common.h" + #include "compat/attrs.h" #include "compat/getpeercred.h" -#ifndef __ASSERT_FUNCTION -#define __ASSERT_FUNCTION "" -#endif /* not __ASSERT_FUNCTION */ - -#define assertok(expr) \ - ((expr) \ - ? (void) (0) \ - : __assertok_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION)) - -static void __assertok_fail(const char *expr,const char *file, - int line,const char *function) -{ - char msg[120]; - snprintf(msg,sizeof(msg),"%s (errno=\"%s\")",expr,strerror(errno)); - __assert_fail(msg,file,line,function); -} - /* create a named socket */ static int create_socket(const char *name) { diff --git a/tests/test_myldap.c b/tests/test_myldap.c index e292d50..6295118 100644 --- a/tests/test_myldap.c +++ b/tests/test_myldap.c @@ -2,7 +2,7 @@ test_myldap.c - simple test for the myldap module This file is part of the nss-pam-ldapd library. - Copyright (C) 2007, 2008, 2009 Arthur de Jong + Copyright (C) 2007, 2008, 2009, 2011 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -29,30 +29,12 @@ #include <assert.h> #include <signal.h> +#include "common.h" + #include "nslcd/log.h" #include "nslcd/cfg.h" #include "nslcd/myldap.h" -#ifndef __ASSERT_FUNCTION -#define __ASSERT_FUNCTION "" -#endif /* not __ASSERT_FUNCTION */ - -#define assertstreq(str1,str2) \ - (assertstreq_impl(str1,str2,"strcmp(" __STRING(str1) "," __STRING(str2) ")==0", \ - __FILE__, __LINE__, __ASSERT_FUNCTION)) - -/* for Solaris: */ -#define __assert_fail(assertion,file,line,function) __assert(assertion,file,line) - -/* method for determening string equalness */ -static void assertstreq_impl(const char *str1,const char *str2, - const char *assertion,const char *file, - int line,const char *function) -{ - if (strcmp(str1,str2)!=0) - __assert_fail(assertion,file,line,function); -} - struct worker_args { int id; }; diff --git a/tests/test_tio.c b/tests/test_tio.c index 0e2a3e8..212bdec 100644 --- a/tests/test_tio.c +++ b/tests/test_tio.c @@ -2,7 +2,7 @@ test_tio.c - simple test for the tio module This file is part of the nss-pam-ldapd library. - Copyright (C) 2007, 2008 Arthur de Jong + Copyright (C) 2007, 2008, 2011 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -33,25 +33,12 @@ #endif /* HAVE_STDINT_H */ #include <stdlib.h> #include <errno.h> +#include <unistd.h> +#include <fcntl.h> -#include "common/tio.h" - -#ifndef __ASSERT_FUNCTION -#define __ASSERT_FUNCTION "" -#endif /* not __ASSERT_FUNCTION */ - -#define assertok(expr) \ - ((expr) \ - ? (void) (0) \ - : __assertok_fail(__STRING(expr),__FILE__,__LINE__,__ASSERT_FUNCTION)) +#include "common.h" -static void __assertok_fail(const char *expr,const char *file, - int line,const char *function) -{ - char msg[120]; - snprintf(msg,sizeof(msg),"%s (errno=\"%s\")",expr,strerror(errno)); - __assert_fail(msg,file,line,function); -} +#include "common/tio.h" /* structure for passing arguments to helper (is a thread) */ struct helper_args { |