mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-29 20:28:59 +00:00
Add string buffer util
This will help to build strings incrementally.
This commit is contained in:
parent
570a003c39
commit
6dba1922c1
4 changed files with 212 additions and 0 deletions
47
app/tests/test_strbuf.c
Normal file
47
app/tests/test_strbuf.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "common.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue