File: testemoji.cpp

package info (click to toggle)
fcitx5 5.1.18-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 32,228 kB
  • sloc: cpp: 110,377; java: 3,125; javascript: 2,137; sh: 1,912; xml: 1,552; python: 1,312; ansic: 843; makefile: 11
file content (46 lines) | stat: -rw-r--r-- 1,530 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 */
#include <fcntl.h>
#include "fcitx-utils/log.h"
#include "fcitx-utils/standardpaths.h"
#include "fcitx-utils/testing.h"
#include "fcitx/addonmanager.h"
#include "emoji_public.h"
#include "testdir.h"

using namespace fcitx;

int main() {
    setupTestingEnvironmentPath(
        FCITX5_BINARY_DIR, {"bin"},
        {"test", "src/modules", FCITX5_SOURCE_DIR "/src/modules"});
    AddonManager manager(FCITX5_BINARY_DIR "/src/modules/emoji");
    manager.registerDefaultLoader(nullptr);
    manager.load();
    auto *emoji = manager.addon("emoji", true);
    FCITX_ASSERT(emoji);
    auto emojis = emoji->call<IEmoji::query>("zh", "大笑", false);
    FCITX_ASSERT(std::find(emojis.begin(), emojis.end(), "\xf0\x9f\x98\x84") !=
                 emojis.end())
        << emojis;
    emojis = emoji->call<IEmoji::query>("en", "eggplant", false);
    FCITX_ASSERT(std::find(emojis.begin(), emojis.end(), "\xf0\x9f\x8d\x86") !=
                 emojis.end())
        << emojis;

    auto files =
        StandardPaths::global().locate(StandardPathsType::PkgData, "emoji/data",
                                       pathfilter::extension(".dict"));
    // Check if all languages are loadable.
    for (const auto &[name, __] : files) {
        std::string lang = name.stem().string();
        FCITX_ASSERT(emoji->call<IEmoji::check>(lang, false))
            << "Failed to load " << lang;
    }

    return 0;
}