• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define TEST_BUFFER_SIZE 128
20 #define TEST_DATA_LEN 2
21 
22 /**
23  * @tc.name      : memccpy_0100
24  * @tc.desc      : Copies a string until spaces or data is greater than the specified length
25  * @tc.level     : Level 0
26  */
memccpy_0100(void)27 void memccpy_0100(void)
28 {
29     const char src[TEST_BUFFER_SIZE] = "musl test";
30     char dest[TEST_BUFFER_SIZE] = "";
31     int i;
32     void *rev = memccpy(dest, src, ' ', TEST_DATA_LEN);
33     EXPECT_PTREQ("memccpy_0100", rev, NULL);
34     EXPECT_EQ("memccpy_0100", strlen(dest), TEST_DATA_LEN);
35     for (i = 0; i < TEST_DATA_LEN; i++) {
36         EXPECT_EQ("memccpy_0100", dest[i], src[i]);
37     }
38 
39     memset(dest, 0x0, sizeof(dest));
40     rev = memccpy(dest, src, ' ', sizeof(src));
41     EXPECT_PTRNE("memccpy_0100", rev, NULL);
42     EXPECT_EQ("memccpy_0100", strlen(dest), strlen("musl "));
43     for (i = 0; i < strlen("musl "); i++) {
44         EXPECT_EQ("memccpy_0100", dest[i], src[i]);
45     }
46 }
47 
48 /**
49  * @tc.name      : memccpy_0200
50  * @tc.desc      : Use a character not contained in the original string as the end position
51  *                 for processing the copied string
52  * @tc.level     : Level 0
53  */
memccpy_0200(void)54 void memccpy_0200(void)
55 {
56     const char src[TEST_BUFFER_SIZE] = "musl test";
57     char dest[TEST_BUFFER_SIZE] = "";
58     int i;
59     void *rev = memccpy(dest, src, 'A', strlen(src));
60     EXPECT_PTREQ("memccpy_0200", rev, NULL);
61     EXPECT_STREQ("memccpy_0200", dest, src);
62 }
63 
64 /**
65  * @tc.name      : memccpy_0300
66  * @tc.desc      : The length of the copied string is 0
67  * @tc.level     : Level 2
68  */
memccpy_0300(void)69 void memccpy_0300(void)
70 {
71     const char src[TEST_BUFFER_SIZE] = "musl test";
72     char dest[TEST_BUFFER_SIZE] = "";
73     int i;
74     void *rev = memccpy(dest, src, ' ', 0);
75     EXPECT_PTREQ("memccpy_0300", rev, NULL);
76     EXPECT_EQ("memccpy_0300", strlen(dest), 0);
77 }
78 
main(void)79 int main(void)
80 {
81     memccpy_0100();
82     memccpy_0200();
83     memccpy_0300();
84     return t_status;
85 }