2010-08-14 21:59:25 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2010-01-21 02:51:37 +03:00
2010-02-03 15:03:47 +03:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
2012-04-12 02:20:58 +04:00
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
2010-02-03 15:03:47 +03:00
( 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
2012-04-12 02:20:58 +04:00
Lesser General Public License for more details .
2010-02-03 15:03:47 +03:00
2012-04-12 02:20:58 +04:00
You should have received a copy of the GNU Lesser General Public License
2010-02-03 15:03:47 +03:00
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2010-01-21 02:51:37 +03:00
# include <stdio.h>
# include <errno.h>
# include <string.h>
# include <unistd.h>
# include "job.h"
int main ( int argc , char * argv [ ] ) {
JobType a , b , c , d , e , f , g ;
for ( a = 0 ; a < _JOB_TYPE_MAX ; a + + )
for ( b = 0 ; b < _JOB_TYPE_MAX ; b + + ) {
2010-01-23 03:52:57 +03:00
if ( ! job_type_is_mergeable ( a , b ) )
2010-01-21 02:51:37 +03:00
printf ( " Not mergeable: %s + %s \n " , job_type_to_string ( a ) , job_type_to_string ( b ) ) ;
for ( c = 0 ; c < _JOB_TYPE_MAX ; c + + ) {
/* Verify transitivity of mergeability
* of job types */
2010-01-23 03:52:57 +03:00
assert ( ! job_type_is_mergeable ( a , b ) | |
! job_type_is_mergeable ( b , c ) | |
job_type_is_mergeable ( a , c ) ) ;
2010-01-21 02:51:37 +03:00
d = a ;
if ( job_type_merge ( & d , b ) > = 0 ) {
printf ( " %s + %s = %s \n " , job_type_to_string ( a ) , job_type_to_string ( b ) , job_type_to_string ( d ) ) ;
/* Verify that merged entries can be
* merged with the same entries they
2010-09-03 18:30:48 +04:00
* can be merged with separately */
2010-01-23 03:52:57 +03:00
assert ( ! job_type_is_mergeable ( a , c ) | | job_type_is_mergeable ( d , c ) ) ;
assert ( ! job_type_is_mergeable ( b , c ) | | job_type_is_mergeable ( d , c ) ) ;
2010-01-21 02:51:37 +03:00
/* Verify that if a merged
2011-02-21 17:32:17 +03:00
* with b is not mergeable with
2010-01-21 02:51:37 +03:00
* c then either a or b is not
* mergeable with c either . */
2010-01-23 03:52:57 +03:00
assert ( job_type_is_mergeable ( d , c ) | | ! job_type_is_mergeable ( a , c ) | | ! job_type_is_mergeable ( b , c ) ) ;
2010-01-21 02:51:37 +03:00
e = b ;
if ( job_type_merge ( & e , c ) > = 0 ) {
/* Verify associativity */
f = d ;
assert ( job_type_merge ( & f , c ) = = 0 ) ;
g = e ;
assert ( job_type_merge ( & g , a ) = = 0 ) ;
assert ( f = = g ) ;
printf ( " %s + %s + %s = %s \n " , job_type_to_string ( a ) , job_type_to_string ( b ) , job_type_to_string ( c ) , job_type_to_string ( d ) ) ;
}
}
}
}
return 0 ;
}