ldb: version 1.1.27
[Samba.git] / lib / util / tests / str.c
blob6c234738ead0b3d0b8405e5187e20fd0d4588202
1 /*
2 Unix SMB/CIFS implementation.
4 util_str testing
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/>.
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "torture/local/proto.h"
26 static bool test_string_sub_simple(struct torture_context *tctx)
28 char tmp[100];
29 strlcpy(tmp, "foobar", sizeof(tmp));
30 string_sub(tmp, "foo", "bar", sizeof(tmp));
31 torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub");
32 return true;
35 static bool test_string_sub_multiple(struct torture_context *tctx)
37 char tmp[100];
38 strlcpy(tmp, "fooblafoo", sizeof(tmp));
39 string_sub(tmp, "foo", "bar", sizeof(tmp));
40 torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub");
41 return true;
44 static bool test_string_sub_longer(struct torture_context *tctx)
46 char tmp[100];
47 strlcpy(tmp, "foobla", sizeof(tmp));
48 string_sub(tmp, "foo", "blie", sizeof(tmp));
49 torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub");
50 return true;
53 static bool test_string_sub_shorter(struct torture_context *tctx)
55 char tmp[100];
56 strlcpy(tmp, "foobla", sizeof(tmp));
57 string_sub(tmp, "foo", "bl", sizeof(tmp));
58 torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub");
59 return true;
62 static bool test_string_sub_special_char(struct torture_context *tctx)
64 char tmp[100];
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");
68 return true;
71 static bool test_string_sub_talloc_simple(struct torture_context *tctx)
73 char *t;
75 t = string_sub_talloc(tctx, "foobla", "foo", "bl");
77 torture_assert_str_equal(tctx, t, "blbla", "invalid sub");
79 return true;
82 static bool test_string_sub_talloc_multiple(struct torture_context *tctx)
84 char *t;
86 t = string_sub_talloc(tctx, "fooblafoo", "foo", "aapnootmies");
88 torture_assert_str_equal(tctx, t, "aapnootmiesblaaapnootmies",
89 "invalid sub");
91 return true;
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);
121 return suite;