From 5e8d18a7745c53d35fac54b2507d62ac9cbc9ab2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 17 Sep 2022 15:31:52 +0900 Subject: [PATCH] [console] Add failing test for adding to full 1-line buffer I've decided that appending to a full single-line buffer should simply scroll through the existing text. Unsurprisingly, the existing code doesn't handle the situation all that well. While I've already got a fix for it, I think I've got a better idea that will handle full buffers more gracefully. --- libs/console/test/test-buffer.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/console/test/test-buffer.c b/libs/console/test/test-buffer.c index 21738d350..5ebeca7a5 100644 --- a/libs/console/test/test-buffer.c +++ b/libs/console/test/test-buffer.c @@ -96,6 +96,35 @@ test_2 (void) goto fail; } + // add a single char at the end of the full buffer the buffer should + // just effectively scroll through the text as chars are added (via + // the single line object maintaining constant length but updating its + // text pointer) + Con_BufferAddText (con, "N"); + if (con->num_lines != 1) { + printf ("con_buffer num_lines incorrect: %d\n", con->num_lines); + goto fail; + } + if (con->cur_line != 0) { + printf ("con_buffer cur_line incorrect: %d\n", con->cur_line); + goto fail; + } + if (con->lines[con->cur_line].text != con->buffer + 1) { + printf ("con_buffer cur_line.text incorrect: %p, %p\n", + con->lines[con->cur_line].text, con->buffer + 1); + goto fail; + } + if (con->lines[con->cur_line].len != 1024) { + printf ("con_buffer cur_line.line incorrect: %zd\n", + con->lines[con->cur_line].len); + goto fail; + } + if (memcmp (con->buffer + 1, text + 1024 + 1, 1024 - 1) + || con->buffer[0] != 'N') { + printf ("con_buffer incorrect\n"); + goto fail; + } + ret = 0; fail: if (ret) {