Ejemplo n.º 1
0
struct mem_buffer_trunk *
BufferTest::append_trunk(const char * data) {
    if (data) {
        size_t capacity = strlen(data);
        struct mem_buffer_trunk * trunk =
            mem_buffer_append_trunk(&m_buffer, capacity);
        mem_trunk_append(&m_buffer, trunk, data, capacity);
        return trunk;
    }
    else {
        return mem_buffer_append_trunk(&m_buffer, m_buffer.m_auto_inc_size);
    }
}
Ejemplo n.º 2
0
TEST_F(BufferTest, trunk_free_middle) {
    const char * data = "abcde";

    struct mem_buffer_trunk * trunk1 = 
        mem_buffer_append_trunk(&m_buffer, 5);
    mem_trunk_append(&m_buffer, trunk1, data, 3);

    struct mem_buffer_trunk * trunk2 = 
        mem_buffer_append_trunk(&m_buffer, 5);
    mem_trunk_append(&m_buffer, trunk2, data, 4);

    EXPECT_EQ((size_t)7, mem_buffer_size(&m_buffer));

    mem_trunk_free(&m_buffer, trunk2);
    EXPECT_EQ((size_t)3, mem_buffer_size(&m_buffer));
}
Ejemplo n.º 3
0
TEST_F(BufferTest, trunk_create) {
    struct mem_buffer_trunk * trunk = 
        mem_buffer_append_trunk(&m_buffer, 3);

    EXPECT_EQ((size_t)3, trunk->m_capacity);
    EXPECT_EQ((size_t)0, trunk->m_size);
    EXPECT_TRUE(trunk->m_allocrator == m_buffer.m_default_allocrator);
}
Ejemplo n.º 4
0
TEST_F(BufferTest, trunk_append_overflow) {
    struct mem_buffer_trunk * trunk = 
        mem_buffer_append_trunk(&m_buffer, 2);

    const char * data = "abcde";

    EXPECT_EQ((size_t)2, mem_trunk_append(&m_buffer, trunk, data, 3));
    EXPECT_EQ((size_t)2, trunk->m_size);
    EXPECT_EQ((size_t)2, mem_buffer_size(&m_buffer));
}
Ejemplo n.º 5
0
TEST_F(BufferTest, strcat_to_str_trunk_full) {
    struct mem_buffer_trunk * trunk1 =
        mem_buffer_append_trunk(&m_buffer, 7);

    EXPECT_EQ((size_t)4, mem_trunk_append(&m_buffer, trunk1, "abc", 4));

    EXPECT_EQ(0, mem_buffer_strcat(&m_buffer, "def"));
    EXPECT_STREQ("abcdef", (char*)mem_buffer_make_continuous(&m_buffer, 0));

    EXPECT_EQ((size_t)7, mem_buffer_size(&m_buffer));
    EXPECT_EQ((size_t)1, mem_buffer_trunk_count(&m_buffer));
}
Ejemplo n.º 6
0
TEST_F(BufferTest, trunk_free) {
    struct mem_buffer_trunk * trunk = 
        mem_buffer_append_trunk(&m_buffer, 5);

    const char * data = "abcde";

    EXPECT_EQ((size_t)3, mem_trunk_append(&m_buffer, trunk, data, 3));
    EXPECT_EQ((size_t)3, trunk->m_size);
    EXPECT_EQ((size_t)3, mem_buffer_size(&m_buffer));

    mem_trunk_free(&m_buffer, trunk);
    EXPECT_EQ((size_t)0, mem_buffer_size(&m_buffer));
}
Ejemplo n.º 7
0
TEST_F(BufferTest, trunk_append_twice) {
    struct mem_buffer_trunk * trunk = 
        mem_buffer_append_trunk(&m_buffer, 10);

    const char * data = "abcde";

    EXPECT_EQ((size_t)3, mem_trunk_append(&m_buffer, trunk, data, 3));
    EXPECT_EQ((size_t)3, mem_trunk_append(&m_buffer, trunk, data, 3));
    EXPECT_EQ((size_t)6, trunk->m_size);
    EXPECT_EQ((size_t)6, mem_buffer_size(&m_buffer));

    char buf = 0;
    EXPECT_EQ((size_t)1, mem_trunk_append(&m_buffer, trunk, &buf, 1));
    EXPECT_EQ((size_t)7, trunk->m_size);
    EXPECT_EQ((size_t)7, mem_buffer_size(&m_buffer));

    EXPECT_STREQ("abcabc", as_string());
}