PreviousUpNext

15.4.1422  src/lib/x-kit/widget/lib/widget-unit-test.pkg

## widget-unit-test.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/widget/xkit-widget.sublib


# Run by:
#     src/lib/test/all-unit-tests.pkg

stipulate
    include unit_test;                                          # unit_test                     is from   src/lib/src/unit-test.pkg
    include makelib::scripting_globals;
    include 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 tsr =  thread_scheduler_is_running;                 # thread_scheduler_is_running   is form   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 sox =  socket_junk;                                 # socket_junk                   is from   src/lib/internet/socket-junk.pkg
    package wg  =  widget;                                      # widget                        is from   src/lib/x-kit/widget/basic/widget.pkg
    package xc  =  xclient;                                     # xclient                       is from   src/lib/x-kit/xclient/xclient.pkg
    #
    tracefile   =  "widget-unit-test.trace.log";
herein

    package widget_unit_test {

        name = "src/lib/x-kit/widget/lib/widget-unit-test.pkg";

        trace =  xtr::log_if  xtr::io_logging 0;                # Conditionally write strings to tracing.log or whatever.

        default_time_quantum                                    # Copied from src/lib/x-kit/widget/lib/run-in-x-window.pkg
            =
            time::from_milliseconds 20;


        fun make_root_window
                display_or_null                                                         # Allow overriding of the DISPLAY environment variable setting.
            =
            {   my  ( xdisplay,                                                         # Typically from $DISPLAY environment variable.
                      xauthentication:  Null_Or(xc::Xauthentication)                    # Typically from ~/.Xauthority
                    )
                    =
                    xc::get_xdisplay_string_and_xauthentication  display_or_null;

                trace .{ sprintf "widget_unit_test: DISPLAY variable is set to '%s'" xdisplay; };

                trace .{ sprintf "widget_unit_test: Now  calling wg::make_root_window"; };

                THE (wg::make_root_window (xdisplay, xauthentication))
                except
                    xc::XSERVER_CONNECT_ERROR s
                        =
                        {   fil::write
                                ( fil::stderr,
                                  string::cat
                                    [ "run_in_x_window: unable to open display \"",   xdisplay,   "\"\n",
                                      "  ",   s,   "\n"
                                    ]
                                );

                            trace .{ sprintf "widget_unit_test: make_root_window: Unable to open display %s: %s" xdisplay s; };

                            NULL;
                        };
              };

        fun run ()
            =
            {   printf "\nDoing %s:\n" name;   

                # Remove any old version of the tracefile:
                #
                if (isfile tracefile)
                    #
                    unlink tracefile;
                fi;

                # Open tracelog file and
                # select tracing level:
                #
                {   include 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.    
                };

                start_up_thread_scheduler'
                    default_time_quantum
                   .{
                        assert  (tsr::thread_scheduler_is_running ());

                        case (make_root_window NULL)
                            #
                            THE root_window
                                =>
                                {   trace .{ sprintf "widget_unit_test: run: Successfully constructed root window"; };

                                    xsession = wg::xsession_of root_window;
                                    screen   = wg::screen_of   root_window;

                                    assert TRUE;
                                };
                            NULL =>
                                {   trace .{ sprintf "widget_unit_test: run: Failed to construct root window, skipping remaining tests"; };
                                    assert FALSE;
                                };
                        esac;   

#                       my  ( display_name:     String,                                         # Typically from $DISPLAY environment variable.
#                             xauthentication:  Null_Or(xclient::Xauthentication)                       # Typically from ~/.Xauthority
#                           )
#                           =
#                           xc::get_xdisplay_string_and_xauthentication  NULL;

#                       trace .{ sprintf "widget_unit_test: DISPLAY variable is set to '%s'" display_name; };

#                       trace .{ sprintf "widget_unit_test: Now  calling dy::open_xdisplay"; };

#                       {   xdisplay =  dy::open_xdisplay { display_name, xauthentication };    # Raises dy::XSERVER_CONNECT_ERROR on failure.
#                               
#   
#                           trace .{ sprintf "widget_unit_test: Done calling dy::open_xdisplay"; };
#   
#                           exercise_window_stuff  xdisplay;
#   
#   #                           do_it (make_root_window NULL);
#   
#                       } except
#                           dy::XSERVER_CONNECT_ERROR string
#                               =
#                               {   fprintf fil::stderr "widget_unit_test: Could not connect to X server: %s\n" string;
#                                   fprintf fil::stderr "widget_unit_test: *** OMITTING XCLIENT UNIT TESTS. ***\n";
#   
#                                   trace .{ sprintf "widget_unit_test: Could not connect to X server: %s" string; };
#                                   trace .{         "widget_unit_test: *** OMITTING XCLIENT UNIT TESTS. ***";     };
#   
#                                   assert FALSE;
#                               };
#   
                        trace .{ sprintf "xclient-unit-test.pkg: Now  calling shut_down_thread_scheduler"; };

#                       shut_down_thread_scheduler  winix__premicrothread::process::success;
                    };

# Commented out for always-on multithreading:
                # Close tracelog file:
                #
#               {   include logger;                             # logger                        is from   src/lib/src/lib/thread-kit/src/lib/logger.pkg
#
#                   tracing_to =  fil::logger_is_set_to ();
#
#                   set_logger_to  fil::LOG_TO_STDERR;
#
#                   case tracing_to
#                       #
#                       fil::LOG_TO_STREAM stream =>  fil::close_output stream;
#                       #
#                       _                          =>  ();
#                    esac;
#               };

                assert TRUE;

                summarize_unit_tests  name;
            };
    };

end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext