3 util_str_escape testing
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2017
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "torture/torture.h"
23 #include "torture/local/proto.h"
24 #include "lib/util/util_str_escape.h"
26 static bool test_log_escape_empty_string(struct torture_context
*tctx
)
28 char *result
= log_escape( tctx
, "");
29 torture_assert_str_equal(tctx
, result
, "", "Empty string handling");
33 static bool test_log_escape_null_string(struct torture_context
*tctx
)
35 char *result
= log_escape( tctx
, NULL
);
36 torture_assert(tctx
, (result
== NULL
), "Empty string handling");
40 static bool test_log_escape_plain_string(struct torture_context
*tctx
)
42 const char *input
= "a plain string with no escapable characters";
43 const char *expected
= "a plain string with no escapable characters";
45 char *result
= log_escape( tctx
, input
);
46 torture_assert_str_equal(tctx
, result
, expected
,
47 "Plain string handling");
51 static bool test_log_escape_string(struct torture_context
*tctx
)
53 const char *input
= "\a\b\f\n\r\t\v\\\x01";
54 const char *expected
= "\\a\\b\\f\\n\\r\\t\\v\\\\\\x01";
56 char *result
= log_escape( tctx
, input
);
57 torture_assert_str_equal(tctx
, result
, expected
,
58 "Escapable characters in string");
62 static bool test_log_escape_hex_string(struct torture_context
*tctx
)
64 const char *input
= "\x01\x1F ";
65 const char *expected
= "\\x01\\x1F ";
67 char *result
= log_escape( tctx
, input
);
68 torture_assert_str_equal(tctx
, result
, expected
,
72 struct torture_suite
*torture_local_util_str_escape(TALLOC_CTX
*mem_ctx
)
74 struct torture_suite
*suite
= torture_suite_create(mem_ctx
,
77 torture_suite_add_simple_test(suite
, "log_escape_empty_string",
78 test_log_escape_empty_string
);
79 torture_suite_add_simple_test(suite
, "log_escape_null_string",
80 test_log_escape_null_string
);
81 torture_suite_add_simple_test(suite
, "log_escape_plain_string",
82 test_log_escape_plain_string
);
83 torture_suite_add_simple_test(suite
, "log_escape_string",
84 test_log_escape_string
);
85 torture_suite_add_simple_test(suite
, "log_escape_hex_string",
86 test_log_escape_hex_string
);