85 lines
1.9 KiB
C
85 lines
1.9 KiB
C
#include "test.h"
|
|
#include <limits.h>
|
|
|
|
void
|
|
popup_layout(struct ct *t)
|
|
{
|
|
static const struct {
|
|
int first;
|
|
int shown;
|
|
int total;
|
|
char *want;
|
|
} markers[] = {
|
|
{ 0, 0, 0, "" },
|
|
{ 0, 9, 9, "" },
|
|
{ 0, 9, 10, "1-9/10" },
|
|
{ 9, 1, 10, "10-10/10" },
|
|
{ 0, 9, 18, "1-9/18" },
|
|
{ 9, 9, 18, "10-18/18" },
|
|
{ 9, 9, 32, "10-18/32" },
|
|
{ 18, 9, 32, "19-27/32" },
|
|
{ 27, 5, 32, "28-32/32" },
|
|
};
|
|
char buf[32];
|
|
Caret caret;
|
|
int i, n, x, y;
|
|
|
|
for(i = 0; i < nelem(markers); i++){
|
|
n = pagemarker(buf, sizeof buf, markers[i].first,
|
|
markers[i].shown, markers[i].total);
|
|
CT_EQ_INT(t, strlen(markers[i].want), n);
|
|
CT_CHECK(t, strcmp(markers[i].want, buf) == 0);
|
|
}
|
|
CT_EQ_INT(t, (1 + Maxdisp + 1) * Fontsz, Imgh);
|
|
|
|
memset(&caret, 0, sizeof caret);
|
|
popupposition(&caret, 40, 50, 800, 600, 100, 60, &x, &y);
|
|
CT_EQ_INT(t, 50, x);
|
|
CT_EQ_INT(t, 60, y);
|
|
caret.valid = 1;
|
|
caret.x = 70;
|
|
caret.y = 80;
|
|
caret.h = 20;
|
|
popupposition(&caret, 40, 50, 800, 600, 100, 60, &x, &y);
|
|
CT_EQ_INT(t, 70, x);
|
|
CT_EQ_INT(t, 100, y);
|
|
caret.x = 790;
|
|
caret.y = 590;
|
|
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
|
|
CT_EQ_INT(t, 700, x);
|
|
CT_EQ_INT(t, 530, y);
|
|
|
|
/* Neither side fits: choose above, then clamp to the screen. */
|
|
caret.x = 20;
|
|
caret.y = 30;
|
|
caret.h = 20;
|
|
popupposition(&caret, 0, 0, 80, 80, 100, 100, &x, &y);
|
|
CT_EQ_INT(t, 0, x);
|
|
CT_EQ_INT(t, 0, y);
|
|
|
|
caret.x = 70;
|
|
caret.y = 80;
|
|
caret.h = 0;
|
|
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
|
|
CT_EQ_INT(t, 70, x);
|
|
CT_EQ_INT(t, 80, y);
|
|
caret.h = -20;
|
|
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
|
|
CT_EQ_INT(t, 70, x);
|
|
CT_EQ_INT(t, 80, y);
|
|
|
|
caret.x = INT_MIN;
|
|
caret.y = INT_MAX;
|
|
caret.h = INT_MAX;
|
|
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
|
|
CT_EQ_INT(t, 0, x);
|
|
CT_EQ_INT(t, 540, y);
|
|
caret.x = INT_MAX;
|
|
caret.y = INT_MIN;
|
|
caret.h = INT_MIN;
|
|
popupposition(&caret, 0, 0, INT_MAX, INT_MAX,
|
|
INT_MAX, INT_MAX, &x, &y);
|
|
CT_EQ_INT(t, 0, x);
|
|
CT_EQ_INT(t, 0, y);
|
|
}
|