File: test_buffer_insert.c

package info (click to toggle)
mle 1.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,108 kB
  • sloc: ansic: 13,335; sh: 728; php: 228; makefile: 83
file content (29 lines) | stat: -rw-r--r-- 983 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "test.h"

char *str = "hello\nworld";

void test(buffer_t *buf, mark_t *cur) {
    char *data;
    bint_t data_len;
    bint_t nchars;

    buffer_insert(buf, 0, "\xe4\xb8\x96\xe7\x95\x8c\n", 7, &nchars);
    buffer_get(buf, &data, &data_len);
    ASSERT("bol", 0, strncmp(data, "\xe4\xb8\x96\xe7\x95\x8c\nhello\nworld", data_len));
    ASSERT("bolnchars", 3, nchars);

    buffer_insert(buf, 3, "s", 1, &nchars);
    buffer_get(buf, &data, &data_len);
    ASSERT("3", 0, strncmp(data, "\xe4\xb8\x96\xe7\x95\x8c\nshello\nworld", data_len));
    ASSERT("3nchars", 1, nchars);

    buffer_insert(buf, 7, "\n\n", 2, &nchars);
    buffer_get(buf, &data, &data_len);
    ASSERT("nlnl", 0, strncmp(data, "\xe4\xb8\x96\xe7\x95\x8c\nshel\n\nlo\nworld", data_len));
    ASSERT("nlnlnchars", 2, nchars);

    buffer_insert(buf, 20, "!", 1, NULL);
    buffer_get(buf, &data, &data_len);
    ASSERT("oob", 0, strncmp(data, "\xe4\xb8\x96\xe7\x95\x8c\nshel\n\nlo\nworld!", data_len));
}