8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / test / libc-tests / tests / priv_gettext / priv_gettext.c
blob4f99a8130d0de82d5afcc309093645f3ee7b4e50
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2015 Joyent, Inc.
16 #include <string.h>
17 #include <locale.h>
18 #include <assert.h>
19 #include <stdlib.h>
20 #include <priv.h>
23 * This tests priv_gettext(). The priv_gettext() function always falls back to
24 * the C locale if it can't find anything. To deal with that, we've defined a
25 * dummy translation for the zz_AA.UTF-8 locale which has a translation for the
26 * 'dtrace_kernel' privilege.
28 * Normally 'dtrace_kernel' has the following description:
30 * Allows DTrace kernel-level tracing.
32 * In the zz_AA.UTF-8 locale it has the following description:
34 * Ah Elbereth Gilthoniel
36 * We explicitly verify that things respect the global locale and per-thread
37 * locale.
40 static const char *def = "Allows DTrace kernel-level tracing.\n";
41 static const char *trans = "Ah Elbereth Gilthoniel\n";
43 static void
44 priv_verify(const char *exp)
46 char *res = priv_gettext("dtrace_kernel");
47 assert(res != NULL);
48 assert(strcmp(res, exp) == 0);
49 free(res);
52 int
53 main(void)
55 locale_t loc;
57 (void) setlocale(LC_ALL, "C");
58 priv_verify(def);
60 (void) setlocale(LC_ALL, "zz_AA.UTF-8");
61 priv_verify(trans);
63 (void) setlocale(LC_ALL, "C");
64 loc = newlocale(LC_MESSAGES_MASK, "zz_AA.UTF-8", NULL);
65 assert(loc != NULL);
66 priv_verify(def);
68 (void) uselocale(loc);
69 priv_verify(trans);
71 (void) uselocale(LC_GLOBAL_LOCALE);
72 priv_verify(def);
73 freelocale(loc);
75 (void) setlocale(LC_ALL, "zz_AA.UTF-8");
76 loc = newlocale(LC_MESSAGES_MASK, "C", NULL);
77 assert(loc != NULL);
78 priv_verify(trans);
80 (void) uselocale(loc);
81 priv_verify(def);
83 (void) uselocale(LC_GLOBAL_LOCALE);
84 priv_verify(trans);
85 freelocale(loc);
87 return (0);