• 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      : wcscmp_0100
23  * @tc.desc      : Compares two equal wide strings and returns a value equal to 0
24  * @tc.level     : Level 0
25  */
wcscmp_0100(void)26 void wcscmp_0100(void)
27 {
28     wchar_t str1[] = L"test wcscmp";
29     wchar_t str2[] = L"test wcscmp";
30     if (wcscmp(str1, str2)) {
31         t_error("%s error, the result of comparing two strings should be equal", __func__);
32     }
33 }
34 
35 /**
36  * @tc.name      : wcscmp_0200
37  * @tc.desc      : Compares two equal wide strings and returns a value less than zero
38  * @tc.level     : Level 0
39  */
wcscmp_0200(void)40 void wcscmp_0200(void)
41 {
42     wchar_t str1[] = L"ABCD";
43     wchar_t str2[] = L"ABCE";
44     if (wcscmp(str1, str2) >= 0) {
45         t_error("%s error, expected result value less than zero", __func__);
46     }
47 }
48 
49 /**
50  * @tc.name      : wcscmp_0300
51  * @tc.desc      : Compares two equal wide strings and returns a value greater than zero
52  * @tc.level     : Level 0
53  */
wcscmp_0300(void)54 void wcscmp_0300(void)
55 {
56     wchar_t str1[] = L"ABCE";
57     wchar_t str2[] = L"ABCD";
58     if (wcscmp(str1, str2) <= 0) {
59         t_error("%s error, expected result value greater than zero", __func__);
60     }
61 }
62 
63 /**
64  * @tc.name      : wcscmp_0400
65  * @tc.desc      : The first characters of the compared wide strings are different
66  * @tc.level     : Level 1
67  */
wcscmp_0400(void)68 void wcscmp_0400(void)
69 {
70     wchar_t str1[] = L"ABCD";
71     wchar_t str2[] = L"BCDE";
72     if (wcscmp(str1, str2) >= 0) {
73         t_error("%s error, expected result value less than zero", __func__);
74     }
75     if (wcscmp(str2, str1) <= 0) {
76         t_error("%s error, expected result value greater than zero", __func__);
77     }
78 }
79 
80 /**
81  * @tc.name      : wcscmp_0500
82  * @tc.desc      : One or both of the wide strings compared are equal to NULL
83  * @tc.level     : Level 1
84  */
wcscmp_0500(void)85 void wcscmp_0500(void)
86 {
87     wchar_t str1[] = L"";
88     wchar_t str2[] = L"";
89     wchar_t str3[] = L"A";
90     if (wcscmp(str1, str3) >= 0) {
91         t_error("%s error, expected result value less than zero", __func__);
92     }
93     if (wcscmp(str3, str1) <= 0) {
94         t_error("%s error, expected result value greater than zero", __func__);
95     }
96     if (wcscmp(str1, str2)) {
97         t_error("%s error, the result of comparing two strings should be equal", __func__);
98     }
99 }
100 
main(int argc,char * argv[])101 int main(int argc, char *argv[])
102 {
103     wcscmp_0100();
104     wcscmp_0200();
105     wcscmp_0300();
106     wcscmp_0400();
107     wcscmp_0500();
108     return t_status;
109 }