• 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 <locale.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19 
20 static const int lcMarkArry[] = {LC_PAPER_MASK,
21     LC_NAME_MASK,
22     LC_ADDRESS_MASK,
23     LC_TELEPHONE_MASK,
24     LC_MEASUREMENT_MASK,
25     LC_IDENTIFICATION_MASK,
26     LC_ALL_MASK};
27 
28 /**
29  * @tc.name      : newlocale_0100
30  * @tc.desc      : Check whether the LC_ALL type is passed to newlocale to create a custom locale environment
31  * @tc.level     : Level 0
32  */
newlocale_0100(void)33 void newlocale_0100(void)
34 {
35     char *lo = setlocale(LC_ALL, "C");
36     if (!lo) {
37         EXPECT_PTRNE("newlocale_0100", lo, NULL);
38         return;
39     }
40     locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
41     EXPECT_PTRNE("newlocale_0100", newlocale_, NULL);
42 
43     if (newlocale_) {
44         freelocale(newlocale_);
45         newlocale_ = NULL;
46     }
47 }
48 
49 /**
50  * @tc.name      : newlocale_0200
51  * @tc.desc      : Check whether the LC_ALL type is passed to newlocale to create a custom locale environment
52  * @tc.level     : Level 0
53  */
newlocale_0200(void)54 void newlocale_0200(void)
55 {
56     char *lo = setlocale(LC_ALL, "C");
57     if (!lo) {
58         EXPECT_PTRNE("newlocale_0200", lo, NULL);
59         return;
60     }
61     locale_t newlocale_ = newlocale(LC_ALL_MASK, "C", NULL);
62     EXPECT_PTRNE("newlocale_0200", newlocale_, NULL);
63 
64     if (newlocale_) {
65         freelocale(newlocale_);
66         newlocale_ = NULL;
67     }
68 }
69 
70 /**
71  * @tc.name      : newlocale_0300
72  * @tc.desc      : Determines whether the custom locale environment is created successfully
73  * by passing different LC data types to newlocale
74  * @tc.level     : Level 0
75  */
newlocale_0300(void)76 void newlocale_0300(void)
77 {
78     char *lo = setlocale(LC_ALL, "C");
79     if (!lo) {
80         EXPECT_PTRNE("newlocale_0300", lo, NULL);
81         return;
82     }
83     for (int i = 0; i < sizeof(lcMarkArry) / sizeof(lcMarkArry[0]); i++) {
84         locale_t newlocale_ = newlocale(lcMarkArry[i], "en_US", NULL);
85         EXPECT_PTRNE("newlocale_0300", newlocale_, NULL);
86 
87         if (newlocale_) {
88             freelocale(newlocale_);
89             newlocale_ = NULL;
90         }
91     }
92 }
93 
main(void)94 int main(void)
95 {
96     newlocale_0100();
97     newlocale_0200();
98     newlocale_0300();
99 
100     return t_status;
101 }