s3: Avoid a thundering herd in g_lock_unlock
[Samba.git] / lib / util / tests / str.c
blob3bd6a02fdc28ba384ff250e1c0e9640a194bb137
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"
25 static bool test_string_sub_simple(struct torture_context *tctx)
27 char tmp[100];
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");
31 return true;
34 static bool test_string_sub_multiple(struct torture_context *tctx)
36 char tmp[100];
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");
40 return true;
43 static bool test_string_sub_longer(struct torture_context *tctx)
45 char tmp[100];
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");
49 return true;
52 static bool test_string_sub_shorter(struct torture_context *tctx)
54 char tmp[100];
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");
58 return true;
61 static bool test_string_sub_special_char(struct torture_context *tctx)
63 char tmp[100];
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");
67 return true;
70 static bool test_string_sub_talloc_simple(struct torture_context *tctx)
72 char *t;
74 t = string_sub_talloc(tctx, "foobla", "foo", "bl");
76 torture_assert_str_equal(tctx, t, "blbla", "invalid sub");
78 return true;
81 static bool test_string_sub_talloc_multiple(struct torture_context *tctx)
83 char *t;
85 t = string_sub_talloc(tctx, "fooblafoo", "foo", "aapnootmies");
87 torture_assert_str_equal(tctx, t, "aapnootmiesblaaapnootmies",
88 "invalid sub");
90 return true;
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);
120 return suite;