106 lines
3.1 KiB
C
106 lines
3.1 KiB
C
// Native surface validation test.
|
|
// Exercises invalid parameters and clipped dirty rectangles without depending on windowing.
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <ntlite/syscall.h>
|
|
|
|
#define SURFACE_W 32u
|
|
#define SURFACE_H 24u
|
|
|
|
static void print(const char* s) {
|
|
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) };
|
|
SysWriteConsole(&req);
|
|
}
|
|
|
|
static void print_u64(uint64_t v) {
|
|
char buf[32];
|
|
int i = 0;
|
|
if (v == 0) { print("0"); return; }
|
|
while (v && i < (int)sizeof(buf)) {
|
|
buf[i++] = (char)('0' + (v % 10));
|
|
v /= 10;
|
|
}
|
|
while (i--) {
|
|
char c = buf[i];
|
|
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromParts(&c, 1) };
|
|
SysWriteConsole(&req);
|
|
}
|
|
}
|
|
|
|
static void exit_now(int code) {
|
|
for (;;) SysExitProcess(code);
|
|
}
|
|
|
|
static void fail(const char* msg) {
|
|
print("surface_invalid_rect: ");
|
|
print(msg);
|
|
print("\n");
|
|
exit_now(1);
|
|
}
|
|
|
|
static void fail_status(const char* what, uint32_t status) {
|
|
print("surface_invalid_rect: ");
|
|
print(what);
|
|
print(" failed status=");
|
|
print_u64(status);
|
|
print("\n");
|
|
exit_now(1);
|
|
}
|
|
|
|
static void expect_status(const char* what, uint32_t got, uint32_t expected) {
|
|
if (got == expected) return;
|
|
print("surface_invalid_rect: ");
|
|
print(what);
|
|
print(" returned ");
|
|
print_u64(got);
|
|
print(" expected ");
|
|
print_u64(expected);
|
|
print("\n");
|
|
exit_now(1);
|
|
}
|
|
|
|
int main(void) {
|
|
print("surface_invalid_rect: start\n");
|
|
|
|
uint32_t bad = 0;
|
|
uint32_t s = SysCreateSurface(0, SURFACE_H, SYS_SURFACE_FORMAT_XRGB8888, SYS_SURFACE_FLAG_NONE, &bad);
|
|
expect_status("zero width", s, SYS_STATUS_INVALID_PARAMETER);
|
|
|
|
s = SysCreateSurface(SURFACE_W, SURFACE_H, 0x9999u, SYS_SURFACE_FLAG_NONE, &bad);
|
|
expect_status("bad format", s, SYS_STATUS_NOT_SUPPORTED);
|
|
|
|
uint32_t surface = 0;
|
|
s = SysCreateSurface(SURFACE_W, SURFACE_H, SYS_SURFACE_FORMAT_XRGB8888,
|
|
SYS_SURFACE_FLAG_NONE, &surface);
|
|
if (s != SYS_STATUS_SUCCESS) fail_status("create surface", s);
|
|
|
|
void* base = 0;
|
|
uint32_t pitch = 0;
|
|
s = SysMapSurface(surface, &base, &pitch);
|
|
if (s != SYS_STATUS_SUCCESS) fail_status("map surface", s);
|
|
if (!base || pitch < SURFACE_W * sizeof(uint32_t)) fail("invalid mapping");
|
|
|
|
s = SysPresentSurface(surface, 0, 1);
|
|
expect_status("null rect array with nonzero count", s, SYS_STATUS_INVALID_PARAMETER);
|
|
|
|
DISPLAY_RECT rects[SYS_SURFACE_MAX_RECTS + 1];
|
|
memset(rects, 0, sizeof(rects));
|
|
s = SysPresentSurface(surface, rects, SYS_SURFACE_MAX_RECTS + 1);
|
|
expect_status("too many rects", s, SYS_STATUS_INVALID_PARAMETER);
|
|
|
|
DISPLAY_RECT clipped = { -8, -8, 24, 24 };
|
|
s = SysPresentSurface(surface, &clipped, 1);
|
|
if (s != SYS_STATUS_SUCCESS) fail_status("present clipped rect", s);
|
|
|
|
DISPLAY_RECT empty = { 10000, 10000, 16, 16 };
|
|
s = SysPresentSurface(surface, &empty, 1);
|
|
if (s != SYS_STATUS_SUCCESS) fail_status("present empty clipped rect", s);
|
|
|
|
SysCloseHandle(surface);
|
|
print("surface_invalid_rect: PASS\n");
|
|
exit_now(0);
|
|
return 0;
|
|
}
|