Debian Codegraph @

libctf/testsuite/libctf-writable/ctf-nonroot-addition.c

raw
1 /* Make sure adding a non-root-visible type after adding a root-visible forward
2 adds a new type rather than promoting and returning the existing one. */
3
4 #include <ctf-api.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 int
10 main (int argc, char *argv[])
11 {
12 ctf_dict_t *fp;
13 ctf_id_t root, nonroot;
14 int err;
15
16 if ((fp = ctf_create (&err)) == NULL)
17 {
18 fprintf (stderr, "Cannot create: %s\n", ctf_errmsg (err));
19 return 1;
20 }
21
22 if ((root = ctf_add_forward (fp, CTF_ADD_ROOT, "foo", CTF_K_ENUM)) == CTF_ERR)
23 goto add_err;
24
25 if ((nonroot = ctf_add_enum (fp, CTF_ADD_NONROOT, "foo")) == CTF_ERR)
26 goto add_err;
27
28 if (nonroot == root)
29 fprintf (stderr, "Non-root addition should not promote root-visible forwards\n");
30 else
31 printf ("All done.\n");
32
33 ctf_dict_close (fp);
34 return 0;
35
36 add_err:
37 fprintf (stderr, "Cannot add: %s\n", ctf_errmsg (ctf_errno (fp)));
38 }