test: update b_stream usage
This commit is contained in:
@@ -153,39 +153,33 @@ void test_queue_iterate(CuTest *tc)
|
||||
void test_stringstream_1(CuTest *tc)
|
||||
{
|
||||
char buf[1024];
|
||||
b_stringstream s;
|
||||
b_stringstream_begin(&s, buf, sizeof buf);
|
||||
b_stringstream *s = b_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
b_stringstream_add(&s, "hello");
|
||||
b_stringstream_addf(&s, "(%d + %.1f)", 32, 2.3);
|
||||
b_stream_write_string(s, "hello", NULL);
|
||||
b_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
|
||||
|
||||
const char *x[] = {"ABC", "DEF", NULL};
|
||||
char *end = b_stringstream_steal(s);
|
||||
b_stringstream_unref(s);
|
||||
|
||||
b_stringstream_addv(&s, x);
|
||||
b_stringstream_addvl(&s, x, 2);
|
||||
|
||||
b_stringstream_add_many(&s, "more", "more", "more", NULL);
|
||||
const char *end = b_stringstream_end(&s);
|
||||
|
||||
CuAssertStrEquals(tc, "hello(32 + 2.3)ABCDEFABCDEFmoremoremore", end);
|
||||
CuAssertStrEquals(tc, "hello(32 + 2.3)", end);
|
||||
}
|
||||
|
||||
void test_stringstream_2(CuTest *tc)
|
||||
{
|
||||
char buf[1024];
|
||||
b_stringstream s;
|
||||
b_stringstream_begin(&s, buf, sizeof buf);
|
||||
b_stringstream *s = b_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
b_stringstream_add(&s, "{\n");
|
||||
b_stringstream_push_indent(&s, 1);
|
||||
b_stream_write_string(s, "{\n", NULL);
|
||||
b_stream_push_indent(s, 1);
|
||||
|
||||
b_stringstream_add(&s, "a = 32,\n");
|
||||
b_stringstream_add(&s, "b = 64\n");
|
||||
b_stream_write_string(s, "a = 32,\n", NULL);
|
||||
b_stream_write_string(s, "b = 64\n", NULL);
|
||||
|
||||
b_stringstream_pop_indent(&s);
|
||||
b_stringstream_add(&s, "}");
|
||||
b_stream_pop_indent(s);
|
||||
b_stream_write_string(s, "}", NULL);
|
||||
|
||||
char *str = b_stringstream_end(&s);
|
||||
char *str = b_stringstream_steal(s);
|
||||
b_stringstream_unref(s);
|
||||
|
||||
CuAssertStrEquals(tc, "{\n a = 32,\n b = 64\n}", str);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user