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 <stdio.h>
18#include <locale.h>
19#include "functionalext.h"
20
21#define PACKAGE "test_dcngettext"
22#define CATEGORY LC_MESSAGES
23
24/**
25 * @tc.name      : dcgettext_0200
26 * @tc.desc      : Test fallback behavior of dcgettext() when a translation is not found
27 *  For this case, the provided mo file should NOT contain a translation for the msgid "not_translated".
28 *  The remote path should be "${test_src_dir}/zh_CN/LC_MESSAGES/test_dcngettext.mo"
29 * @tc.level     : level 0
30 */
31void dcgettext_0100()
32{
33    char *msgid = "hello";
34    setlocale(LC_ALL, "zh_CN");
35    bindtextdomain(PACKAGE, "/data/local/tmp/");
36    char* result = dcgettext(PACKAGE, msgid, CATEGORY);
37    if (!result) {
38        EXPECT_PTRNE("dcgettext_0200", result, NULL);
39        return;
40    }
41    EXPECT_TRUE("dcgettext_0200", strlen(result) > 0);
42    EXPECT_STREQ("gettext_0100", "nihao", result);
43}
44
45int main(void)
46{
47    dcgettext_0100();
48    return t_status;
49}
50