Files
tdkpin/original/reconstructed/tests/test_object_windows_handlers.c
ddidderr 8b99e9607c feat(reconstruction): complete binary-backed C recovery
Replace the partial mechanics transcriptions with a separate, readable C11
reconstruction of the complete Win16 image while preserving the original raw
Ghidra export as immutable evidence. Cover all ordinary and overlapping entry
points, Borland runtime behavior, Win16 imports, segmented data, callbacks,
resources, indirect control flow, physics, rendering, persistence, and
startup/shutdown lifecycles.

Add deterministic extraction and audit tooling plus address-linked ledgers for
functions, imports, DGROUP ranges and objects, relocations, resources, and
callbacks. The final gate records zero raw, partial, restored, unknown,
blocked, or unclassified required units. Keep the semantic-fidelity boundary
explicit: the portable C is not claimed to reproduce a byte-identical Borland
NE build.

Add strict focused harnesses for every reconstructed C unit, exact resource
round-trip checks, and a 16-bit Borland Real48 reference probe. No Rust source
or Cargo metadata is changed in this phase.

Test Plan:
- `bash original/tools/test_reconstructed_c.sh` -- passed
- `bash original/tools/probe_real48_reference.sh` -- passed bit-for-bit
- `python3 original/tools/audit_reconstruction.py --require-complete` -- passed
- `git diff --cached --check` -- passed
- `git diff HEAD -- '*.rs' Cargo.toml Cargo.lock` -- empty
2026-08-23 16:41:17 +02:00

170 lines
5.6 KiB
C

#include "../tdkpin_dialog.h"
#include <assert.h>
Win16FarPtr g_object_windows_application;
uint8_t g_object_windows_focus_event_marker;
static bool g_bool_result;
static Win16FarPtr g_expected_bool_procedure;
static Win16FarPtr g_expected_bool_receiver;
static unsigned g_bool_calls;
static HWND16 g_set_focus_window;
static Win16FarPtr g_window_from_handle;
static Win16FarPtr g_called_method;
static Win16FarPtr g_called_receiver;
static unsigned g_method_calls;
static unsigned g_dispose_calls;
static Win16FarPtr g_u16_procedures[2];
static uint16_t g_u16_arguments[2];
static unsigned g_u16_calls;
bool win16_call_object_bool_method(
Win16FarPtr procedure, Win16FarPtr object)
{
assert(procedure == g_expected_bool_procedure);
assert(object == g_expected_bool_receiver);
g_bool_calls++;
return g_bool_result;
}
HWND16 SetFocus16(HWND16 window)
{
g_set_focus_window = window;
return 0x9999;
}
Win16FarPtr object_windows_object_from_window(HWND16 window)
{
assert(window == g_set_focus_window);
return g_window_from_handle;
}
void win16_call_object_method(
Win16FarPtr procedure, Win16FarPtr object)
{
g_called_method = procedure;
g_called_receiver = object;
g_method_calls++;
}
void borland_dispose_object(Win16FarPtr object)
{
g_called_receiver = object;
g_dispose_calls++;
}
void win16_call_object_u16_method(
Win16FarPtr procedure, Win16FarPtr object, uint16_t argument)
{
assert(g_u16_calls < 2);
g_u16_procedures[g_u16_calls] = procedure;
g_u16_arguments[g_u16_calls] = argument;
g_called_receiver = object;
g_u16_calls++;
}
static void write_far(
Win16FarPtr base, uint16_t offset, Win16FarPtr value)
{
win16_write_u16(base, offset, win16_far_offset(value));
win16_write_u16(
base, (uint16_t)(offset + 2), win16_far_selector(value));
}
int main(void)
{
static uint8_t dgroup[0x1000];
win16_reset_segment_bindings();
win16_bind_segment(0x5000, dgroup, sizeof(dgroup), true);
win16_set_dgroup_selector(0x5000);
Win16FarPtr application = win16_make_far_pointer(0x5000, 0x0200);
Win16FarPtr main_window = win16_make_far_pointer(0x5000, 0x0300);
Win16FarPtr other_window = win16_make_far_pointer(0x5000, 0x0400);
Win16FarPtr attached = win16_make_far_pointer(0x5000, 0x0600);
g_object_windows_application = application;
win16_write_u16(application, 0, 0x0700);
write_far(application, 8, main_window);
win16_write_u16(main_window, 0, 0x0780);
win16_write_u16(other_window, 0, 0x0800);
win16_write_u16(attached, 0, 0x0880);
Win16FarPtr app_can_close =
win16_make_far_pointer(0x6000, 0x1111);
Win16FarPtr window_can_close =
win16_make_far_pointer(0x6000, 0x2222);
write_far(win16_dgroup_pointer(0x0700), 0x44, app_can_close);
write_far(win16_dgroup_pointer(0x0800), 0x3c, window_can_close);
ObjectWindowsMessage message = {0};
g_expected_bool_procedure = app_can_close;
g_expected_bool_receiver = application;
g_bool_result = true;
g_bool_calls = 0;
object_windows_query_end_session_result(main_window, &message);
assert(g_bool_calls == 1 && message.result == 0);
g_expected_bool_procedure = window_can_close;
g_expected_bool_receiver = other_window;
g_bool_result = false;
object_windows_query_end_session_result(other_window, &message);
assert(message.result == 1);
message.wparam = 0x1234;
g_window_from_handle = other_window;
write_far(other_window, 0x43, attached);
Win16FarPtr attached_method =
win16_make_far_pointer(0x6000, 0x3333);
write_far(win16_dgroup_pointer(0x0880), 0x0c, attached_method);
g_method_calls = 0;
g_object_windows_focus_event_marker = 0;
object_windows_focus_message(main_window, &message);
assert(g_set_focus_window == 0x1234);
assert(g_method_calls == 1 && g_called_method == attached_method &&
g_called_receiver == attached);
assert(g_object_windows_focus_event_marker == 1);
g_window_from_handle = 0;
g_method_calls = 0;
g_object_windows_focus_event_marker = 0;
object_windows_focus_message(0, &message);
assert(g_method_calls == 0 && g_object_windows_focus_event_marker == 1);
Win16FarPtr dialog = win16_make_far_pointer(0x5000, 0x0500);
win16_write_u16(dialog, 0, 0x0900);
Win16FarPtr dialog_can_close =
win16_make_far_pointer(0x6000, 0x4444);
Win16FarPtr dialog_transfer =
win16_make_far_pointer(0x6000, 0x5555);
Win16FarPtr dialog_close =
win16_make_far_pointer(0x6000, 0x6666);
write_far(win16_dgroup_pointer(0x0900), 0x3c, dialog_can_close);
write_far(win16_dgroup_pointer(0x0900), 0x44, dialog_transfer);
write_far(win16_dgroup_pointer(0x0900), 0x50, dialog_close);
win16_write_u8(win16_far_add_offset(dialog, 0x25), 0);
g_expected_bool_procedure = dialog_can_close;
g_expected_bool_receiver = dialog;
g_bool_result = true;
g_dispose_calls = 0;
object_windows_dialog_validate_and_close(dialog, &message);
assert(g_dispose_calls == 1 && g_called_receiver == dialog);
win16_write_u8(win16_far_add_offset(dialog, 0x25), 1);
g_expected_bool_procedure = dialog_can_close;
g_expected_bool_receiver = dialog;
g_bool_result = false;
g_u16_calls = 0;
object_windows_dialog_validate_and_close(dialog, &message);
assert(g_u16_calls == 0);
g_bool_result = true;
object_windows_dialog_validate_and_close(dialog, &message);
assert(g_u16_calls == 2 && g_called_receiver == dialog);
assert(g_u16_procedures[0] == dialog_transfer &&
g_u16_arguments[0] == 1);
assert(g_u16_procedures[1] == dialog_close &&
g_u16_arguments[1] == 1);
return 0;
}