Add stream structure and utilities
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
#include "test_stream.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(c8, &stream) : !wpStreamAtEnd(c8, &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;
|
||||
while (!wpStreamAtEnd(c8, &stream)) {
|
||||
c = wpStreamPeek(c8, &stream);
|
||||
wpStreamConsume(c8, &stream);
|
||||
result = result && (wpStreamAtEnd(c8, &stream) ? c == NULL : 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);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
#include "test_stream.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(c8, &stream) : !wpStreamAtEnd(c8, &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;
|
||||
while (!wpStreamAtEnd(c8, &stream)) {
|
||||
c = wpStreamPeek(c8, &stream);
|
||||
wpStreamConsume(c8, &stream);
|
||||
result = result && (wpStreamAtEnd(c8, &stream) ? c == NULL : 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);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
#ifndef TEST_STREAM_H
|
||||
#define TEST_STREAM_H
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
WpTestFuncResult test_stream_at_end(void);
|
||||
WpTestFuncResult test_stream_peek(void);
|
||||
WpTestFuncResult test_stream_consume(void);
|
||||
|
||||
#endif // !TEST_STREAM_H
|
||||
Reference in New Issue
Block a user