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"
24 #include "torture/local/proto.h"
26 static bool test_string_sub_simple(struct torture_context
*tctx
)
29 strlcpy(tmp
, "foobar", sizeof(tmp
));
30 string_sub(tmp
, "foo", "bar", sizeof(tmp
));
31 torture_assert_str_equal(tctx
, tmp
, "barbar", "invalid sub");
35 static bool test_string_sub_multiple(struct torture_context
*tctx
)
38 strlcpy(tmp
, "fooblafoo", sizeof(tmp
));
39 string_sub(tmp
, "foo", "bar", sizeof(tmp
));
40 torture_assert_str_equal(tctx
, tmp
, "barblabar", "invalid sub");
44 static bool test_string_sub_longer(struct torture_context
*tctx
)
47 strlcpy(tmp
, "foobla", sizeof(tmp
));
48 string_sub(tmp
, "foo", "blie", sizeof(tmp
));
49 torture_assert_str_equal(tctx
, tmp
, "bliebla", "invalid sub");
53 static bool test_string_sub_shorter(struct torture_context
*tctx
)
56 strlcpy(tmp
, "foobla", sizeof(tmp
));
57 string_sub(tmp
, "foo", "bl", sizeof(tmp
));
58 torture_assert_str_equal(tctx
, tmp
, "blbla", "invalid sub");
62 static bool test_string_sub_special_char(struct torture_context
*tctx
)
65 strlcpy(tmp
, "foobla", sizeof(tmp
));
66 string_sub(tmp
, "foo", "%b;l", sizeof(tmp
));
67 torture_assert_str_equal(tctx
, tmp
, "_b_lbla", "invalid sub");
71 static bool test_string_sub_talloc_simple(struct torture_context
*tctx
)
75 t
= string_sub_talloc(tctx
, "foobla", "foo", "bl");
77 torture_assert_str_equal(tctx
, t
, "blbla", "invalid sub");
82 static bool test_string_sub_talloc_multiple(struct torture_context
*tctx
)
86 t
= string_sub_talloc(tctx
, "fooblafoo", "foo", "aapnootmies");
88 torture_assert_str_equal(tctx
, t
, "aapnootmiesblaaapnootmies",
96 struct torture_suite
*torture_local_util_str(TALLOC_CTX
*mem_ctx
)
98 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "str");
100 torture_suite_add_simple_test(suite
, "string_sub_simple",
101 test_string_sub_simple
);
103 torture_suite_add_simple_test(suite
, "string_sub_multiple",
104 test_string_sub_multiple
);
106 torture_suite_add_simple_test(suite
, "string_sub_shorter",
107 test_string_sub_shorter
);
109 torture_suite_add_simple_test(suite
, "string_sub_longer",
110 test_string_sub_longer
);
112 torture_suite_add_simple_test(suite
, "string_sub_special_chars",
113 test_string_sub_special_char
);
115 torture_suite_add_simple_test(suite
, "string_sub_talloc_simple",
116 test_string_sub_talloc_simple
);
118 torture_suite_add_simple_test(suite
, "string_sub_talloc_multiple",
119 test_string_sub_talloc_multiple
);