text.c: use strncpy instead of strcpy for better security
[platform/upstream/libxkbcommon.git] / test / messages.c
1 /*
2  * Copyright © 2023 Pierre Le Marre <dev@wismill.eu>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23
24 #include "config.h"
25
26 #include <assert.h>
27 #include <stdlib.h>
28
29 #include "test.h"
30 #include "messages-codes.h"
31 #include "messages.h"
32
33 static void
34 test_message_get(void)
35 {
36     const struct xkb_message_entry* entry;
37     /* Invalid codes */
38     /* NOTE: 0 must not be a valid message code */
39     entry = xkb_message_get(0);
40     assert(entry == NULL);
41     entry = xkb_message_get(_XKB_LOG_MESSAGE_MIN_CODE - 1);
42     assert(entry == NULL);
43     entry = xkb_message_get(_XKB_LOG_MESSAGE_MAX_CODE + 1);
44     assert(entry == NULL);
45
46     /* Valid codes */
47     entry = xkb_message_get(_XKB_LOG_MESSAGE_MIN_CODE);
48     assert(entry != NULL);
49     entry = xkb_message_get(XKB_WARNING_CANNOT_INFER_KEY_TYPE);
50     assert(entry != NULL);
51     entry = xkb_message_get(XKB_ERROR_INVALID_SYNTAX);
52     assert(entry != NULL);
53     entry = xkb_message_get(XKB_WARNING_CONFLICTING_KEY_FIELDS);
54     assert(entry != NULL);
55     entry = xkb_message_get(_XKB_LOG_MESSAGE_MAX_CODE);
56     assert(entry != NULL);
57 }
58
59 int
60 main(void)
61 {
62     test_message_get();
63 }