コード例 #1
0
TEST_F(BufferTest, trunk_count_basic) {
    append_trunk("");
    append_trunk("");
    append_trunk("");

    EXPECT_EQ((size_t)3, mem_buffer_trunk_count(&m_buffer));
}
コード例 #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, trunk_at_basic) {
    struct mem_buffer_trunk * t1 = append_trunk("");
    struct mem_buffer_trunk * t2 = append_trunk("");
    struct mem_buffer_trunk * t3 = append_trunk("");

    EXPECT_TRUE(t1 == mem_buffer_trunk_at(&m_buffer, 0));
    EXPECT_TRUE(t2 == mem_buffer_trunk_at(&m_buffer, 1));
    EXPECT_TRUE(t3 == mem_buffer_trunk_at(&m_buffer, 2));
    EXPECT_TRUE(NULL == mem_buffer_trunk_at(&m_buffer, 3));
}
コード例 #4
0
TEST_F(BufferTest, append_multi_trunk) {
    EXPECT_TRUE(append_trunk("a"));
    EXPECT_TRUE(append_trunk("b"));
    EXPECT_TRUE(append_trunk("c"));

    append_zero();

    EXPECT_EQ((size_t)4, mem_buffer_size(&m_buffer));
    EXPECT_STREQ("abc", as_string());
}
コード例 #5
0
TEST_F(BufferTest, set_size_small_multi_trunk) {
    EXPECT_TRUE(append_trunk("aaa"));
    EXPECT_TRUE(append_trunk("bbb"));
    EXPECT_EQ((size_t)6, mem_buffer_size(&m_buffer));

    EXPECT_EQ(0, mem_buffer_set_size(&m_buffer, 1));
    EXPECT_EQ((size_t)1, mem_buffer_size(&m_buffer));

    EXPECT_EQ((size_t)2, mem_buffer_trunk_count(&m_buffer));
}
コード例 #6
0
TEST_F(BufferTest, make_exactly_multi_trunk) {
    char buf[5] = { 0 };

    EXPECT_TRUE(append_trunk("a"));
    EXPECT_TRUE(append_trunk("b"));
    EXPECT_TRUE(append_trunk("c"));

    memcpy(buf,mem_buffer_make_exactly(&m_buffer), mem_buffer_size(&m_buffer));

    EXPECT_STREQ("abc", buf);
}
コード例 #7
0
TEST_F(BufferTest, pos_seek_back_multi_trunk_with_empty_trunk_end) {
    append_trunk("a");
    append_trunk("");
    append_trunk("");

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

    EXPECT_EQ(-1, mem_pos_seek(&p, -1));
    EXPECT_EQ('a', mem_pos_data(&p));
}
コード例 #8
0
TEST_F(BufferTest, read_basic) {
    char buf[5];

    EXPECT_TRUE(append_trunk("a"));
    EXPECT_TRUE(append_trunk("b"));
    EXPECT_TRUE(append_trunk("c"));

    EXPECT_EQ(3, mem_buffer_read(buf, 5, &m_buffer));
    buf[3] = 0;

    EXPECT_STREQ("abc", buf);
}
コード例 #9
0
TEST_F(BufferTest, pos_insert_multi_trunk_at_trunk_last) {
    append_trunk("a");
    append_trunk("bc");
    append_trunk("d");

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

    EXPECT_EQ(3, mem_pos_insert(&p, "efg", 3));
    EXPECT_EQ('d', mem_pos_data(&p));

    append_zero();
    EXPECT_STREQ("abcefgd", as_string());
}
コード例 #10
0
TEST_F(BufferTest, pos_insert_enouth_in_current_middle) {
    append_trunk("a");
    append_trunk("bc");
    append_trunk("d");

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

    EXPECT_EQ(1, mem_pos_insert(&p, "efg", 1));
    EXPECT_EQ('c', mem_pos_data(&p));

    append_zero();
    EXPECT_STREQ("abecd", as_string());
}
コード例 #11
0
TEST_F(BufferTest, pos_diff_multi_trunk_middle_to_middle) {
    append_trunk("a");
    append_trunk("b");
    append_trunk("c");

    struct mem_buffer_pos b;
    mem_pos_at(&b, &m_buffer, 1);

    struct mem_buffer_pos e;
    mem_pos_at(&e, &m_buffer, 2);

    EXPECT_EQ(1, mem_pos_diff(&b, &e));
    EXPECT_EQ(-1, mem_pos_diff(&e, &b));
}
コード例 #12
0
TEST_F(BufferTest, pos_diff_same_multi_trunk) {
    append_trunk("a");
    append_trunk("b");
    append_trunk("c");

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

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

    EXPECT_EQ(3, mem_pos_diff(&b, &e));
    EXPECT_EQ(-3, mem_pos_diff(&e, &b));
}
コード例 #13
0
TEST_F(BufferTest, pos_seek_back_multi_trunk_all_empty_trunk) {
    append_trunk("");
    append_trunk("");
    append_trunk("");

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

    EXPECT_EQ(0, mem_pos_seek(&p, -1));

    struct mem_buffer_pos e;
    mem_buffer_end(&e, &m_buffer);
    EXPECT_TRUE(mem_pos_eq(&p, &e));
}
コード例 #14
0
TEST_F(BufferTest, pos_insert_not_use_empty_trunk) {
    append_trunk("a");
    append_trunk("bc");
    append_trunk(NULL);
    append_trunk("d");

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

    EXPECT_EQ(3, mem_pos_insert(&p, "efg", 3));
    EXPECT_EQ((size_t)5, trunk_count());
    EXPECT_EQ('d', mem_pos_data(&p));

    append_zero();
    EXPECT_STREQ("abcefgd", as_string());
}
コード例 #15
0
TEST_F(BufferTest, pos_seek_back_multi_trunk) {
    append_trunk("a");
    append_trunk("b");
    append_trunk("c");

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

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

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

    EXPECT_EQ(-1, mem_pos_seek(&p, -1));
    EXPECT_EQ('a', mem_pos_data(&p));
}
コード例 #16
0
TEST_F(BufferTest, pos_seek_back_from_head) {
    struct mem_buffer_trunk * t1 = append_trunk("abc");

    struct mem_buffer_pos p;
    mem_buffer_begin(&p, &m_buffer);
    EXPECT_EQ(0, mem_pos_seek(&p, -2));

    EXPECT_TRUE(t1 == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
}
コード例 #17
0
TEST_F(BufferTest, pos_seek_fwd_from_last) {
    append_trunk("abc");

    struct mem_buffer_pos p;
    mem_buffer_end(&p, &m_buffer);
    EXPECT_EQ(0, mem_pos_seek(&p, 2));

    EXPECT_TRUE(NULL == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
}
コード例 #18
0
TEST_F(BufferTest, pos_seek_fwd_to_last) {
    struct mem_buffer_trunk * t1 = append_trunk("abc");

    struct mem_buffer_pos p;
    mem_buffer_begin(&p, &m_buffer);
    EXPECT_EQ(2, mem_pos_seek(&p, 2));

    EXPECT_TRUE(t1 == p.m_trunk);
    EXPECT_EQ((size_t)2, p.m_pos_in_trunk);
}
コード例 #19
0
TEST_F(BufferTest, pos_seek_back_to_head) {
    struct mem_buffer_trunk * t1 = append_trunk("abc");

    struct mem_buffer_pos p;
    mem_buffer_end(&p, &m_buffer);
    EXPECT_EQ(-3, mem_pos_seek(&p, -3));

    EXPECT_TRUE(t1 == p.m_trunk);
    EXPECT_EQ((size_t)0, p.m_pos_in_trunk);
    EXPECT_EQ('a', mem_pos_data(&p));
}
コード例 #20
0
TEST_F(BufferTest, make_continuous_single_trunk) {
    char buf[5] = { 0 };

    struct mem_buffer_trunk * told = append_trunk("a");
    void * newDataAddr = mem_buffer_make_continuous(&m_buffer, 0);
    EXPECT_TRUE(told == trunk_at(0));

    memcpy(buf, newDataAddr, mem_buffer_size(&m_buffer));

    EXPECT_STREQ("a", buf);
}
コード例 #21
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());
}
コード例 #22
0
TEST_F(BufferTest, pos_diff_basic) {
    append_trunk("abc");

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

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

    EXPECT_EQ(3, mem_pos_diff(&b, &e));
    EXPECT_EQ(-3, mem_pos_diff(&e, &b));
}
コード例 #23
0
TEST_F(BufferTest, pos_diff_same_trunk) {
    append_trunk("abc");

    struct mem_buffer_pos b;
    mem_pos_at(&b, &m_buffer, 2);

    struct mem_buffer_pos e;
    mem_pos_at(&e, &m_buffer, 1);

    EXPECT_EQ(-1, mem_pos_diff(&b, &e));
    EXPECT_EQ(1, mem_pos_diff(&e, &b));
}
コード例 #24
0
TEST_F(BufferTest, pos_insert_at_trunk_middle) {
    append_trunk("def");

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

    EXPECT_EQ(3, mem_pos_insert(&p, "abc", 3));
    EXPECT_EQ('e', mem_pos_data(&p));

    append_zero();
    EXPECT_STREQ("dabcef", as_string());
}
コード例 #25
0
TEST_F(BufferTest, pos_insert_zero) {
    append_trunk("def");

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

    EXPECT_EQ(0, mem_pos_insert(&p, "", 0));
    EXPECT_EQ('d', mem_pos_data(&p));

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

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

    EXPECT_EQ(3, mem_pos_insert(&p, "abc", 3));
    EXPECT_EQ((size_t)6, buffer_size());
    EXPECT_EQ('d', mem_pos_data(&p));

    append_zero();
    EXPECT_STREQ("abcdef", as_string());
}
コード例 #27
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);
}