• 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 <string.h>
18 #include <wchar.h>
19 #include "test.h"
20 
21 /**
22  * @tc.name      : wcsnlen_0100
23  * @tc.desc      : Test the wcsnlen method to get the number of wide strings
24  * @tc.level     : Level 0
25  */
wcsnlen_0100(void)26 void wcsnlen_0100(void)
27 {
28     wchar_t *wc = L"ABCDEF";
29     size_t want = 6;
30     size_t result = wcsnlen(wc, 6);
31     if (result != want) {
32         t_error("%s wcsnlen error get result is %d are not want 6\n", __func__, result);
33     }
34 }
35 
36 /**
37  * @tc.name      : wcsnlen_0200
38  * @tc.desc      : Test the return value of wcsnlen when the incoming length is 0
39  * @tc.level     : Level 1
40  */
wcsnlen_0200(void)41 void wcsnlen_0200(void)
42 {
43     wchar_t *wc = L"ABCDEF";
44     size_t result = wcsnlen(wc, 0);
45     if (result != 0) {
46         t_error("%s wcsnlen error get result is %d are not want 0\n", __func__, result);
47     }
48 }
49 
50 /**
51  * @tc.name      : wcsnlen_0300
52  * @tc.desc      : Test the return value of wcsnlen when the incoming length is less than the incoming wide string
53  * @tc.level     : Level 1
54  */
wcsnlen_0300(void)55 void wcsnlen_0300(void)
56 {
57     wchar_t *wc = L"ABCDEF";
58     size_t want = 3;
59     size_t result = wcsnlen(wc, 3);
60     if (result != want) {
61         t_error("%s wcsnlen error get result is %d are not want 3\n", __func__, result);
62     }
63 }
64 
65 /**
66  * @tc.name      : wcsnlen_0400
67  * @tc.desc      : Test the return value of wcsnlen when the incoming length is greater than the incoming wide string
68  *                 length
69  * @tc.level     : Level 1
70  */
wcsnlen_0400(void)71 void wcsnlen_0400(void)
72 {
73     wchar_t *wc = L"ABCDEF";
74     size_t want = 6;
75     size_t result = wcsnlen(wc, 7);
76     if (result != want) {
77         t_error("%s wcsnlen error get result is %d are not want 6\n", __func__, result);
78     }
79 }
80 
main(int argc,char * argv[])81 int main(int argc, char *argv[])
82 {
83     wcsnlen_0100();
84     wcsnlen_0200();
85     wcsnlen_0300();
86     wcsnlen_0400();
87     return t_status;
88 }