83 lines
1.9 KiB
C
83 lines
1.9 KiB
C
// vim:fileencoding=utf-8:foldmethod=marker
|
|
|
|
#include "test_stream.h"
|
|
#include <stdio.h>
|
|
|
|
#define COUNT 3
|
|
|
|
WpTestFuncResult test_stream_at_end(void) {
|
|
b8 result = true;
|
|
|
|
c8 characters[COUNT] = {'a', 'b', 'c'};
|
|
WpC8Stream stream = wpStream(c8, characters, COUNT);
|
|
|
|
for (u32 i = 0; i < COUNT; ++i) {
|
|
wpStreamConsume(c8, &stream);
|
|
result = result && (i == 2 ? wpStreamAtEnd(&stream) : !wpStreamAtEnd(&stream));
|
|
}
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_stream_peek(void) {
|
|
b8 result = true;
|
|
|
|
c8 characters[COUNT] = {'a', 'b', 'c'};
|
|
WpC8Stream stream = wpStream(c8, characters, COUNT);
|
|
|
|
c8 *c = NULL;
|
|
for (u32 i = 0; i <= COUNT; ++i) {
|
|
c = wpStreamPeek(c8, &stream);
|
|
wpStreamConsume(c8, &stream);
|
|
result = result && (i == 3 ? c == NULL : c != NULL);
|
|
}
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_stream_peek_with_offset(void) {
|
|
b8 result = true;
|
|
|
|
c8 characters[COUNT] = {'a', 'b', 'c'};
|
|
WpC8Stream stream = wpStream(c8, characters, COUNT);
|
|
|
|
u64 offset = 2;
|
|
c8 *c = wpStreamPeekWithOffset(c8, &stream, offset);
|
|
result = result && *c == characters[offset];
|
|
|
|
c = wpStreamPeekWithOffset(c8, &stream, 5);
|
|
result = result && c == NULL;
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_stream_consume(void) {
|
|
b8 result = true;
|
|
|
|
c8 characters[COUNT] = {'a', 'b', 'c'};
|
|
WpC8Stream stream = wpStream(c8, characters, COUNT);
|
|
|
|
c8 *c = NULL;
|
|
for (u32 i = 0; i <= COUNT; ++i) {
|
|
c = wpStreamConsume(c8, &stream);
|
|
result = result && (i == COUNT ? c == NULL : c != NULL);
|
|
}
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_stream_consume_count(void) {
|
|
b8 result = true;
|
|
|
|
c8 characters[COUNT] = {'a', 'b', 'c'};
|
|
WpC8Stream stream = wpStream(c8, characters, COUNT);
|
|
|
|
c8 *c = wpStreamConsumeCount(c8, &stream, COUNT);
|
|
result = result && c != NULL && wpStreamAtEnd(&stream);
|
|
|
|
c = wpStreamConsumeCount(c8, &stream, COUNT);
|
|
result = result && c == NULL;
|
|
|
|
return wpTesterResult(result);
|
|
}
|