2017-11-18 19:09:20 +03:00
/* SPDX-License-Identifier: LGPL-2.1+ */
2015-07-13 20:47:26 +03:00
/***
This file is part of systemd
Copyright 2015 Tom Gundersen
* * */
# include "bitmap.h"
int main ( int argc , const char * argv [ ] ) {
2015-07-31 19:56:35 +03:00
_cleanup_bitmap_free_ Bitmap * b = NULL , * b2 = NULL ;
2015-07-16 15:06:11 +03:00
Iterator it ;
2015-07-13 20:47:26 +03:00
unsigned n = ( unsigned ) - 1 , i = 0 ;
b = bitmap_new ( ) ;
assert_se ( b ) ;
assert_se ( bitmap_ensure_allocated ( & b ) = = 0 ) ;
bitmap_free ( b ) ;
b = NULL ;
assert_se ( bitmap_ensure_allocated ( & b ) = = 0 ) ;
assert_se ( bitmap_isset ( b , 0 ) = = false ) ;
assert_se ( bitmap_isset ( b , 1 ) = = false ) ;
assert_se ( bitmap_isset ( b , 256 ) = = false ) ;
assert_se ( bitmap_isclear ( b ) = = true ) ;
assert_se ( bitmap_set ( b , 0 ) = = 0 ) ;
assert_se ( bitmap_isset ( b , 0 ) = = true ) ;
assert_se ( bitmap_isclear ( b ) = = false ) ;
bitmap_unset ( b , 0 ) ;
assert_se ( bitmap_isset ( b , 0 ) = = false ) ;
assert_se ( bitmap_isclear ( b ) = = true ) ;
assert_se ( bitmap_set ( b , 1 ) = = 0 ) ;
assert_se ( bitmap_isset ( b , 1 ) = = true ) ;
assert_se ( bitmap_isclear ( b ) = = false ) ;
bitmap_unset ( b , 1 ) ;
assert_se ( bitmap_isset ( b , 1 ) = = false ) ;
assert_se ( bitmap_isclear ( b ) = = true ) ;
assert_se ( bitmap_set ( b , 256 ) = = 0 ) ;
assert_se ( bitmap_isset ( b , 256 ) = = true ) ;
assert_se ( bitmap_isclear ( b ) = = false ) ;
bitmap_unset ( b , 256 ) ;
assert_se ( bitmap_isset ( b , 256 ) = = false ) ;
assert_se ( bitmap_isclear ( b ) = = true ) ;
2015-07-17 19:30:41 +03:00
assert_se ( bitmap_set ( b , 32 ) = = 0 ) ;
bitmap_unset ( b , 0 ) ;
assert_se ( bitmap_isset ( b , 32 ) = = true ) ;
bitmap_unset ( b , 32 ) ;
BITMAP_FOREACH ( n , NULL , it )
assert_not_reached ( " NULL bitmap " ) ;
2015-07-13 20:47:26 +03:00
assert_se ( bitmap_set ( b , 0 ) = = 0 ) ;
assert_se ( bitmap_set ( b , 1 ) = = 0 ) ;
assert_se ( bitmap_set ( b , 256 ) = = 0 ) ;
2015-07-16 15:06:11 +03:00
BITMAP_FOREACH ( n , b , it ) {
2015-07-13 20:47:26 +03:00
assert_se ( n = = i ) ;
if ( i = = 0 )
i = 1 ;
else if ( i = = 1 )
i = 256 ;
else if ( i = = 256 )
i = ( unsigned ) - 1 ;
}
assert_se ( i = = ( unsigned ) - 1 ) ;
i = 0 ;
2015-07-16 15:06:11 +03:00
BITMAP_FOREACH ( n , b , it ) {
2015-07-13 20:47:26 +03:00
assert_se ( n = = i ) ;
if ( i = = 0 )
i = 1 ;
else if ( i = = 1 )
i = 256 ;
else if ( i = = 256 )
i = ( unsigned ) - 1 ;
}
assert_se ( i = = ( unsigned ) - 1 ) ;
2017-11-28 12:19:04 +03:00
b2 = bitmap_copy ( b ) ;
assert_se ( b2 ) ;
assert_se ( bitmap_equal ( b , b2 ) = = true ) ;
assert_se ( bitmap_equal ( b , b ) = = true ) ;
assert_se ( bitmap_equal ( b , NULL ) = = false ) ;
assert_se ( bitmap_equal ( NULL , b ) = = false ) ;
assert_se ( bitmap_equal ( NULL , NULL ) = = true ) ;
2015-07-13 20:47:26 +03:00
bitmap_clear ( b ) ;
assert_se ( bitmap_isclear ( b ) = = true ) ;
2017-11-28 12:19:04 +03:00
assert_se ( bitmap_equal ( b , b2 ) = = false ) ;
bitmap_free ( b2 ) ;
b2 = NULL ;
2015-07-13 20:47:26 +03:00
assert_se ( bitmap_set ( b , ( unsigned ) - 1 ) = = - ERANGE ) ;
2015-07-31 19:56:35 +03:00
bitmap_free ( b ) ;
b = NULL ;
assert_se ( bitmap_ensure_allocated ( & b ) = = 0 ) ;
assert_se ( bitmap_ensure_allocated ( & b2 ) = = 0 ) ;
assert_se ( bitmap_equal ( b , b2 ) ) ;
assert_se ( bitmap_set ( b , 0 ) = = 0 ) ;
bitmap_unset ( b , 0 ) ;
assert_se ( bitmap_equal ( b , b2 ) ) ;
2015-07-31 20:01:34 +03:00
assert_se ( bitmap_set ( b , 1 ) = = 0 ) ;
bitmap_clear ( b ) ;
assert_se ( bitmap_equal ( b , b2 ) ) ;
assert_se ( bitmap_set ( b , 0 ) = = 0 ) ;
assert_se ( bitmap_set ( b2 , 0 ) = = 0 ) ;
assert_se ( bitmap_equal ( b , b2 ) ) ;
2015-07-13 20:47:26 +03:00
return 0 ;
}