File: testconfig.c

package info (click to toggle)
fcitx 1%3A4.2.9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 19,800 kB
  • sloc: ansic: 134,151; cpp: 7,280; sh: 2,778; python: 800; xml: 345; makefile: 42
file content (56 lines) | stat: -rw-r--r-- 1,522 bytes parent folder | download | duplicates (7)
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
47
48
49
50
51
52
53
54
55
56
#include <assert.h>
#include "fcitx-config/fcitx-config.h"
#include "fcitx-config/hotkey.h"

typedef struct _TestConfig
{
    FcitxGenericConfig gc;
    char* name;
    char* str;
    FcitxHotkey hk[2];
    char c;
    int i;
    boolean b;
} TestConfig;

CONFIG_BINDING_BEGIN(TestConfig)
CONFIG_BINDING_REGISTER("Test", "Name", name)
CONFIG_BINDING_REGISTER("Test", "String", str)
CONFIG_BINDING_REGISTER("Test", "Hotkey", hk)
CONFIG_BINDING_REGISTER("Test", "Char", c)
CONFIG_BINDING_REGISTER("Test", "Integer", i)
CONFIG_BINDING_REGISTER("Test", "Boolean", b)
CONFIG_BINDING_END()


int main(int argc, char* argv[])
{
    if (argc <= 3)
        return 1;

    FcitxConfigFileDesc* configDesc = FcitxConfigParseConfigFileDesc(argv[1]);
    assert(configDesc);
    TestConfig tc;
    memset(&tc, 0, sizeof(tc));
    FcitxConfigFile* configFile = FcitxConfigParseConfigFile(argv[2], configDesc);
    assert(configFile);
    TestConfigConfigBind(&tc, configFile, configDesc);
    FcitxConfigBindSync((FcitxGenericConfig*) &tc);

    assert(tc.i == 1);
    assert(strcmp(tc.str, "CTRL_A") == 0);
    assert(tc.hk[0].sym == FcitxKey_A);
    assert(tc.hk[0].state == FcitxKeyState_Ctrl);
    assert(tc.hk[1].sym == FcitxKey_None);
    assert(tc.hk[1].state == FcitxKeyState_None);
    assert(tc.c == 'a');
    assert(tc.b == true);


    FcitxConfigSaveConfigFile(argv[3], (FcitxGenericConfig*) &tc, configDesc);

    FcitxConfigFree((FcitxGenericConfig*) &tc);

    FcitxConfigFreeConfigFileDesc(configDesc);
    return 0;
}