Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses Rototill to add complex character support:



details:   https://anonhg.NetBSD.org/src/rev/dfa704205194
branches:  trunk
changeset: 454506:dfa704205194
user:      blymn <blymn%NetBSD.org@localhost>
date:      Thu Sep 19 11:31:57 2019 +0000

description:
Rototill to add complex character support:

- Add cchar command to director test language to allow a complex character
  to be defined and passed to the slave.
- Removed the distinction between args and returns internally to prevent
  confusing the two which leads to errors and/or crashes.
- Converted mutt_test to use the new cchar definition and fixed the
  check files for the test.

diffstat:

 tests/lib/libcurses/check_files/mutt_test5.chk |    4 +-
 tests/lib/libcurses/check_files/mutt_test6.chk |    2 +-
 tests/lib/libcurses/director/returns.h         |   44 +-
 tests/lib/libcurses/director/testlang_conf.l   |   40 +-
 tests/lib/libcurses/director/testlang_parse.y  |  680 ++++++++++++++++--------
 tests/lib/libcurses/slave/commands.c           |   18 +-
 tests/lib/libcurses/slave/slave.c              |   10 +-
 tests/lib/libcurses/testframe.txt              |   21 +
 tests/lib/libcurses/tests/mutt_test            |   13 +-
 9 files changed, 534 insertions(+), 298 deletions(-)

diffs (truncated from 1567 to 300 lines):

diff -r e58755df0724 -r dfa704205194 tests/lib/libcurses/check_files/mutt_test5.chk
--- a/tests/lib/libcurses/check_files/mutt_test5.chk    Thu Sep 19 06:09:52 2019 +0000
+++ b/tests/lib/libcurses/check_files/mutt_test5.chk    Thu Sep 19 11:31:57 2019 +0000
@@ -1,4 +1,4 @@
-cup13;1Xjsetaf7Xsetab0XEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
-boldEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEsgr0opj
setaf7Xsetab0XEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEj
+cup13;1Xsetaf7Xsetab0XEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
+boldEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEsgr0op
setaf7Xsetab0XEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEj
 boldEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEsgr0op
setaf7Xsetab0XEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEj
 boldEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEsgr0op
\ No newline at end of file
diff -r e58755df0724 -r dfa704205194 tests/lib/libcurses/check_files/mutt_test6.chk
--- a/tests/lib/libcurses/check_files/mutt_test6.chk    Thu Sep 19 06:09:52 2019 +0000
+++ b/tests/lib/libcurses/check_files/mutt_test6.chk    Thu Sep 19 11:31:57 2019 +0000
@@ -1,1 +1,1 @@
-jcup15;11Xsetaf7Xsetab0XsmsoRRRRRRRRRRRcup24;1Xrmsoopsetaf7Xsetab0Xjopjcup15;15Xsetaf7Xsetab0XHHHopsetaf7Xsetab0Xjop
\ No newline at end of file
+cup15;11Xsetaf7Xsetab0XsmsoRRRRRRRRRRRcup24;1Xrmsoopsetaf7Xsetab0Xjopcup15;15Xsetaf7Xsetab0XHHHopsetaf7Xsetab0Xjop
\ No newline at end of file
diff -r e58755df0724 -r dfa704205194 tests/lib/libcurses/director/returns.h
--- a/tests/lib/libcurses/director/returns.h    Thu Sep 19 06:09:52 2019 +0000
+++ b/tests/lib/libcurses/director/returns.h    Thu Sep 19 11:31:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: returns.h,v 1.1 2011/04/10 09:55:09 blymn Exp $        */
+/*     $NetBSD: returns.h,v 1.2 2019/09/19 11:31:57 blymn Exp $        */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -33,28 +33,30 @@
 
 
 typedef enum {
-       ret_number = 1,
-       ret_string,
-       ret_byte,
-       ret_err,
-       ret_ok,
-       ret_null,
-       ret_nonnull,
-       ret_var,
-       ret_ref,
-       ret_count,
-       ret_slave_error
-} returns_enum_t;
+       data_number = 1,
+       data_static,
+       data_string,
+       data_byte,
+       data_cchar,
+       data_err,
+       data_ok,
+       data_null,
+       data_nonnull,
+       data_var,
+       data_ref,
+       data_count,
+       data_slave_error
+} data_enum_t;
 
 typedef struct {
-       returns_enum_t  return_type;
-       void            *return_value;  /* used if return_type is ret_num or
-                                          or ret_byte or ret_string */
-       size_t          return_len;     /* number of bytes in return_value iff
-                                          return_type is ret_byte */
-       int             return_index;   /* index into var array for return
-                                          if return_type is ret_var */
-} returns_t;
+       data_enum_t     data_type;
+       void            *data_value;    /* used if data_type is data_num or
+                                          or data_byte or data_string */
+       size_t          data_len;       /* number of bytes in return_value iff
+                                          return_type is data_byte */
+       int             data_index;     /* index into var array for return
+                                          if data_type is data_var */
+} ct_data_t;
 
 typedef struct {
        size_t  count;
diff -r e58755df0724 -r dfa704205194 tests/lib/libcurses/director/testlang_conf.l
--- a/tests/lib/libcurses/director/testlang_conf.l      Thu Sep 19 06:09:52 2019 +0000
+++ b/tests/lib/libcurses/director/testlang_conf.l      Thu Sep 19 11:31:57 2019 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_conf.l,v 1.7 2013/11/21 11:06:04 blymn Exp $  */
+/*     $NetBSD: testlang_conf.l,v 1.8 2019/09/19 11:31:57 blymn Exp $  */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -155,10 +155,14 @@
 VARNAME                [A-Za-z][A-Za-z0-9_-]+
 NULL_RET       NULL
 NON_NULL       NON_NULL
+CCHAR          [cC][cC][hH][aA][rR]
 BYTE           BYTE
 OR             \|
 LHB            \(
 RHB            \)
+LHSB           \[
+RHSB           \]
+MULTIPLIER     \*
 
 %x incl
 %option noinput nounput
@@ -286,6 +290,14 @@
                        return ERR_RET;
                }
 
+{MULTIPLIER}   {
+                       return MULTIPLIER;
+               }
+
+{CCHAR}        {
+                       return CCHAR;
+               }
+
 {OR}           {
                        return OR;
                }
@@ -298,6 +310,14 @@
                        return RHB;
                }
 
+{LHSB}         {
+                       return LHSB;
+               }
+
+{RHSB}         {
+                       return RHSB;
+               }
+
 {HEX}          {
                        /* Hex value, convert to decimal and return numeric */
                        unsigned long val;
@@ -342,17 +362,17 @@
                        char *p;
                        size_t len;
 
-                       if ((yylval.retval = malloc(sizeof(returns_t))) == NULL)
+                       if ((yylval.retval = malloc(sizeof(ct_data_t))) == NULL)
                                err(1, "Cannot allocate return struct");
                        p = yytext;
                        p++; /* skip the leading ' */
-                       if ((yylval.retval->return_value = dequote(p, &len))
+                       if ((yylval.retval->data_value = dequote(p, &len))
                             == NULL)
                                err(1, "Cannot allocate string");
 
-                       yylval.retval->return_type = ret_byte;
+                       yylval.retval->data_type = data_byte;
                        /* trim trailing ' */
-                       yylval.retval->return_len = len - 1;
+                       yylval.retval->data_len = len - 1;
                        return BYTE;
                }
 
@@ -362,7 +382,7 @@
                        size_t i;
                        chtype *rv;
 
-                       if ((yylval.retval = malloc(sizeof(returns_t))) == NULL)
+                       if ((yylval.retval = malloc(sizeof(ct_data_t))) == NULL)
                                err(1, "Cannot allocate return struct");
                        p = yytext;
                        p++; /* skip the leading ' */
@@ -373,16 +393,16 @@
                                len--;
 
                        chlen = ((len / 2) + 1) * sizeof(chtype);
-                       if ((yylval.retval->return_value = malloc(chlen))
+                       if ((yylval.retval->data_value = malloc(chlen))
                            == NULL)
                                err(1, "Cannot allocate chtype array");
 
-                       rv = yylval.retval->return_value;
+                       rv = yylval.retval->data_value;
                        for (i = 0; i < len; i += 2)
                                *rv++ = (str[i] << 8) | str[i+1];
                        *rv = __NORMAL | '\0'; /* terminates chtype array */    
-                       yylval.retval->return_type = ret_byte;
-                       yylval.retval->return_len = chlen;
+                       yylval.retval->data_type = data_byte;
+                       yylval.retval->data_len = chlen;
                        return BYTE;
                }
 
diff -r e58755df0724 -r dfa704205194 tests/lib/libcurses/director/testlang_parse.y
--- a/tests/lib/libcurses/director/testlang_parse.y     Thu Sep 19 06:09:52 2019 +0000
+++ b/tests/lib/libcurses/director/testlang_parse.y     Thu Sep 19 11:31:57 2019 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_parse.y,v 1.15 2019/06/11 10:22:35 blymn Exp $        */
+/*     $NetBSD: testlang_parse.y,v 1.16 2019/09/19 11:31:57 blymn Exp $        */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -79,27 +79,19 @@
 static char *input_str;        /* string to feed in as input */
 static bool no_input;  /* don't need more input */
 
+static wchar_t *vals = NULL;   /* wchars to attach to a cchar type */
+static unsigned nvals;         /* number of wchars */
+
 #define READ_PIPE  0
 #define WRITE_PIPE 1
 
-const char *returns_enum_names[] = {
-       "unused", "numeric", "string", "byte", "ERR", "OK", "NULL", "not NULL",
-       "variable", "reference", "returns count", "slave error"
-};
-
-typedef enum {
-       arg_static,
-       arg_byte,
-       arg_var,
-       arg_null
-} args_state_t;
-
-static const char *args_enum_names[] = {
-       "static", "byte", "var", "NULL"
+const char *enum_names[] = {
+       "unused", "static", "numeric", "string", "byte", "cchar", "ERR", "OK", "NULL",
+       "not NULL", "variable", "reference", "returns count", "slave error"
 };
 
 typedef struct {
-       args_state_t    arg_type;
+       data_enum_t     arg_type;
        size_t          arg_len;
        char            *arg_string;
        int             var_index;
@@ -108,7 +100,7 @@
 typedef struct {
        char            *function;
        int             nrets;          /* number of returns */
-       returns_t       *returns;       /* array of expected returns */
+       ct_data_t       *returns;       /* array of expected returns */
        int             nargs;          /* number of arguments */
        args_t          *args;          /* arguments for the call */
 } cmd_line_t;
@@ -118,8 +110,9 @@
 typedef struct {
        char *name;
        size_t len;
-       returns_enum_t type;
+       data_enum_t type;
        void *value;
+       cchar_t cchar;
 } var_t;
 
 static size_t nvars;           /* Number of declared variables */
@@ -127,26 +120,28 @@
 
 static int     check_function_table(char *, const char *[], int);
 static int     find_var_index(const char *);
-static void    assign_arg(args_state_t, void *);
+static void    assign_arg(data_enum_t, void *);
 static int     assign_var(char *);
 void           init_parse_variables(int);
 static void    validate(int, void *);
 static void    validate_return(const char *, const char *, int);
-static void    validate_variable(int, returns_enum_t, const void *, int, int);
-static void    validate_byte(returns_t *, returns_t *, int);
+static void    validate_variable(int, data_enum_t, const void *, int, int);
+static void    validate_byte(ct_data_t *, ct_data_t *, int);
 static void    write_cmd_pipe(char *);
-static void    write_cmd_pipe_args(args_state_t, void *);
-static void    read_cmd_pipe(returns_t *);
+static void    write_cmd_pipe_args(data_enum_t, void *);
+static void    read_cmd_pipe(ct_data_t *);
 static void    write_func_and_args(void);
 static void    compare_streams(char *, bool);
 static void    do_function_call(size_t);
 static void    save_slave_output(bool);
-static void    validate_type(returns_enum_t, returns_t *, int);
-static void    set_var(returns_enum_t, char *, void *);
+static void    validate_type(data_enum_t, ct_data_t *, int);
+static void    set_var(data_enum_t, char *, void *);
 static void    validate_reference(int, void *);
 static char    *numeric_or(char *, char *);
 static char    *get_numeric_var(const char *);
 static void    perform_delay(struct timespec *);
+static void    set_cchar(char *, void *);
+static wchar_t *add_to_vals(data_enum_t, void *);
 
 static const char *input_functions[] = {
        "getch", "getnstr", "getstr", "mvgetnstr", "mvgetstr", "mvgetnstr",
@@ -163,7 +158,8 @@
 
 %union {
        char *string;
-       returns_t *retval;
+       ct_data_t *retval;
+       wchar_t *vals;
 }
 
 %token <string> PATH



Home | Main Index | Thread Index | Old Index