Beispiel #1
0
int WriteTest::write(const char * typeName, const void * data, size_t data_size) {
    LPDRMETA meta = dr_lib_find_meta_by_name(m_metaLib, typeName);
    EXPECT_TRUE(meta) << "get meta " << typeName << " error!";

    t_elist_clear();

    int r = dr_pbuf_write(m_buffer, sizeof(m_buffer), data, data_size, meta, t_em());
    m_bufffer_len = r >= 0 ? (size_t)r : 0;
    return r;
}
Beispiel #2
0
int PrintTest::print(const void * data, const char * typeName) {
    LPDRMETA meta = dr_lib_find_meta_by_name(m_metaLib, typeName);
    EXPECT_TRUE(meta) << "get meta " << typeName << " error!";

    t_elist_clear();

    struct write_stream_buffer stream = CPE_WRITE_STREAM_BUFFER_INITIALIZER(&m_buffer);

    int r = dr_json_print((write_stream_t)&stream, data, meta, DR_JSON_PRINT_BEAUTIFY, t_em());
    stream_putc((write_stream_t)&stream, 0);
    return r;
}
Beispiel #3
0
void ReadTest::installMeta(const char * def) {
    m_metaLib = NULL;
    mem_buffer_clear(&m_metaLib_buffer);

    t_elist_clear();

    EXPECT_EQ(
        0,
        dr_create_lib_from_xml_ex(&m_metaLib_buffer, def, strlen(def), t_em()))
        << "install meta error";

    m_metaLib = (LPDRMETALIB)mem_buffer_make_exactly(&m_metaLib_buffer);
}
Beispiel #4
0
int ReadTest::read(const char * decodeTypeName, const void * data, size_t data_size) {
    LPDRMETA meta = dr_lib_find_meta_by_name(m_metaLib, decodeTypeName);
    EXPECT_TRUE(meta) << "get meta " << decodeTypeName << " error!";

    t_elist_clear();

    char buf[1024];
    int len = dr_pbuf_write(buf, sizeof(buf), data, data_size, meta, t_em());
    EXPECT_GT(len, 0);

    int r = dr_pbuf_read(m_result_buffer, sizeof(m_result_buffer), buf, len, meta, t_em());
    m_result_bufffer_len = r;
    m_result_meta = meta;
    return r;
}
Beispiel #5
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());
}