Esempio n. 1
0
TEST_F(BuildFromXmlUnionAlign, align1_basic) {
    parseMeta(
        "<metalib tagsetversion='1' name='net'  version='10'>"
        "    <union name='S1' version='1' id='33'>"
        "	     <entry name='b1' type='int8'/>"
        "	     <entry name='b2' type='int16'/>"
        "    </union>"
        "    <struct name='S2' version='1' id='34'>"
        "	     <entry name='a1' type='int8'/>"
        "	     <entry name='m_u' type='S1'/>"
        "    </struct>"
        "</metalib>"
        );

    ASSERT_TRUE(t_em_no_error());

    EXPECT_EQ(1, dr_meta_align(meta("S1")));
    EXPECT_EQ((size_t)2, dr_meta_size(meta("S1")));

    EXPECT_EQ(0, entry("S1", "b1")->m_data_start_pos);
    EXPECT_EQ(0, entry("S1", "b2")->m_data_start_pos);

    EXPECT_EQ(1, dr_meta_align(meta("S2")));
    EXPECT_EQ((size_t)3, dr_meta_size(meta("S2")));

    EXPECT_EQ(0, entry("S2", "a1")->m_data_start_pos);
    EXPECT_EQ(1, entry("S2", "m_u")->m_data_start_pos);
}
Esempio n. 2
0
TEST_P(BuildFromXmlTypeSizeTest, CheckSize) {
    TypeSizeCase caseData = GetParam();

    char buf[256];
    snprintf(
        buf, 256
        ,
        "<metalib tagsetversion='1' name='net'  version='10'>"
        "    <struct name='S1' version='1' id='33'>"
        "	     <entry name='a1' type='%s'/>"
        "    </struct>"
        "</metalib>"
        ,
        caseData.m_name);

    parseMeta(buf);

    EXPECT_EQ(caseData.m_size, dr_meta_size(meta("S1")))
        << "size of type " << caseData.m_name << " error!";
}
Esempio n. 3
0
int ReadTest::read(const char * data, const char * typeName, int policy, size_t capacity) {
    LPDRMETA meta = dr_lib_find_meta_by_name(m_metaLib, typeName);
    EXPECT_TRUE(meta) << "get meta " << typeName << " error!";
    if (meta == 0) return -1;

    if (capacity == 0) {
        capacity = dr_meta_size(meta);
    }

    cfg_t input = t_cfg_parse(data);
    EXPECT_TRUE(input) << "parse input to cfg fail!";
    if (input == 0) return -1;

    t_elist_clear();
    mem_buffer_clear(&m_buffer);

    return dr_cfg_read(
        mem_buffer_alloc(&m_buffer, capacity),
        capacity,
        input,
        meta,
        policy,
        t_em());
}
Esempio n. 4
0
dr_dm_data_t
dr_dm_data_create(dr_dm_manage_t mgr, const void * data, size_t data_size, const char ** duplicate_index) {
    char * buf;
    dr_dm_data_t role;
    size_t data_capacity;
    dr_dm_data_id_t role_id;
    int generate_role_id;
    size_t index_count;
    struct cpe_hash_it index_it;
    struct dr_dm_data_index * index;
    size_t i;

    index_count = cpe_hash_table_count(&mgr->m_indexes);

    if (duplicate_index) *duplicate_index = NULL;

    if (mgr->m_role_meta == NULL) {
        CPE_ERROR(
            mgr->m_em, "%s: dr_dm_data_create: role meta not exist!",
            dr_dm_manage_name(mgr));
        return NULL;
    }

    if (mgr->m_id_index == NULL) {
        CPE_ERROR(
            mgr->m_em, "%s: dr_dm_data_create: role id entry not exist!",
            dr_dm_manage_name(mgr));
        return NULL;
    }

    data_capacity = dr_meta_size(mgr->m_role_meta);
    if (data_size > data_capacity) {
        CPE_ERROR(
            mgr->m_em, "%s: dr_dm_data_create: data too long, data_size=%d, data_capacity=%d!",
            dr_dm_manage_name(mgr), (int)data_size, (int)data_capacity);
        return NULL;
    }

    generate_role_id = 0;
    role_id = dr_entry_read_int64(data, mgr->m_id_index->m_entry);
    if (role_id == 0) {
        if (mgr->m_id_generate) {
            if (gd_id_generator_generate(&role_id, mgr->m_id_generate) != 0) {
                CPE_ERROR(
                    mgr->m_em, "%s: dr_dm_data_create: generate id from %s fail!",
                    dr_dm_manage_name(mgr), gd_id_generator_name(mgr->m_id_generate));
                return NULL;
            }
            else {
                generate_role_id = 1;
            }
        }
    }

    buf = (char *)mem_alloc(
        mgr->m_alloc,
        sizeof(struct cpe_hash_entry) * index_count
        + sizeof(struct dr_dm_data)
        + data_capacity);
    if (buf == NULL) return NULL;

    role = (dr_dm_data_t)(buf + sizeof(struct cpe_hash_entry) * index_count);

    role->m_mgr = mgr;

    memcpy(dr_dm_data_data(role), data, data_capacity);

    if (generate_role_id) {
        if (dr_entry_set_from_int64(dr_dm_data_data(role), role_id, mgr->m_id_index->m_entry, NULL) != 0) {
            CPE_ERROR(
                mgr->m_em, "%s: dr_dm_data_create: set generated id to data fail!",
                dr_dm_manage_name(mgr));
            mem_free(mgr->m_alloc, buf);
            return NULL;
        }
    }

    for(i = 0; i < index_count; ++i) {
        cpe_hash_entry_init(((struct cpe_hash_entry*)buf) + i);
    }

    cpe_hash_it_init(&index_it, &mgr->m_indexes);
    while((index = cpe_hash_it_next(&index_it))) {
        if (dr_dm_data_index_add(index, role) != 0) {
            struct dr_dm_data_index * index_fall_back;

            CPE_ERROR(
                mgr->m_em, "%s: dr_dm_data_create: add to index %s: duplicate!",
                dr_dm_manage_name(mgr), dr_entry_name(index->m_entry));

            if (duplicate_index) *duplicate_index = dr_dm_data_index_name(index);

            cpe_hash_it_init(&index_it, &mgr->m_indexes);
            while((index_fall_back = cpe_hash_it_next(&index_it)) && index_fall_back != index) {
                dr_dm_data_index_remove(index_fall_back, role);
            }
            
            mem_free(mgr->m_alloc, buf);
            return NULL;
        }
    }

    return role;
}
Esempio n. 5
0
size_t dr_dm_data_data_capacity(dr_dm_data_t dr_dm_data) {
    assert(dr_dm_data->m_mgr->m_role_meta);
    return dr_meta_size(dr_dm_data->m_mgr->m_role_meta);
}
Esempio n. 6
0
 size_t size(void) const { return dr_meta_size(*this); }