]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test-job-type.c
relicense to LGPLv2.1 (with exceptions)
[thirdparty/systemd.git] / src / test-job-type.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ffba6fe 2
a7334b09
LP
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
a7334b09
LP
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
a7334b09 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
a7334b09
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
1ffba6fe
LP
22#include <stdio.h>
23#include <errno.h>
24#include <string.h>
25#include <unistd.h>
26
27#include "job.h"
28
29int main(int argc, char*argv[]) {
30 JobType a, b, c, d, e, f, g;
31
32 for (a = 0; a < _JOB_TYPE_MAX; a++)
33 for (b = 0; b < _JOB_TYPE_MAX; b++) {
34
5cb5a6ff 35 if (!job_type_is_mergeable(a, b))
1ffba6fe
LP
36 printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b));
37
38 for (c = 0; c < _JOB_TYPE_MAX; c++) {
39
40 /* Verify transitivity of mergeability
41 * of job types */
5cb5a6ff
LP
42 assert(!job_type_is_mergeable(a, b) ||
43 !job_type_is_mergeable(b, c) ||
44 job_type_is_mergeable(a, c));
1ffba6fe
LP
45
46 d = a;
47 if (job_type_merge(&d, b) >= 0) {
48
49 printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(d));
50
51 /* Verify that merged entries can be
52 * merged with the same entries they
96d4ce01 53 * can be merged with separately */
5cb5a6ff
LP
54 assert(!job_type_is_mergeable(a, c) || job_type_is_mergeable(d, c));
55 assert(!job_type_is_mergeable(b, c) || job_type_is_mergeable(d, c));
1ffba6fe
LP
56
57 /* Verify that if a merged
35b8ca3a 58 * with b is not mergeable with
1ffba6fe
LP
59 * c then either a or b is not
60 * mergeable with c either. */
5cb5a6ff 61 assert(job_type_is_mergeable(d, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
1ffba6fe
LP
62
63 e = b;
64 if (job_type_merge(&e, c) >= 0) {
65
66 /* Verify associativity */
67
68 f = d;
69 assert(job_type_merge(&f, c) == 0);
70
71 g = e;
72 assert(job_type_merge(&g, a) == 0);
73
74 assert(f == g);
75
76 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));
77 }
78 }
79 }
80 }
81
82
83 return 0;
84}