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 : wmemcmp_0100
23 * @tc.desc : Test the return value of wmemcmp when two strings are equal
24 * @tc.level : Level 0
25 */
wmemcmp_0100(void)26 void wmemcmp_0100(void)
27 {
28 wchar_t l[] = L"ABCD";
29 wchar_t r[] = L"ABCD";
30 int result = wmemcmp(l, r, sizeof(l) / sizeof(*l));
31 if (result != 0) {
32 t_error("%s two strings are not equal\n", __func__);
33 }
34 }
35
36 /**
37 * @tc.name : wmemcmp_0200
38 * @tc.desc : l precedes r in lexicographical order
39 * @tc.level : Level 1
40 */
wmemcmp_0200(void)41 void wmemcmp_0200(void)
42 {
43 wchar_t l[] = L"ABCD";
44 wchar_t r[] = L"ABCE";
45 int result = wmemcmp(l, r, sizeof(l) / sizeof(*l));
46 if (result >= 0) {
47 t_error("%s l is not precedes to r\n", __func__);
48 }
49 }
50
51 /**
52 * @tc.name : wmemcmp_0300
53 * @tc.desc : r precedes l in lexicographical order
54 * @tc.level : Level 1
55 */
wmemcmp_0300(void)56 void wmemcmp_0300(void)
57 {
58 wchar_t l[] = L"ABCD";
59 wchar_t r[] = L"ABCC";
60 int result = wmemcmp(l, r, sizeof(l) / sizeof(*l));
61 if (result <= 0) {
62 t_error("%s l is not follows to r\n", __func__);
63 }
64 }
65
66 /**
67 * @tc.name : wmemcmp_0400
68 * @tc.desc : Test the return value of the function when n=0
69 * @tc.level : Level 1
70 */
wmemcmp_0400(void)71 void wmemcmp_0400(void)
72 {
73 wchar_t l[] = L"ABCD";
74 wchar_t r[] = L"ABCC";
75 int n = 0;
76 int result = wmemcmp(l, r, n);
77 if (result != 0) {
78 t_error("%s result is not want 0\n", __func__);
79 }
80 }
81
main(int argc,char * argv[])82 int main(int argc, char *argv[])
83 {
84 wmemcmp_0100();
85 wmemcmp_0200();
86 wmemcmp_0300();
87 wmemcmp_0400();
88 return t_status;
89 }