From 009593c7c6463ec3d4873231da5231fa16d424e2 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 22 Jan 2015 18:01:45 -0800 Subject: 600 - fake keyboard Use asynchronous channels like 'stdin' for most tests. Use the synchronous fakes for testing low-level stdin helpers. --- mu.arc | 36 ++++++++++++++++++++++++++++++------ mu.arc.t | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/mu.arc b/mu.arc index 14ed973d..21c4fb53 100644 --- a/mu.arc +++ b/mu.arc @@ -199,8 +199,12 @@ line-address-address (obj size 1 address t elem '(line-address)) screen (obj array t elem '(line-address)) screen-address (obj size 1 address t elem '(screen)) + ; fake screen terminal (obj size 5 and-record t elems '((integer) (integer) (integer) (integer) (string-address)) fields '(num-rows num-cols cursor-row cursor-col data)) terminal-address (obj size 1 address t elem '(terminal)) + ; fake keyboard + keyboard (obj size 2 and-record t elems '((integer) (string-address)) fields '(index data)) + keyboard-address (obj size 1 address t elem '(keyboard)) ))) ;; managing concurrent routines @@ -662,16 +666,11 @@ ;? (write (m arg.0)) (pr " => ") (prn (type (m arg.0))) ((if ($.current-charterm) $.charterm-display pr) (m arg.0)) ) - read-key + read-key-from-host (if ($.current-charterm) (and ($.charterm-byte-ready?) ($.charterm-read-key)) ($.graphics-open?) ($.ready-key-press Viewport)) - wait-for-key - (if ($.current-charterm) - ($.charterm-read-key) - ($.graphics-open?) - ($.get-key-press Viewport)) ; graphics window-on @@ -1932,6 +1931,31 @@ (reply result:string-address-array-address) ) +(init-fn init-keyboard + (default-space:space-address <- new space:literal 30:literal) + (result:keyboard-address <- new keyboard:literal) + (buf:string-address-address <- get-address result:keyboard-address/deref data:offset) + (buf:string-address-address/deref <- next-input) + (idx:integer-address <- get-address result:keyboard-address/deref index:offset) + (idx:integer-address/deref <- copy 0:literal) + (reply result:keyboard-address) +) + +(init-fn read-key + (default-space:space-address <- new space:literal 30:literal) + (x:keyboard-address <- next-input) + { begin + (break-unless x:keyboard-address) + (idx:integer-address <- get-address x:keyboard-address/deref index:offset) + (buf:string-address <- get x:keyboard-address/deref data:offset) + (c:character <- index buf:string-address/deref idx:integer-address/deref) + (idx:integer-address/deref <- add idx:integer-address/deref 1:literal) + (reply c:character) + } + (c:character <- read-key-from-host) + (reply c:character) +) + (init-fn send-keys-to-stdin (default-space:space-address <- new space:literal 30:literal) (stdin:channel-address <- next-input) diff --git a/mu.arc.t b/mu.arc.t index a617ec3a..0e8d31a8 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -4087,10 +4087,9 @@ ; fake screen for tests; prints go to a string (reset) -(new-trace "fake-screen-initial") -(add-code:readfile "chessboard-cursor.mu") +(new-trace "fake-screen-empty") (add-code - '((function! main [ + '((function main [ (default-space:space-address <- new space:literal 30:literal/capacity) (screen:terminal-address <- init-fake-terminal 20:literal 10:literal) (5:string-address/raw <- get screen:terminal-address/deref data:offset) @@ -4112,6 +4111,35 @@ " ")) (prn "F - fake screen starts out with all spaces")) +; fake keyboard for tests; must initialize keys in advance +(reset) +(new-trace "fake-keyboard") +(add-code + '((function main [ + (default-space:space-address <- new space:literal 30:literal) + (s:string-address <- new "foo") + (x:keyboard-address <- init-keyboard s:string-address) + (1:character-address/raw <- read-key x:keyboard-address) + ]))) +(run 'main) +(when (~is memory*.1 #\f) + (prn "F - 'read-key' reads character from provided 'fake keyboard' string")) + +; fake keyboard for tests; must initialize keys in advance +(reset) +(new-trace "fake-keyboard2") +(add-code + '((function main [ + (default-space:space-address <- new space:literal 30:literal) + (s:string-address <- new "foo") + (x:keyboard-address <- init-keyboard s:string-address) + (1:character-address/raw <- read-key x:keyboard-address) + (1:character-address/raw <- read-key x:keyboard-address) + ]))) +(run 'main) +(when (~is memory*.1 #\o) + (prn "F - 'read-key' advances cursor in provided string")) + ) ; section 100 (reset) -- cgit 1.4.1-2-gfad0 .EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
void cmd_presence_shows_usage_when_bad_subcmd(void** state);
void cmd_presence_shows_usage_when_bad_console_setting(void** state);
void cmd_presence_shows_usage_when_bad_chat_setting(void** state);
void cmd_presence_shows_usage_when_bad_muc_setting(void** state);
void cmd_presence_console_sets_all(void** state);
void cmd_presence_console_sets_online(void** state);
void cmd_presence_console_sets_none(void** state);
void cmd_presence_chat_sets_all(void** state);
void cmd_presence_chat_sets_online(void** state);
void cmd_presence_chat_sets_none(void** state);
void cmd_presence_room_sets_all(void** state);
void cmd_presence_room_sets_online(void** state);
void cmd_presence_room_sets_none(void** state);