• 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 8
21 
22 /**
23  * @tc.name      : mempcpy_0100
24  * @tc.desc      : Verify strcasecmp process success. Copies the string into the array dest.
25  * @tc.level     : Level 0
26  */
mempcpy_0100(void)27 void mempcpy_0100(void)
28 {
29     const char src[TEST_BUFFER_SIZE] = "mempcpy_0100";
30     char dest[TEST_BUFFER_SIZE] = "";
31     void *rev = mempcpy(dest, src, strlen(src));
32     EXPECT_STREQ("mempcpy_0100", dest, "mempcpy_0100");
33 }
34 
35 /**
36  * @tc.name      : mempcpy_0200
37  * @tc.desc      : Verify strcasecmp process success. Copies the 8 consecutive characters starting with the 8th
38  *                 character in src into d.
39  * @tc.level     : Level 0
40  */
mempcpy_0200(void)41 void mempcpy_0200(void)
42 {
43     const char src[TEST_BUFFER_SIZE] = "mempcpy_0200test";
44     char dest[TEST_BUFFER_SIZE] = "";
45     void *rev = mempcpy(dest, src + TEST_DATA_LEN, TEST_DATA_LEN * strlen(src));
46     EXPECT_STREQ("mempcpy_0200", dest, "0200test");
47 }
48 
49 /**
50  * @tc.name      : mempcpy_0300
51  * @tc.desc      : Verify strcasecmp process success. Overwrite the original data.
52  * @tc.level     : Level 0
53  */
mempcpy_0300(void)54 void mempcpy_0300(void)
55 {
56     const char src[TEST_BUFFER_SIZE] = "mempcpy_0300";
57     char dest[TEST_BUFFER_SIZE] = "****";
58     void *rev = mempcpy(dest, src, strlen(src));
59     EXPECT_STREQ("mempcpy_0300", dest, "mempcpy_0300");
60 }
61 
62 /**
63  * @tc.name      : mempcpy_0400
64  * @tc.desc      : Verify strcasecmp process fail. The length of the copied string is 0.
65  * @tc.level     : Level 2
66  */
mempcpy_0400(void)67 void mempcpy_0400(void)
68 {
69     const char src[TEST_BUFFER_SIZE] = "mempcpy_0400";
70     char dest[TEST_BUFFER_SIZE] = "";
71     void *rev = mempcpy(dest, src, 0);
72     EXPECT_STREQ("mempcpy_0200", dest, "");
73 }
74 
main(void)75 int main(void)
76 {
77     mempcpy_0100();
78     mempcpy_0200();
79     mempcpy_0300();
80     mempcpy_0400();
81     return t_status;
82 }