|
|
|
@ -13,23 +13,23 @@ void test_bytebuf_simple(void) {
|
|
|
|
|
assert(ok);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "hello", sizeof("hello") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 5);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 5);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_read(&buf, data, 4);
|
|
|
|
|
assert(!strncmp((char *) data, "hell", 4));
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) " world", sizeof(" world") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 7);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 7);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "!", 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 8);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 8);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_read(&buf, &data[4], 8);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 0);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 0);
|
|
|
|
|
|
|
|
|
|
data[12] = '\0';
|
|
|
|
|
assert(!strcmp((char *) data, "hello world!"));
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 0);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 0);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_destroy(&buf);
|
|
|
|
|
}
|
|
|
|
@ -42,31 +42,31 @@ void test_bytebuf_boundaries(void) {
|
|
|
|
|
assert(ok);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "hello ", sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 6);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 6);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "hello ", sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 12);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 12);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "hello ", sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 18);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 18);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_read(&buf, data, 9);
|
|
|
|
|
assert(!strncmp((char *) data, "hello hel", 9));
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 9);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 9);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "world", sizeof("world") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 14);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 14);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "!", 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 15);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 15);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_skip(&buf, 3);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 12);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 12);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_read(&buf, data, 12);
|
|
|
|
|
data[12] = '\0';
|
|
|
|
|
assert(!strcmp((char *) data, "hello world!"));
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 0);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 0);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_destroy(&buf);
|
|
|
|
|
}
|
|
|
|
@ -79,37 +79,37 @@ void test_bytebuf_two_steps_write(void) {
|
|
|
|
|
assert(ok);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "hello ", sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 6);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 6);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "hello ", sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 12);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 12);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_prepare_write(&buf, (uint8_t *) "hello ", sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 12); // write not committed yet
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 12); // write not committed yet
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_read(&buf, data, 9);
|
|
|
|
|
assert(!strncmp((char *) data, "hello hel", 3));
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 3);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 3);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_commit_write(&buf, sizeof("hello ") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 9);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 9);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_prepare_write(&buf, (uint8_t *) "world", sizeof("world") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 9); // write not committed yet
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 9); // write not committed yet
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_commit_write(&buf, sizeof("world") - 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 14);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 14);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_write(&buf, (uint8_t *) "!", 1);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 15);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 15);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_skip(&buf, 3);
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 12);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 12);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_read(&buf, data, 12);
|
|
|
|
|
data[12] = '\0';
|
|
|
|
|
assert(!strcmp((char *) data, "hello world!"));
|
|
|
|
|
assert(sc_bytebuf_read_available(&buf) == 0);
|
|
|
|
|
assert(sc_bytebuf_can_read(&buf) == 0);
|
|
|
|
|
|
|
|
|
|
sc_bytebuf_destroy(&buf);
|
|
|
|
|
}
|
|
|
|
|