コード例 #1
0
TEST_F(BufferTest, pos_seek_fwd_empty) {
    struct mem_buffer_pos p;
    mem_buffer_begin(&p, &m_buffer);
    EXPECT_FALSE(mem_pos_valide(&p));

    EXPECT_EQ(0, mem_pos_seek(&p, 1));
    EXPECT_TRUE(NULL == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
    EXPECT_FALSE(mem_pos_valide(&p));
}
コード例 #2
0
TEST_F(BufferTest, pos_seek_fwd_multi_trunk) {
    struct mem_buffer_trunk * t1 = append_trunk("a");
    struct mem_buffer_trunk * t2 = append_trunk("b");
    struct mem_buffer_trunk * t3 = append_trunk("c");

    struct mem_buffer_pos p;
    mem_buffer_begin(&p, &m_buffer);
    EXPECT_TRUE(t1 == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
    EXPECT_EQ('a', mem_pos_data(&p));

    EXPECT_EQ(1, mem_pos_seek(&p, 1));
    EXPECT_TRUE(t2 == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
    EXPECT_EQ('b', mem_pos_data(&p));

    EXPECT_EQ(1, mem_pos_seek(&p, 1));
    EXPECT_TRUE(t3 == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
    EXPECT_EQ('c', mem_pos_data(&p));

    EXPECT_EQ(1, mem_pos_seek(&p, 1));
    EXPECT_TRUE(NULL == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
    EXPECT_FALSE(mem_pos_valide(&p));
}
コード例 #3
0
TEST_F(BufferTest, pos_valid_end) {
    append_string("a");

    struct mem_buffer_pos l;
    mem_buffer_end(&l, &m_buffer);

    EXPECT_EQ(0, mem_pos_valide(&l));
}
コード例 #4
0
TEST_F(BufferTest, pos_valid_head) {
    append_string("a");

    struct mem_buffer_pos l;
    mem_buffer_begin(&l, &m_buffer);

    EXPECT_EQ(1, mem_pos_valide(&l));
}
コード例 #5
0
TEST_F(BufferTest, pos_insert_in_empty) {
    struct mem_buffer_pos p;
    mem_pos_at(&p, &m_buffer, 3);

    EXPECT_EQ(3, mem_pos_insert(&p, "abc", 3));
    EXPECT_FALSE(mem_pos_valide(&p));

    append_zero();
    EXPECT_STREQ("abc", as_string());
}
コード例 #6
0
TEST_F(BufferTest, pos_insert_at_trunk_last) {
    append_trunk("def");

    struct mem_buffer_pos p;
    mem_pos_at(&p, &m_buffer, 3);

    EXPECT_EQ(3, mem_pos_insert(&p, "abc", 3));
    EXPECT_FALSE(mem_pos_valide(&p));

    append_zero();
    EXPECT_STREQ("defabc", as_string());
}
コード例 #7
0
TEST_F(BufferTest, pos_seek_back_basic) {
    struct mem_buffer_trunk * t1 = append_trunk("abc");

    struct mem_buffer_pos p;
    mem_buffer_end(&p, &m_buffer);
    EXPECT_FALSE(mem_pos_valide(&p));

    EXPECT_EQ(-1, mem_pos_seek(&p, -1));
    EXPECT_EQ('c', mem_pos_data(&p));

    EXPECT_TRUE(t1 == p.m_trunk);
    EXPECT_EQ((size_t)2, p.m_pos_in_trunk);
}
コード例 #8
0
TEST_F(BufferTest, pos_at) {
    append_string("abc");

    struct mem_buffer_pos p;
    mem_pos_at(&p, &m_buffer, 0);
    EXPECT_EQ('a', mem_pos_data(&p));

    mem_pos_at(&p, &m_buffer, 1);
    EXPECT_EQ('b', mem_pos_data(&p));

    mem_pos_at(&p, &m_buffer, 2);
    EXPECT_EQ('c', mem_pos_data(&p));

    mem_pos_at(&p, &m_buffer, 3);
    EXPECT_FALSE(mem_pos_valide(&p));
}
コード例 #9
0
char mem_pos_data(mem_buffer_pos_t l) {
    assert(mem_pos_valide(l));
    return ((char *)mem_trunk_data(l->m_trunk))[l->m_pos_in_trunk];
}