dcerpc-netlogon: improve NetrLogonGetCapabilities dissection
[wireshark-sm.git] / epan / test_epan.c
blob452c53211b1f0a5b7398ee191015aa52c5e20830
1 /*
2 * Wireshark - Network traffic analyzer
3 * By Gerald Combs <gerald@wireshark.org>
4 * Copyright 1998 Gerald Combs
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
9 #include "config.h"
11 #include "strutil.h"
12 #include <wsutil/utf8_entities.h>
15 * FIXME: LABEL_LENGTH includes the nul byte terminator.
16 * This is confusing but matches ITEM_LABEL_LENGTH.
18 #define LABEL_LENGTH 8
20 void test_label_strcat(void)
22 char label[LABEL_LENGTH];
23 const char *src;
24 size_t pos;
26 src = "ABCD";
27 pos = 0;
28 pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
29 g_assert_cmpstr(label, ==, "ABCD");
30 g_assert_cmpuint(pos, ==, 4);
32 src = "EFGH";
33 pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
34 g_assert_cmpstr(label, ==, "ABCDEFG");
35 g_assert_cmpuint(pos, ==, 8);
37 src = "IJKL";
38 pos = 7;
39 pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
40 g_assert_cmpstr(label, ==, "ABCDEFG");
41 g_assert_cmpuint(pos, ==, 11);
43 /* UTF-8 multibyte does not fit, do not truncate. */
44 src = "ABCDEF"UTF8_MIDDLE_DOT;
45 pos = 0;
46 pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
47 g_assert_cmpstr(label, ==, "ABCDEF");
48 g_assert_cmpuint(pos, ==, 8); /* Tried to write 8 bytes. */
51 void test_label_strcat_escape_whitespace(void)
53 char label[128];
54 const char *src, *dst;
55 size_t pos;
57 src = "ABCD\n\t\f\r\aE"UTF8_MIDDLE_DOT"Z";
58 dst = "ABCD\\n\\t\\f\\r\\aE"UTF8_MIDDLE_DOT"Z";
59 pos = ws_label_strcpy(label, sizeof(label), 0, src, 0);
60 g_assert_cmpstr(label, ==, dst);
61 g_assert_cmpuint(pos, ==, strlen(dst));
64 void test_label_escape_control(void)
66 char label[128];
67 const char *src, *dst;
68 size_t pos;
70 src = "ABCD \x04\x17\xC2\x80 EFG \xC2\x90 HIJ \xC2\x9F Z";
71 dst = "ABCD \\x04\\x17\\u0080 EFG \\u0090 HIJ \\u009F Z";
72 pos = ws_label_strcpy(label, sizeof(label), 0, src, 0);
73 g_assert_cmpstr(label, ==, dst);
74 g_assert_cmpuint(pos, ==, strlen(dst));
77 int main(int argc, char **argv)
79 int ret;
81 ws_log_init("test_proto", NULL);
83 g_test_init(&argc, &argv, NULL);
85 g_test_add_func("/label/strcat", test_label_strcat);
86 g_test_add_func("/label/escape_whitespace", test_label_strcat_escape_whitespace);
87 g_test_add_func("/label/escape_control", test_label_escape_control);
89 ret = g_test_run();
91 return ret;
95 * Editor modelines - https://www.wireshark.org/tools/modelines.html
97 * Local variables:
98 * c-basic-offset: 4
99 * tab-width: 8
100 * indent-tabs-mode: nil
101 * End:
103 * vi: set shiftwidth=4 tabstop=8 expandtab:
104 * :indentSize=4:tabSize=8:noTabs=true: