• 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 <stdio.h>
17 #include <locale.h>
18 #include <string.h>
19 #include "test.h"
20 
21 /**
22  * @tc.name      : strxfrm_0100
23  * @tc.desc      : Put all characters in src into dest
24  * @tc.level     : Level 0
25  */
strxfrm_0100(void)26 void strxfrm_0100(void)
27 {
28     char desp[20] = {};
29     char *str = "abcdef";
30     int want = 6;
31     size_t result = strxfrm(desp, str, want + 1);
32     if (result != want) {
33         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want);
34     }
35     if (strcmp(desp, str) != 0) {
36         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
37     }
38 }
39 
40 /**
41  * @tc.name      : strxfrm_0200
42  * @tc.desc      : Put all characters in src into dest, and set n to be the same as the length of src
43  * @tc.level     : Level 1
44  */
strxfrm_0200(void)45 void strxfrm_0200(void)
46 {
47     char desp[20] = {};
48     char *str = "abcdef";
49     int want = 6;
50     size_t result = strxfrm(desp, str, want);
51     if (result != want) {
52         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want);
53     }
54     if (strcmp(desp, str) == 0) {
55         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
56     }
57 }
58 
59 /**
60  * @tc.name      : strxfrm_0300
61  * @tc.desc      : Put all characters in src into dest, set n less than the length of src
62  * @tc.level     : Level 1
63  */
strxfrm_0300(void)64 void strxfrm_0300(void)
65 {
66     char desp[20] = {};
67     char *str = "abcdef";
68     int want = 3;
69     size_t result = strxfrm(desp, str, want);
70     if (result != strlen(str)) {
71         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, strlen(str));
72     }
73     if (strcmp(desp, str) == 0) {
74         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
75     }
76 }
77 
78 /**
79  * @tc.name      : strxfrm_0400
80  * @tc.desc      : Test empty string dest array size is less than src
81  * @tc.level     : Level 1
82  */
strxfrm_0400(void)83 void strxfrm_0400(void)
84 {
85     char desp[5];
86     char *str = "abcdef";
87     int want = 6;
88     size_t result = strxfrm(desp, str, want + 1);
89     if (result != want) {
90         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want);
91     }
92     if (strcmp(desp, str) != 0) {
93         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
94     }
95 }
96 
97 /**
98  * @tc.name      : strxfrm_0500
99  * @tc.desc      : Test to copy the content of src to the string dest of the existing content
100  * @tc.level     : Level 1
101  */
strxfrm_0500(void)102 void strxfrm_0500(void)
103 {
104     char desp[10];
105     strcpy(desp, "123");
106     char *str = "abcdef";
107     int want = 6;
108     size_t result = strxfrm(desp, str, want + 1);
109     if (result != want) {
110         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want);
111     }
112     if (strcmp(desp, str) != 0) {
113         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
114     }
115 }
116 
117 /**
118  * @tc.name      : strxfrm_0600
119  * @tc.desc      : The test copies the content of src to dest whose length is greater than src through strxfrm
120  * @tc.level     : Level 1
121  */
strxfrm_0600(void)122 void strxfrm_0600(void)
123 {
124     char desp[10];
125     strcpy(desp, "1234567");
126     char *str = "abcdef";
127     int want = 6;
128     size_t result = strxfrm(desp, str, want + 1);
129     if (result != want) {
130         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want);
131     }
132     if (strcmp(desp, str) != 0) {
133         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
134     }
135 }
136 
137 /**
138  * @tc.name      : strxfrm_0700
139  * @tc.desc      : Test move over src
140  * @tc.level     : Level 1
141  */
strxfrm_0700(void)142 void strxfrm_0700(void)
143 {
144     char desp[10];
145     strcpy(desp, "1234567");
146     char *str = "abcdef";
147     int move = 10;
148     size_t result = strxfrm(desp, str, move);
149     int want = 6;
150     if (result != want) {
151         t_error("%s strxfrm get size is %d is not want %d\n", __func__, result, want);
152     }
153     if (strcmp(desp, str) != 0) {
154         t_error("%s strxfrm get desp is %s is not want %s\n", __func__, desp, str);
155     }
156 }
157 
main(int argc,char * argv[])158 int main(int argc, char *argv[])
159 {
160     strxfrm_0100();
161     strxfrm_0200();
162     strxfrm_0300();
163     strxfrm_0400();
164     strxfrm_0500();
165     strxfrm_0600();
166     strxfrm_0700();
167     return t_status;
168 }