## xsocket-unit-test-old.pkg
#
# NB: We must compile this locally via
# xclient-internals.sublib
# instead of globally via
#
src/lib/test/unit-tests.lib# like most unit tests, in order to have
# access to required library internals.
# Compiled by:
#
src/lib/x-kit/xclient/xclient.sublib# Run by:
#
src/lib/test/all-unit-tests.pkgstipulate
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg include package makelib::scripting_globals;
include package threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg #
package fil = file__premicrothread; # file__premicrothread is from
src/lib/std/src/posix/file--premicrothread.pkg package mps = microthread_preemptive_scheduler; # microthread_preemptive_scheduler is from
src/lib/src/lib/thread-kit/src/core-thread-kit/microthread-preemptive-scheduler.pkg# package tsc = thread_scheduler_control; # thread_scheduler_control is from
src/lib/src/lib/thread-kit/src/posix/thread-scheduler-control.pkg package tsr = thread_scheduler_is_running; # thread_scheduler_is_running is from
src/lib/src/lib/thread-kit/src/core-thread-kit/thread-scheduler-is-running.pkg package tr = logger; # logger is from
src/lib/src/lib/thread-kit/src/lib/logger.pkg package xtr = xlogger; # xlogger is from
src/lib/x-kit/xclient/src/stuff/xlogger.pkg# package xet = xevent_types; # xevent_types is from
src/lib/x-kit/xclient/src/wire/xevent-types.pkg package sox = socket_junk; # socket_junk is from
src/lib/internet/socket-junk.pkg package xok = xsocket_old; # xsocket_old is from
src/lib/x-kit/xclient/src/wire/xsocket-old.pkg package dy = display_old; # display_old is from
src/lib/x-kit/xclient/src/wire/display-old.pkg package xt = xtypes; # xtypes is from
src/lib/x-kit/xclient/src/wire/xtypes.pkg package au = authentication; # authentication is from
src/lib/x-kit/xclient/src/stuff/authentication.pkg package v2w = value_to_wire; # value_to_wire is from
src/lib/x-kit/xclient/src/wire/value-to-wire.pkg package wi = window_old; # window_old is from
src/lib/x-kit/xclient/src/window/window-old.pkg package g2d = geometry2d; # geometry2d is from
src/lib/std/2d/geometry2d.pkg package hsv = hue_saturation_value; # hue_saturation_value is from
src/lib/x-kit/xclient/src/color/hue-saturation-value.pkg package xx = xsocket_ximps; # xsocket_ximps is from
src/lib/x-kit/xclient/src/wire/xsocket-ximps.pkg #
tracefile = "xsocket-ximps-unit-test.trace.log";
herein
package xsocket_unit_test_old {
#
name = "src/lib/x-kit/xclient/src/stuff/xsocket-unit-test-old.pkg";
trace = xtr::log_if xtr::io_logging 0; # Conditionally write strings to tracing.log or whatever.
fun exercise_window_stuff (xdisplay: dy::Xdisplay)
=
{ xdisplay -> { default_screen, screens, next_xid, xsocket, ... };
screen = list::nth (screens, default_screen);
screen -> { root_window_id => parent_window_id, root_visual, black_rgb8, white_rgb8, ... }: dy::Xscreen;
green_pixel = rgb8::rgb8_green;
background_pixel = green_pixel;
border_pixel = black_rgb8;
window_id = next_xid ();
take_xevent' = xok::take_xevent' xsocket;
fun do_xevent (e: xevent_types::x::Event)
=
();
case root_visual
#
xt::VISUAL { visual_id, depth => 24, red_mask => 0uxFF0000, green_mask => 0ux00FF00, blue_mask => 0ux0000FF, ... }
=>
{ # Set up a null thread to read and discard
# incoming X events, since the xsocket logic
# will deadlock if we do not:
#
make_thread "Discard all X events" {.
#
for (;;) {
#
do_one_mailop [
#
take_xevent' ==> do_xevent
];
};
};
# Create a new X-window with the given xid
#
fun create_window (xsocket: xok::Xsocket)
{
window_id: xt::Window_Id,
parent_window_id: xt::Window_Id,
visual_id: xt::Visual_Id_Choice,
#
io_class: xt::Io_Class,
depth: Int,
site: g2d::Window_Site,
attributes: List( xt::a::Window_Attribute )
}
=
xok::send_xrequest xsocket msg
where
msg = v2w::encode_create_window
{
window_id,
parent_window_id,
visual_id,
io_class,
depth,
site,
attributes
};
end;
create_window xsocket
{
window_id,
parent_window_id,
visual_id => xt::SAME_VISUAL_AS_PARENT,
#
depth => 24,
io_class => xt::INPUT_OUTPUT,
#
site => { upperleft => { col=>100, row=>100 },
size => { wide=>400, high=>400 },
border_thickness => 1
}
: g2d::Window_Site,
attributes
=>
[ xt::a::BORDER_PIXEL border_pixel,
xt::a::BACKGROUND_PIXEL background_pixel,
xt::a::EVENT_MASK wi::standard_xevent_mask
]
};
xok::send_xrequest xsocket (v2w::encode_map_window { window_id });
xok::flush_xsocket xsocket;
sleep_for 0.1;
trace {. sprintf "xsocket_unit_test_old: Now writing create_window_request to socket."; };
# sox::send_vector (socket, create_window_request);
trace {. sprintf "xsocket_unit_test_old: Done writing create_window_request to socket."; };
trace {. sprintf "xsocket_unit_test_old: Now reading back header of reply for create_window request."; };
# header = sox::receive_vector (socket, 8);
trace {. sprintf "xsocket_unit_test_old: Done reading back header of reply for create_window request."; };
};
xt::VISUAL { visual_id, depth, red_mask, green_mask, blue_mask, ... }
=>
{ printf "\nxsocket-unit-test-old.pkg: exercise_window_stuff:\n";
printf "This code assumes root visual has depth=24 red_mask=0xff0000 green_mask=0x00ff00 blue_mask=0x0000ff\n";
printf "but actually the root visual has depth=%d red_mask=0x%06x green_mask=0x%06x blue_mask=0x%06x\n" depth (unt::to_int red_mask) (unt::to_int green_mask) (unt::to_int blue_mask);
printf "Skipping these unit tests.\n";
assert FALSE;
};
xt::NO_VISUAL_FOR_THIS_DEPTH int
=>
{ # This case should never happen.
assert FALSE;
print "root_visual is NO_VISUAL_FOR_THIS_DEPTH?!\n";
};
esac;
# window
# =
# create_window
# :
# xok::Xsocket
# ->
# { id: xt::Window_Id,
# parent: xt::Window_Id,
# #
# in_only: Null_Or( Bool ),
# depth: Int,
# visual: Null_Or( xt::Visual_Id ),
# #
# geometry: g2d::Window_Site,
# attributes: List( Xwin_Val )
# }
# ->
# Void;
();
}; # fun exercise_window_stuff
fun run ()
=
{ # Remove any old version of the tracefile:
#
if (isfile tracefile)
unlink tracefile;
fi;
printf "\nDoing %s:\n" name;
# Open tracelog file and
# select tracing level:
#
{ include package logger; # logger is from
src/lib/src/lib/thread-kit/src/lib/logger.pkg #
set_logger_to (fil::LOG_TO_FILE tracefile);
#
# enable fil::all_logging; # Gross overkill.
# enable xtr::xkit_logging; # Lesser overkill.
# enable xtr::io_logging; # Saner yet.
};
assert (tsr::thread_scheduler_is_running ());
(au::get_xdisplay_string_and_xauthentication NULL)
->
( display_name: String, # Typically from $DISPLAY environment variable.
xauthentication: Null_Or(xt::Xauthentication) # Typically from ~/.Xauthority
);
trace {. sprintf "xsocket_unit_test_old: DISPLAY variable is set to '%s'" display_name; };
trace {. sprintf "xsocket_unit_test_old: Now calling dy::open_xdisplay"; };
{ xdisplay = dy::open_xdisplay { display_name, xauthentication }; # Raises dy::XSERVER_CONNECT_ERROR on failure.
# Apparently dy:: is hardwired to use xsession-old.pkg
# so the above likely needs to be cloned.
xdisplay -> { xsocket, ... };
# xsocket -> xok::
# Need to extract 'socket' from xdisplay here
# But apparently there is no way to do so...
(make_run_gun ()) -> { run_gun', fire_run_gun };
(make_end_gun ()) -> { end_gun', fire_end_gun };
# (xx::make_xsocket_ximps_state ()) -> xsocket_ximps_state;
# (xx::make_xsocket_ximps ("xsocket_ximpl", xsocket_ximps_state)) -> (xsocket_ximps_configstate, xsocket_ximps_exports);
#
# xsocket_ximps_imports = { xevent_sink }
# where
# xevent_sink = { put_value }
# where
# fun put_value (event: xet::x::Event) = (); # Dummy.
# end;
# end;
# SOON!
# configure_xsocket_ximps (xsocket_ximps_configstate, xsocket_ximps_state, xsocket_ximps_imports, run_gun', end_gun', socket);
# fire_run_gun ();
# fire_end_gun ();
# trace {. sprintf "xsocket_unit_test_old: Done calling dy::open_xdisplay"; };
#
# exercise_window_stuff xdisplay;
#
# # do_it (make_root_window NULL);
#
dy::close_xdisplay xdisplay;
} except
dy::XSERVER_CONNECT_ERROR string
=
{ fprintf fil::stderr "xsocket_unit_test_old: Could not connect to X server: %s\n" string;
fprintf fil::stderr "xsocket_unit_test_old: *** OMITTING XSOCKET_XIMP UNIT TESTS. ***\n";
# trace {. sprintf "xsocket_unit_test_old: Could not connect to X server: %s" string; };
# trace {. "xsocket_unit_test_old: *** OMITTING XSOCKET_XIMP UNIT TESTS. ***"; };
#
assert FALSE;
};
assert TRUE;
summarize_unit_tests name;
};
};
end;