chiark / gitweb /
extend examples a bit
[elogind.git] / test-job-type.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include <stdio.h>
4 #include <errno.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 #include "job.h"
9
10 int main(int argc, char*argv[]) {
11         JobType a, b, c, d, e, f, g;
12
13         for (a = 0; a < _JOB_TYPE_MAX; a++)
14                 for (b = 0; b < _JOB_TYPE_MAX; b++) {
15
16                         if (!job_type_is_mergeable(a, b))
17                                 printf("Not mergeable: %s + %s\n", job_type_to_string(a), job_type_to_string(b));
18
19                         for (c = 0; c < _JOB_TYPE_MAX; c++) {
20
21                                 /* Verify transitivity of mergeability
22                                  * of job types */
23                                 assert(!job_type_is_mergeable(a, b) ||
24                                        !job_type_is_mergeable(b, c) ||
25                                        job_type_is_mergeable(a, c));
26
27                                 d = a;
28                                 if (job_type_merge(&d, b) >= 0) {
29
30                                         printf("%s + %s = %s\n", job_type_to_string(a), job_type_to_string(b), job_type_to_string(d));
31
32                                         /* Verify that merged entries can be
33                                          * merged with the same entries they
34                                          * can be merged with seperately */
35                                         assert(!job_type_is_mergeable(a, c) || job_type_is_mergeable(d, c));
36                                         assert(!job_type_is_mergeable(b, c) || job_type_is_mergeable(d, c));
37
38                                         /* Verify that if a merged
39                                          * with b is not mergable with
40                                          * c then either a or b is not
41                                          * mergeable with c either. */
42                                         assert(job_type_is_mergeable(d, c) || !job_type_is_mergeable(a, c) || !job_type_is_mergeable(b, c));
43
44                                         e = b;
45                                         if (job_type_merge(&e, c) >= 0) {
46
47                                                 /* Verify associativity */
48
49                                                 f = d;
50                                                 assert(job_type_merge(&f, c) == 0);
51
52                                                 g = e;
53                                                 assert(job_type_merge(&g, a) == 0);
54
55                                                 assert(f == g);
56
57                                                 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));
58                                         }
59                                 }
60                         }
61                 }
62
63
64         return 0;
65 }