Fcitx
testing.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_UTILS_TESTING_H_
8 #define _FCITX_UTILS_TESTING_H_
9 
10 #include <filesystem>
11 #include <string>
12 #include <vector>
13 #include <fcitx-utils/fcitxutils_export.h>
14 
15 /// \addtogroup FcitxUtils
16 /// \{
17 /// \file
18 /// \brief Utility functions for testing
19 
20 namespace fcitx {
21 
22 /**
23  * Set corresponding environment variable to make sure fcitx can be run properly
24  * for testing.
25  *
26  * This function will do following things:
27  * 1. set SKIP_FCITX_PATH to 1, so StandardPath won't try to resolve it's
28  * hardcoded installation path.
29  * 2. Setup addonDirs, which should point to all the directories of shared
30  * library that need to be loaded.
31  * 3. Set user path to invalid path to prevent write user data.
32  * 4. Set up the data dirs, in order to find necessary data files, addon's .conf
33  * files, and setup the path to find the testing only addons.
34  *
35  * For example, you want to test a test addon A in current project. And your
36  * code directory looks like: src/a a.conf.in test/ testa.cpp build/ : cmake
37  * binary dir. Then you need to first create a cmake rule to make sure addon
38  * config file follow the fcitx directory structure. Which is
39  * $fcitx_data_dir/addon.
40  *
41  * This can be achieved by:
42  * Create test/addon, and have a CMake rule to copy generated a.conf to
43  * build/test/addon.
44  *
45  * Then you can invoke setupTestingEnvironment like:
46  * setupTestingEnvironment(PATH_TO_build, {"src/a"}, {"test"});
47  * So fcitx_data_dir will include build/test, so build/test/addon/a.conf will
48  * loaded. And build/src/a will be used to locate build/src/a.so.
49  *
50  * @param testBinaryDir base directory for build data
51  * @param addonDirs directory of addons
52  * @param dataDirs directory of fcitx data
53  */
54 FCITXUTILS_EXPORT void
55 setupTestingEnvironment(const std::string &testBinaryDir,
56  const std::vector<std::string> &addonDirs,
57  const std::vector<std::string> &dataDirs);
58 
59 FCITXUTILS_EXPORT void
60 setupTestingEnvironmentPath(const std::filesystem::path &testBinaryDir,
61  const std::vector<std::filesystem::path> &addonDirs,
62  const std::vector<std::filesystem::path> &dataDirs);
63 
64 } // namespace fcitx
65 
66 #endif // _FCITX_UTILS_TESTING_H_
Definition: action.cpp:17
void setupTestingEnvironment(const std::string &testBinaryDir, const std::vector< std::string > &addonDirs, const std::vector< std::string > &dataDirs)
Set corresponding environment variable to make sure fcitx can be run properly for testing...
Definition: testing.cpp:21