source: vendor/current/lib/util/tests/str.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 3.4 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 util_str testing
5
6 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
7
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.
12
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.
17
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/>.
20*/
21
22#include "includes.h"
23#include "torture/torture.h"
24#include "torture/local/proto.h"
25
26static bool test_string_sub_simple(struct torture_context *tctx)
27{
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;
33}
34
35static bool test_string_sub_multiple(struct torture_context *tctx)
36{
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;
42}
43
44static bool test_string_sub_longer(struct torture_context *tctx)
45{
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;
51}
52
53static bool test_string_sub_shorter(struct torture_context *tctx)
54{
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;
60}
61
62static bool test_string_sub_special_char(struct torture_context *tctx)
63{
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;
69}
70
71static bool test_string_sub_talloc_simple(struct torture_context *tctx)
72{
73 char *t;
74
75 t = string_sub_talloc(tctx, "foobla", "foo", "bl");
76
77 torture_assert_str_equal(tctx, t, "blbla", "invalid sub");
78
79 return true;
80}
81
82static bool test_string_sub_talloc_multiple(struct torture_context *tctx)
83{
84 char *t;
85
86 t = string_sub_talloc(tctx, "fooblafoo", "foo", "aapnootmies");
87
88 torture_assert_str_equal(tctx, t, "aapnootmiesblaaapnootmies",
89 "invalid sub");
90
91 return true;
92}
93
94
95
96struct torture_suite *torture_local_util_str(TALLOC_CTX *mem_ctx)
97{
98 struct torture_suite *suite = torture_suite_create(mem_ctx, "str");
99
100 torture_suite_add_simple_test(suite, "string_sub_simple",
101 test_string_sub_simple);
102
103 torture_suite_add_simple_test(suite, "string_sub_multiple",
104 test_string_sub_multiple);
105
106 torture_suite_add_simple_test(suite, "string_sub_shorter",
107 test_string_sub_shorter);
108
109 torture_suite_add_simple_test(suite, "string_sub_longer",
110 test_string_sub_longer);
111
112 torture_suite_add_simple_test(suite, "string_sub_special_chars",
113 test_string_sub_special_char);
114
115 torture_suite_add_simple_test(suite, "string_sub_talloc_simple",
116 test_string_sub_talloc_simple);
117
118 torture_suite_add_simple_test(suite, "string_sub_talloc_multiple",
119 test_string_sub_talloc_multiple);
120
121 return suite;
122}
Note: See TracBrowser for help on using the repository browser.