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 <wchar.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include "test.h"
20
21 /**
22 * @tc.name : wcsncasecmp_0100
23 * @tc.desc : Test wcsncasecmp ignore case compares the first n digits of two wide strings
24 * @tc.level : Level 0
25 */
wcsncasecmp_0100(void)26 void wcsncasecmp_0100(void)
27 {
28 int result = wcsncasecmp(L"hello1", L"HELLO2", 5);
29 if (result != 0) {
30 t_error("%s wcsncasecmp get result is %d are not want 0\n", __func__, result);
31 }
32 }
33
34 /**
35 * @tc.name : wcsncasecmp_0200
36 * @tc.desc : Test that wcsncasecmp returns the result when ws1 is greater than ws2 in the dictionary
37 * @tc.level : Level 1
38 */
wcsncasecmp_0200(void)39 void wcsncasecmp_0200(void)
40 {
41 int result = wcsncasecmp(L"hello1", L"HELLO2", 6);
42 if (result >= 0) {
43 t_error("%s wcsncasecmp get result is %d are not want less 0\n", __func__, result);
44 }
45 }
46
47 /**
48 * @tc.name : wcsncasecmp_0300
49 * @tc.desc : Test that wcsncasecmp returns the result when ws1 is less than ws2 in the dictionary
50 * @tc.level : Level 1
51 */
wcsncasecmp_0300(void)52 void wcsncasecmp_0300(void)
53 {
54 int result = wcsncasecmp(L"hello2", L"HELLO1", 6);
55 if (result <= 0) {
56 t_error("%s wcsncasecmp get result is %d are not want gress 0\n", __func__, result);
57 }
58 }
59
60 /**
61 * @tc.name : wcsncasecmp_0400
62 * @tc.desc : Test that wcsncasecmp returns the result when ws1 is longer in the dictionary than ws2
63 * @tc.level : Level 1
64 */
wcsncasecmp_0400(void)65 void wcsncasecmp_0400(void)
66 {
67 int result = wcsncasecmp(L"hello", L"HELL", 5);
68 if (result <= 0) {
69 t_error("%s wcsncasecmp get result is %d are not want gress 0\n", __func__, result);
70 }
71 }
72
73 /**
74 * @tc.name : wcsncasecmp_0500
75 * @tc.desc : wcsncasecmp returns result when test ws1 is shorter than ws2 in dictionary
76 * @tc.level : Level 1
77 */
wcsncasecmp_0500(void)78 void wcsncasecmp_0500(void)
79 {
80 int result = wcsncasecmp(L"hell", L"HELLO", 5);
81 if (result >= 0) {
82 t_error("%s wcsncasecmp get result is %d are not want less 0\n", __func__, result);
83 }
84 }
85
86 /**
87 * @tc.name : wcsncasecmp_0600
88 * @tc.desc : Test the result returned by wcsncasecmp when the number of comparisons is 0
89 * @tc.level : Level 2
90 */
wcsncasecmp_0600(void)91 void wcsncasecmp_0600(void)
92 {
93 int result = wcsncasecmp(L"foo", L"bar", 0);
94 if (result != 0) {
95 t_error("%s wcsncasecmp get result is %d are not want 0\n", __func__, result);
96 }
97 }
98
main(int argc,char * argv[])99 int main(int argc, char *argv[])
100 {
101 wcsncasecmp_0100();
102 wcsncasecmp_0200();
103 wcsncasecmp_0300();
104 wcsncasecmp_0400();
105 wcsncasecmp_0500();
106 wcsncasecmp_0600();
107 return t_status;
108 }