1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <string.h>
17 #include "functionalext.h"
18
19 /**
20 * @tc.name : memmem_0100
21 * @tc.desc : Normal value test, assert whether the address value of the return value is
22 * the created buffer address
23 * @tc.level : Level 0
24 */
memmem_0100(void)25 void memmem_0100(void)
26 {
27 const char buffer[] = "musl test";
28 const char cmp[] = "musl";
29 char *ptr = NULL;
30
31 for (int i = 0; i < sizeof(cmp) / sizeof(cmp[0]); i++) {
32 ptr = memmem(buffer, sizeof(buffer), cmp, i);
33 if (ptr == NULL) {
34 EXPECT_PTRNE("memmem_0100", ptr, NULL);
35 return;
36 }
37 EXPECT_PTREQ("memmem_0100", ptr, buffer);
38 }
39 }
40
41 /**
42 * @tc.name : memmem_0200
43 * @tc.desc : Assert whether the returned value of an invalid parameter is null
44 * @tc.level : Level 2
45 */
memmem_0200(void)46 void memmem_0200(void)
47 {
48 const char buffer[] = "musl test";
49 size_t buflen = sizeof(buffer) / sizeof(buffer[0]);
50 size_t errlen = buflen + 1;
51 char *ptr = NULL;
52
53 ptr = memmem(buffer, sizeof(buffer), "musl", errlen);
54 EXPECT_PTREQ("memmem_0200", ptr, NULL);
55
56 ptr = memmem(buffer, sizeof(buffer), "muls", 3);
57 EXPECT_PTREQ("memmem_0200", ptr, NULL);
58 }
59
main(void)60 int main(void)
61 {
62 memmem_0100();
63 memmem_0200();
64
65 return t_status;
66 }