• 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 /**
21  * @tc.name      : uselocale_0100
22  * @tc.desc      : Asserts whether the result returned when uselocale passes a null pointer is the global locale
23  * @tc.level     : Level 0
24  */
uselocale_0100(void)25 void uselocale_0100(void)
26 {
27     char *rev = setlocale(LC_ALL, "C");
28     if (!rev) {
29         EXPECT_PTRNE("uselocale_0100", rev, NULL);
30         return;
31     }
32     locale_t usenow = uselocale(NULL);
33     EXPECT_PTRNE("uselocale_0100", usenow, NULL);
34     EXPECT_PTREQ("uselocale_0100", usenow, LC_GLOBAL_LOCALE);
35 }
36 
37 /**
38  * @tc.name      : uselocale_0200
39  * @tc.desc      : Asserts whether a custom locale is successfully created
40  * using newLOCALE and used using the custom locale using the uselocale function
41  * @tc.level     : Level 0
42  */
uselocale_0200(void)43 void uselocale_0200(void)
44 {
45     char *rev = setlocale(LC_ALL, "C");
46     if (!rev) {
47         EXPECT_PTRNE("uselocale_0200", rev, NULL);
48         return;
49     }
50     uselocale(NULL);
51     locale_t newLocale = newlocale(LC_PAPER_MASK, "en_ZA", NULL);
52     if (newLocale) {
53         EXPECT_PTREQ("uselocale_0200", newLocale, NULL);
54         freelocale(newLocale);
55         newLocale = NULL;
56         return;
57     }
58     newLocale = newlocale(LC_PAPER_MASK, "C.UTF-8", NULL);
59     locale_t usenow = uselocale(newLocale);
60     EXPECT_PTREQ("uselocale_0200", usenow, LC_GLOBAL_LOCALE);
61     locale_t it = uselocale(NULL);
62     EXPECT_PTREQ("uselocale_0200", it, newLocale);
63 
64     if (newLocale) {
65         freelocale(newLocale);
66         newLocale = NULL;
67     }
68 }
69 
main(void)70 int main(void)
71 {
72     uselocale_0100();
73     uselocale_0200();
74     return t_status;
75 }