#include "../tdkpin_game_windows.h" #include #include #include #include enum { WINDOW_HANDLE = 4, WINDOW_ATTRIBUTES = 0x21, WINDOW_X = 0x29, WINDOW_Y = 0x2b, WINDOW_WIDTH = 0x2d, WINDOW_HEIGHT = 0x2f, WINDOW_OWNER = 0x41, }; static uint8_t g_objects[0x1000]; static bool g_enter; static uint32_t g_base_style; static INT16 g_screen_width; static INT16 g_screen_height; static unsigned g_base_calls; static Win16FarPtr g_expected_title; static Win16FarPtr g_expected_parent; static unsigned g_focus_calls; static HWND16 g_focused_window; static Win16FarPtr object_at(uint16_t offset) { return win16_make_far_pointer(0x6000, offset); } static void reset_fixture(void) { memset(g_objects, 0, sizeof(g_objects)); win16_reset_segment_bindings(); win16_bind_segment(0x6000, g_objects, sizeof(g_objects), true); g_enter = true; g_base_style = 0; g_screen_width = 1024; g_screen_height = 768; g_base_calls = 0; g_expected_title = object_at(0x700); g_expected_parent = object_at(0x800); g_focus_calls = 0; g_focused_window = 0; } bool borland_enter_object_constructor( BorlandObjectCallFrame *frame, uint16_t offset) { assert(offset == 0); if (g_enter && frame->vmt_argument != 0) { win16_write_u16(frame->object, 0, frame->vmt_argument); } return g_enter; } Win16FarPtr object_windows_window_construct( Win16FarPtr window, uint16_t vmt, Win16FarPtr title, Win16FarPtr parent) { assert(vmt == 0); assert(title == g_expected_title); assert(parent == g_expected_parent); g_base_calls++; win16_write_u32(window, WINDOW_ATTRIBUTES, g_base_style); win16_write_u16(window, WINDOW_HANDLE, 0x4444); return window; } INT16 GetSystemMetrics16(INT16 index) { assert(index == 0 || index == 1); return index == 0 ? g_screen_width : g_screen_height; } HWND16 SetFocus16(HWND16 window) { g_focus_calls++; g_focused_window = window; return 0x9999; } static void assert_geometry( Win16FarPtr window, INT16 x, INT16 y, uint16_t width, uint16_t height) { assert((INT16)win16_read_u16( win16_far_add_offset(window, WINDOW_X)) == x); assert((INT16)win16_read_u16( win16_far_add_offset(window, WINDOW_Y)) == y); assert(win16_read_u16( win16_far_add_offset(window, WINDOW_WIDTH)) == width); assert(win16_read_u16( win16_far_add_offset(window, WINDOW_HEIGHT)) == height); } static void test_main_window(void) { reset_fixture(); Win16FarPtr window = object_at(0x100); assert(tdkpin_main_window_construct( window, 0x1234, g_expected_title, g_expected_parent) == window); assert(g_base_calls == 1); assert(win16_read_u16(window) == 0x1234); assert_geometry(window, 192, 144, 640, 480); assert(win16_read_u32( win16_far_add_offset(window, WINDOW_ATTRIBUTES)) == 0x86ca0000u); assert(g_focus_calls == 0); reset_fixture(); window = object_at(0x100); g_screen_width = 801; g_screen_height = 601; (void)tdkpin_main_window_construct( window, 0, g_expected_title, g_expected_parent); assert_geometry(window, 80, 60, 640, 480); } static void test_centered_child_window(void) { reset_fixture(); Win16FarPtr window = object_at(0x200); g_base_style = 0x00010000u; assert(tdkpin_centered_child_window_construct( window, 0x2345, g_expected_title, g_expected_parent) == window); assert(g_base_calls == 1); assert(win16_read_far_pointer(window, WINDOW_OWNER) == g_expected_parent); assert_geometry(window, 140, 80, 360, 300); assert(win16_read_u32( win16_far_add_offset(window, WINDOW_ATTRIBUTES)) == 0x46810002u); assert(g_focus_calls == 1 && g_focused_window == 0x4444); } static void test_full_child_window(void) { reset_fixture(); Win16FarPtr window = object_at(0x300); g_base_style = 0xffffffffu; assert(tdkpin_full_child_window_construct( window, 0x3456, g_expected_title, g_expected_parent) == window); assert(g_base_calls == 1); assert(win16_read_far_pointer(window, WINDOW_OWNER) == g_expected_parent); assert_geometry(window, 0, 0, 640, 460); assert(win16_read_u32( win16_far_add_offset(window, WINDOW_ATTRIBUTES)) == 0x46000002u); assert(g_focus_calls == 1 && g_focused_window == 0x4444); } static void test_constructor_entry_failure(void) { reset_fixture(); Win16FarPtr window = object_at(0x400); win16_write_u32(window, WINDOW_ATTRIBUTES, 0x11223344u); g_enter = false; assert(tdkpin_centered_child_window_construct( window, 0x4567, g_expected_title, g_expected_parent) == window); assert(g_base_calls == 0 && g_focus_calls == 0); assert(win16_read_u32( win16_far_add_offset(window, WINDOW_ATTRIBUTES)) == 0x11223344u); } int main(void) { test_main_window(); test_centered_child_window(); test_full_child_window(); test_constructor_entry_failure(); return 0; }