Files
kryon/tests/text_input_platform_test.c
T

88 lines
2.1 KiB
C

#include "kryon.h"
#include <stdio.h>
static int callback_count;
static int events[8];
void ClearTextInputFocus(void);
static void
text_input_callback(int active)
{
if(callback_count < (int)(sizeof(events) / sizeof(events[0])))
events[callback_count] = active != 0;
callback_count++;
}
static int
check_event(int index, int expected)
{
if(index >= callback_count) {
fprintf(stderr, "FAIL: missing callback %d\n", index);
return 0;
}
if(events[index] != expected) {
fprintf(stderr, "FAIL: callback %d got %d want %d\n",
index, events[index], expected);
return 0;
}
return 1;
}
int
main(void)
{
int ok = 1;
SetTextInputPlatformCallback(text_input_callback);
ok &= TextInputActive() == 0;
if(TextInputActive() != 0)
fprintf(stderr, "FAIL: text input active initially got %d want 0\n",
TextInputActive());
BeginInterfaceFrame(640, 480, 1.0f);
SetFocusTextInputActive(1);
ok &= TextInputActive() == 1;
if(TextInputActive() != 1)
fprintf(stderr, "FAIL: text input active after focus got %d want 1\n",
TextInputActive());
EndInterfaceFrame();
BeginInterfaceFrame(640, 480, 1.0f);
SetFocusTextInputActive(0);
ok &= TextInputActive() == 0;
if(TextInputActive() != 0)
fprintf(stderr, "FAIL: text input active after clear got %d want 0\n",
TextInputActive());
EndInterfaceFrame();
BeginInterfaceFrame(640, 480, 1.0f);
SetFocusTextInputActive(1);
EndInterfaceFrame();
BeginInterfaceFrame(640, 480, 1.0f);
SetFocusTextInputActive(0);
SetFocusTextInputActive(1);
EndInterfaceFrame();
BeginInterfaceFrame(640, 480, 1.0f);
ClearTextInputFocus();
EndInterfaceFrame();
ok &= callback_count == 4;
if(callback_count != 4)
fprintf(stderr, "FAIL: callback count got %d want 4\n", callback_count);
ok &= check_event(0, 1);
ok &= check_event(1, 0);
ok &= check_event(2, 1);
ok &= check_event(3, 0);
SetTextInputPlatformCallback(NULL);
if(ok)
printf("text_input_platform_test: OK\n");
return ok ? 0 : 1;
}