summaryrefslogtreecommitdiffstats
path: root/src/tests/linebuf_test.c
diff options
context:
space:
mode:
authorMichael Brown2007-01-12 18:08:37 +0100
committerMichael Brown2007-01-12 18:08:37 +0100
commit996b091b50ccdc317b2a7501dd2fe18b0a3d421a (patch)
tree8751c8b77d43a7697dbaec151fe1d013cef97313 /src/tests/linebuf_test.c
parentPlace multiboot tables in base memory; at least some OSes won't see it (diff)
downloadipxe-996b091b50ccdc317b2a7501dd2fe18b0a3d421a.tar.gz
ipxe-996b091b50ccdc317b2a7501dd2fe18b0a3d421a.tar.xz
ipxe-996b091b50ccdc317b2a7501dd2fe18b0a3d421a.zip
Added generic line-buffering code (a la stdio)
Diffstat (limited to 'src/tests/linebuf_test.c')
-rw-r--r--src/tests/linebuf_test.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tests/linebuf_test.c b/src/tests/linebuf_test.c
new file mode 100644
index 00000000..9ddbb75a
--- /dev/null
+++ b/src/tests/linebuf_test.c
@@ -0,0 +1,27 @@
+#include <stdint.h>
+#include <string.h>
+#include <vsprintf.h>
+#include <gpxe/linebuf.h>
+
+static const char data1[] =
+"Hello world\r\n"
+"This is a particularly mean set of lines\n"
+"with a mixture of terminators\r\r\n"
+"There should be exactly one blank line above\n"
+"and this line should never appear at all since it has no terminator";
+
+void linebuf_test ( void ) {
+ struct line_buffer linebuf;
+ const char *data = data1;
+ size_t len = ( sizeof ( data1 ) - 1 /* be mean; strip the NUL */ );
+ size_t buffered;
+
+ memset ( &linebuf, 0, sizeof ( linebuf ) );
+ while ( ( buffered = line_buffer ( &linebuf, data, len ) ) != len ) {
+ printf ( "\"%s\"\n", buffered_line ( &linebuf ) );
+ data += buffered;
+ len -= buffered;
+ }
+
+ empty_line_buffer ( &linebuf );
+}