2013-07-05 08:25:26 +04:00
/***
This file is part of systemd
Copyright 2013 Zbigniew Jędrzejewski - Szmek
systemd 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 .
systemd 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 systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
# include <stdio.h>
# include <stdlib.h>
typedef const char * ( * lookup_t ) ( int ) ;
typedef int ( * reverse_t ) ( const char * ) ;
static inline void _test_table ( const char * name ,
lookup_t lookup ,
reverse_t reverse ,
2013-07-16 20:01:01 +04:00
int size ,
bool sparse ) {
2013-07-05 08:25:26 +04:00
int i ;
2013-07-16 20:01:01 +04:00
for ( i = - 1 ; i < size + 1 ; i + + ) {
2013-07-05 08:25:26 +04:00
const char * val = lookup ( i ) ;
2013-07-14 01:36:03 +04:00
int rev ;
2013-07-05 08:25:26 +04:00
if ( val )
rev = reverse ( val ) ;
2013-07-14 01:36:03 +04:00
else
rev = reverse ( " --no-such--value---- " ) ;
2013-07-05 08:25:26 +04:00
printf ( " %s: %d → %s → %d \n " , name , i , val , rev ) ;
2014-10-28 20:07:20 +03:00
assert_se ( ! ( i > = 0 & & i < size ?
sparse ? rev ! = i & & rev ! = - 1 : val = = NULL | | rev ! = i :
val ! = NULL | | rev ! = - 1 ) ) ;
2013-07-05 08:25:26 +04:00
}
}
# define test_table(lower, upper) \
2013-07-16 20:01:01 +04:00
_test_table ( STRINGIFY ( lower ) , lower # # _to_string , lower # # _from_string , _ # # upper # # _MAX , false )
2014-07-10 06:29:24 +04:00
# define test_table_sparse(lower, upper) \
_test_table ( STRINGIFY ( lower ) , lower # # _to_string , lower # # _from_string , _ # # upper # # _MAX , true )