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 <libintl.h>
17 #include <locale.h>
18 #include <stdlib.h>
19 #include "functionalext.h"
20
21 #define PACKAGE "test_dcngettext"
22
23 /**
24 * @tc.name : dcngettext_0100
25 * @tc.desc : Get string from dcngettext() with mo file
26 * This case need push the test_dcngettext.mo file of the current path to remote board
27 * The remote path should be "${test_src_dir}/zh_CN/LC_MESSAGES/test_dcngettext.mo"
28 * @tc.level : Level 0
29 */
dcngettext_0100(void)30 static void dcngettext_0100(void)
31 {
32 char *msgid = "hello";
33 setlocale(LC_ALL, "zh_CN");
34 bindtextdomain(PACKAGE, "/tmp");
35 textdomain(PACKAGE);
36 char *result = dcngettext(PACKAGE, msgid, 0, 1, LC_MESSAGES);
37 if (!result) {
38 EXPECT_PTRNE("dcngettext_0100", result, NULL);
39 return;
40 }
41
42 EXPECT_TRUE("dcngettext_0100", strlen(result) > 0);
43 EXPECT_STREQ("dcngettext_0100", "nihao", result);
44 }
45
main(void)46 int main(void)
47 {
48 dcngettext_0100();
49 return t_status;
50 }