コード例 #1
0
ファイル: test_tree_schema.c プロジェクト: fanchanghu/libyang
static void
test_lys_features_disable(void **state)
{
    (void) state; /* unused */
    LYS_INFORMAT yang_format = LYS_IN_YIN;
    const struct lys_module *module;
    int rc;

    module = lys_parse_mem(ctx, lys_module_a, yang_format);
    if (!module) {
        fail();
    }

    assert_string_equal("foo", module->features->name);
    assert_int_equal(0x0, module->features->flags);

    rc = lys_features_enable(module, "*");
    if (rc) {
        fail();
    }


    assert_int_equal(LYS_FENABLED, module->features->flags);

    rc = lys_features_disable(module, "*");
    if (rc) {
        fail();
    }


    assert_int_equal(0x0, module->features->flags);
}
コード例 #2
0
ファイル: test_feature.c プロジェクト: manradhaCisco/libyang
static void
test_fullset(void **state)
{
    struct ly_ctx *ctx = *state;
    const struct lys_module *mod;
    char *buf = NULL;

    const char *tree_alldisabled = "module: features\n"
"   +--rw lst* [id] {not a}?\n"
"   |  +--rw id    string\n"
"   +--rw (ch)? {not (a and b)}?\n"
"   |  +--:(ch3)\n"
"   |     +--rw ch3?   string\n"
"   +--rw axml?   anyxml {not (a or b)}?\n";

    const char *tree_a = "module: features\n"
"   +--rw grp?    string\n"
"   +--rw cont! {a}?\n"
"   +--rw ll*     string {a or b}?\n"
"   +--rw (ch)? {not (a and b)}?\n"
"      +--:(ch1) {a}?\n"
"      |  +--rw ch1?   string\n"
"      +--:(ch3)\n"
"         +--rw ch3?   string\n";

    const char *tree_ab = "module: features\n"
"   +--rw grp?    string\n"
"   +--rw cont! {a}?\n"
"   +--rw lf?     string {a and b}?\n"
"   +--rw ll*     string {a or b}?\n";

    const char *tree_abaa = "module: features\n"
"   +--rw grp?    string\n"
"   +--rw cont! {a}?\n"
"   |  +--rw aug?   string\n"
"   +--rw lf?     string {a and b}?\n"
"   +--rw ll*     string {a or b}?\n"
"rpcs:\n"
"   +---x rpc1 {aa}?\n"
"notifications:\n"
"   +---n notif1 {aa}?\n";

    const char *tree_b = "module: features\n"
"   +--rw ll*     string {a or b}?\n"
"   +--rw lst* [id] {not a}?\n"
"   |  +--rw id    string\n"
"   +--rw (ch)? {not (a and b)}?\n"
"      +--:(ch2) {b}?\n"
"      |  +--rw ch2?   string\n"
"      +--:(ch3)\n"
"         +--rw ch3?   string\n";

    mod = ly_ctx_load_module(ctx, "features", NULL);
    assert_non_null(mod);

    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_alldisabled);
    free(buf); buf = NULL;

    lys_features_enable(mod, "a");
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_a);
    free(buf); buf = NULL;

    lys_features_enable(mod, "b");
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_ab);
    free(buf); buf = NULL;

    lys_features_enable(mod, "aa");
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_abaa);
    free(buf); buf = NULL;

    lys_features_disable(mod, "a"); /* aa is also disabled by disabling a */
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_b);
    free(buf); buf = NULL;
}