mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-21 11:11:37 +00:00
[console] Add test for buffer line tracking
Seems to work, so I guess con_buffer is ok now.
This commit is contained in:
parent
48e5848a41
commit
3eceb444d3
1 changed files with 91 additions and 2 deletions
|
@ -74,7 +74,7 @@ test_2 (void)
|
|||
Con_BufferAddText (con, text);
|
||||
|
||||
if (con->line_head != 1) {
|
||||
printf ("con_buffer num_lines incorrect: %d\n", con->line_head);
|
||||
printf ("con_buffer line_head incorrect: %d\n", con->line_head);
|
||||
goto fail;
|
||||
}
|
||||
if (con->line_tail != 0) {
|
||||
|
@ -104,7 +104,7 @@ test_2 (void)
|
|||
Con_BufferAddText (con, "N");
|
||||
|
||||
if (con->line_head != 1) {
|
||||
printf ("2 con_buffer num_lines incorrect: %d\n", con->line_head);
|
||||
printf ("2 con_buffer line_head incorrect: %d\n", con->line_head);
|
||||
goto fail;
|
||||
}
|
||||
if (con->line_tail != 0) {
|
||||
|
@ -137,11 +137,100 @@ fail:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
test_3 (void)
|
||||
{
|
||||
int ret = 1;
|
||||
static char text[] = R"(01 don't forget this line
|
||||
02 and some more lines here
|
||||
03 adsf
|
||||
04 adfa
|
||||
06 hi there
|
||||
06 don't forget there's line 07
|
||||
)";
|
||||
static uint32_t lengths[] = { 26, 28, 9, 8, 12, 32, 0 };
|
||||
static uint32_t lengths2[] = { 1, 5, 2 };
|
||||
|
||||
__auto_type con = Con_CreateBuffer (256, 8);
|
||||
Con_BufferAddText (con, text);
|
||||
|
||||
if (con->line_head != 7) {
|
||||
printf ("con_buffer line_head incorrect: %d\n", con->line_head);
|
||||
goto fail;
|
||||
}
|
||||
if (con->line_tail != 0) {
|
||||
printf ("con_buffer line_tail incorrect: %d\n", con->line_tail);
|
||||
goto fail;
|
||||
}
|
||||
uint32_t offs = 0;
|
||||
for (uint32_t i = 0; i < 7; i++) {
|
||||
if (con->lines[i].text != offs) {
|
||||
printf ("con_buffer lines[%d].text incorrect: %u %u\n",
|
||||
i, con->lines[i].text, offs);
|
||||
goto fail;
|
||||
}
|
||||
if (con->lines[i].len != lengths[i]) {
|
||||
printf ("con_buffer lines[%d].len incorrect: %u %u\n",
|
||||
i, con->lines[i].len, lengths[i]);
|
||||
goto fail;
|
||||
}
|
||||
offs += lengths[i];
|
||||
}
|
||||
|
||||
Con_BufferAddText (con, "\nasdf\nas");
|
||||
if (con->line_head != 1) {
|
||||
printf ("2 con_buffer line_head incorrect: %d\n", con->line_head);
|
||||
goto fail;
|
||||
}
|
||||
if (con->line_tail != 2) {
|
||||
printf ("2 con_buffer line_tail incorrect: %d\n", con->line_tail);
|
||||
goto fail;
|
||||
}
|
||||
offs = lengths[0] + lengths[1];
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
uint32_t n = i + 2;
|
||||
if (con->lines[n].text != offs) {
|
||||
printf ("2 con_buffer lines[%d].text incorrect: %u %u\n",
|
||||
n, con->lines[n].text, offs);
|
||||
goto fail;
|
||||
}
|
||||
if (con->lines[n].len != lengths[n]) {
|
||||
printf ("2 con_buffer lines[%d].len incorrect: %u %u\n",
|
||||
n, con->lines[n].len, lengths[n]);
|
||||
goto fail;
|
||||
}
|
||||
offs += lengths[n];
|
||||
}
|
||||
for (uint32_t i = 0; i < 3; i++) {
|
||||
uint32_t n = (i + 6) % con->max_lines;
|
||||
if (con->lines[n].text != offs) {
|
||||
printf ("3 con_buffer lines[%d].text incorrect: %u %u\n",
|
||||
n, con->lines[n].text, offs);
|
||||
goto fail;
|
||||
}
|
||||
if (con->lines[n].len != lengths2[i]) {
|
||||
printf ("3 con_buffer lines[%d].len incorrect: %u %u\n",
|
||||
n, con->lines[n].len, lengths2[i]);
|
||||
goto fail;
|
||||
}
|
||||
offs += lengths2[i];
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
if (ret) {
|
||||
printf ("%s failed\n", __FUNCTION__);
|
||||
}
|
||||
Con_DestroyBuffer (con);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int ret = 0;
|
||||
ret |= test_1 ();
|
||||
ret |= test_2 ();
|
||||
ret |= test_3 ();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue