File: test_strbuf.c

package info (click to toggle)
scrcpy 3.3.4-1
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 2,832 kB
  • sloc: ansic: 22,489; java: 10,142; sh: 953; xml: 94; makefile: 30
file content (48 lines) | stat: -rw-r--r-- 972 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "common.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "util/strbuf.h"

static void test_strbuf_simple(void) {
    struct sc_strbuf buf;
    bool ok = sc_strbuf_init(&buf, 10);
    assert(ok);

    ok = sc_strbuf_append_staticstr(&buf, "Hello");
    assert(ok);

    ok = sc_strbuf_append_char(&buf, ' ');
    assert(ok);

    ok = sc_strbuf_append_staticstr(&buf, "world");
    assert(ok);

    ok = sc_strbuf_append_staticstr(&buf, "!\n");
    assert(ok);

    ok = sc_strbuf_append_staticstr(&buf, "This is a test");
    assert(ok);

    ok = sc_strbuf_append_n(&buf, '.', 3);
    assert(ok);

    assert(!strcmp(buf.s, "Hello world!\nThis is a test..."));

    sc_strbuf_shrink(&buf);
    assert(buf.len == buf.cap);
    assert(!strcmp(buf.s, "Hello world!\nThis is a test..."));

    free(buf.s);
}

int main(int argc, char *argv[]) {
    (void) argc;
    (void) argv;

    test_strbuf_simple();
    return 0;
}