test-job-type.c revision 2eec67acbb00593e414549a7e5b35eb7dd776b1b
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
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 "job.h"
#include "unit.h"
#include "service.h"
unsigned i;
bool merged_ab;
/* fake a unit */
static Service s = {
.type = SERVICE_SIMPLE,
};
for (i = 0; i < ELEMENTSOF(test_states); i++) {
s.state = test_states[i];
printf("\nWith collapsing for service state %s\n"
for (a = 0; a < _JOB_TYPE_MAX_MERGING; a++) {
for (b = 0; b < _JOB_TYPE_MAX_MERGING; b++) {
ab = a;
if (!job_type_is_mergeable(a, b)) {
continue;
}
for (c = 0; c < _JOB_TYPE_MAX_MERGING; c++) {
/* Verify transitivity of mergeability of job types */
assert_se(!job_type_is_mergeable(a, b) ||
!job_type_is_mergeable(b, c) ||
job_type_is_mergeable(a, c));
/* Verify that merged entries can be merged with the same entries
* they can be merged with separately */
/* Verify that if a merged with b is not mergeable with c, then
* either a or b is not mergeable with c either. */
assert_se(job_type_is_mergeable(ab, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
bc = b;
if (job_type_merge_and_collapse(&bc, c, u) >= 0) {
/* Verify associativity */
a_bc = a;
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(ab_c));
}
}
}
}
}
return 0;
}