2 Unix SMB/CIFS implementation.
6 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
25 static bool test_string_sub_simple(struct torture_context
*tctx
)
28 safe_strcpy(tmp
, "foobar", sizeof(tmp
));
29 string_sub(tmp
, "foo", "bar", sizeof(tmp
));
30 torture_assert_str_equal(tctx
, tmp
, "barbar", "invalid sub");
34 static bool test_string_sub_multiple(struct torture_context
*tctx
)
37 safe_strcpy(tmp
, "fooblafoo", sizeof(tmp
));
38 string_sub(tmp
, "foo", "bar", sizeof(tmp
));
39 torture_assert_str_equal(tctx
, tmp
, "barblabar", "invalid sub");
43 static bool test_string_sub_longer(struct torture_context
*tctx
)
46 safe_strcpy(tmp
, "foobla", sizeof(tmp
));
47 string_sub(tmp
, "foo", "blie", sizeof(tmp
));
48 torture_assert_str_equal(tctx
, tmp
, "bliebla", "invalid sub");
52 static bool test_string_sub_shorter(struct torture_context
*tctx
)
55 safe_strcpy(tmp
, "foobla", sizeof(tmp
));
56 string_sub(tmp
, "foo", "bl", sizeof(tmp
));
57 torture_assert_str_equal(tctx
, tmp
, "blbla", "invalid sub");
61 static bool test_string_sub_special_char(struct torture_context
*tctx
)
64 safe_strcpy(tmp
, "foobla", sizeof(tmp
));
65 string_sub(tmp
, "foo", "%b;l", sizeof(tmp
));
66 torture_assert_str_equal(tctx
, tmp
, "_b_lbla", "invalid sub");
70 static bool test_string_sub_talloc_simple(struct torture_context
*tctx
)
74 t
= string_sub_talloc(tctx
, "foobla", "foo", "bl");
76 torture_assert_str_equal(tctx
, t
, "blbla", "invalid sub");
81 static bool test_string_sub_talloc_multiple(struct torture_context
*tctx
)
85 t
= string_sub_talloc(tctx
, "fooblafoo", "foo", "aapnootmies");
87 torture_assert_str_equal(tctx
, t
, "aapnootmiesblaaapnootmies",
95 struct torture_suite
*torture_local_util_str(TALLOC_CTX
*mem_ctx
)
97 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "STR");
99 torture_suite_add_simple_test(suite
, "string_sub_simple",
100 test_string_sub_simple
);
102 torture_suite_add_simple_test(suite
, "string_sub_multiple",
103 test_string_sub_multiple
);
105 torture_suite_add_simple_test(suite
, "string_sub_shorter",
106 test_string_sub_shorter
);
108 torture_suite_add_simple_test(suite
, "string_sub_longer",
109 test_string_sub_longer
);
111 torture_suite_add_simple_test(suite
, "string_sub_special_chars",
112 test_string_sub_special_char
);
114 torture_suite_add_simple_test(suite
, "string_sub_talloc_simple",
115 test_string_sub_talloc_simple
);
117 torture_suite_add_simple_test(suite
, "string_sub_talloc_multiple",
118 test_string_sub_talloc_multiple
);