"Fossies" - the Fresh Open Source Software Archive

Member "nss-pam-ldapd-0.9.12/tests/common.h" (15 Nov 2021, 3218 Bytes) of package /linux/privat/nss-pam-ldapd-0.9.12.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2    common.h - common test routines
    3    This file is part of the nss-pam-ldapd library.
    4 
    5    Copyright (C) 2011-2021 Arthur de Jong
    6 
    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.
   11 
   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.
   16 
   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
   20    02110-1301 USA
   21 */
   22 
   23 #ifndef TEST__COMMON_H
   24 #define TEST__COMMON_H 1
   25 
   26 #include <errno.h>
   27 #include <assert.h>
   28 
   29 #ifndef __ASSERT_FUNCTION
   30 #define __ASSERT_FUNCTION ""
   31 #endif /* not __ASSERT_FUNCTION */
   32 
   33 /* try to find the actual assert function */
   34 #ifndef HAVE___ASSERT_FAIL
   35 /* for Solaris: */
   36 #ifdef sun
   37 #if defined(HAVE___ASSERT_C99)
   38 #define __assert_fail(assertion, file, line, function)                      \
   39   __assert_c99(assertion, file, line, function)
   40 #elif defined(HAVE___ASSERT)
   41 #define __assert_fail(assertion, file, line, function)                      \
   42   __assert(assertion, file, line)
   43 #endif /* HAVE___ASSERT_C99 or HAVE___ASSERT */
   44 #endif /* sun */
   45 /* for FreeBSD: */
   46 #ifdef __FreeBSD__
   47 #define __assert_fail(assertion, file, line, function)                      \
   48   __assert(assertion, file, line, function)
   49 #endif
   50 #endif /* not HAVE___ASSERT_FAIL */
   51 
   52 /* extra assertion function that expects both strings to be the same
   53    (special macro because strcmp() can be a macro that turns ugly in assert) */
   54 #define assertstreq(str1, str2)                                             \
   55   (assertstreq_impl(str1, str2,                                             \
   56                     "strcmp(" __STRING(str1) ", " __STRING(str2) ") == 0",  \
   57                     __FILE__, __LINE__, __ASSERT_FUNCTION))
   58 
   59 static inline void assertstreq_impl(const char *str1, const char *str2,
   60                                     const char *assertion, const char *file,
   61                                     int line, const char *function)
   62 {
   63   if (strcmp(str1, str2) != 0)
   64     __assert_fail(assertion, file, line, function);
   65 }
   66 
   67 /* extra assertion function that expects expr to be valid and prints an
   68    error message that include errno otherwise */
   69 #define assertok(expr)                                                      \
   70   ((expr)                                                                   \
   71    ? (void) (0)                                                             \
   72    : __assertok_fail(__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
   73 
   74 
   75 static inline void __assertok_fail(const char *expr, const char *file,
   76                                    int line, const char *function)
   77 {
   78   char msg[120];
   79   snprintf(msg, sizeof(msg), "%s (errno=\"%s\")", expr, strerror(errno));
   80   __assert_fail(msg, file, line, function);
   81 }
   82 
   83 
   84 #endif /* not TEST__COMMON_H */