File: keyboard.sh

package info (click to toggle)
xnee 3.06-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,324 kB
  • ctags: 2,429
  • sloc: ansic: 21,992; sh: 12,427; makefile: 563
file content (134 lines) | stat: -rwxr-xr-x 2,121 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#/bin/sh
#
#
# Filename:   record/keyboard.sh
# Generated:  Sun Mar 16 21:57:36 CET 2003
# 
# Description:
#
#  Test the Xnee functionality
#       record keyboard 
#
#
 
 
 
 
 
# name of myself
MYNAME=record/keyboard.sh
 
 
# source useful funs
if [ ! -f etc/base_funs ]; 
then 
    echo "Can't find the file: base_funs"  
    echo "Start me up in the xnee test dir "
    exit
else 
    . etc/base_funs
fi 
 
init_test $MYNAME

parse_me "$*"


#######################################################################

KEYBOARD_DEVICE=/dev/swkeybd



function check_nr_of_loops()
{
    PRESS_EXPECTED=$1
    RELEASE_EXPECTED=$2
    LOGFILE=$3
    
    PRESS_NR=`grep -e '^0,2' $LOGFILE | wc -l | sed 's,[ \t]*,,g'`
    RELEASE_NR=`grep -e '^0,2' $LOGFILE | wc -l | sed 's,[ \t]*,,g'`

    verify_same $PRESS_EXPECTED   $PRESS_NR   $LOGFILE 
    verify_same $RELEASE_EXPECTED $RELEASE_NR $LOGFILE 
}



function press_key()
{
    KEY=$1
    verbose "faking key $KEY"
    echo "$KEY" > $KEYBOARD_DEVICE
    sleep 0
}



function test_keyboard()
{
    STR=$1
    FILE=$2

    
    LEN=${#STR}
	
	
	
    CAPS=0
    TMP=0
    while [ "$TMP" != "$LEN" ];
    do
      CAPS_ADD=$(echo ${STR:$TMP:1} | sed 's,[a-z],,g' | grep -c -e "[A-Z]")
      CAPS=$(( $CAPS + $CAPS_ADD ))
      TMP=$(( $TMP + 1 ))
    done

    verbose "CAPS=$CAPS"
    verbose "LEN=$LEN"

    LEN=$(( $LEN + $CAPS)) 
    TLEN=$(( $LEN * 2 ))
    verbose "TLEN=$TLEN"
    

    verbose "starting xnee"
    run_cnee --record --device-event-range 2-3 --data-to-record 10000 --seconds-to-record 10000 --events-to-record $TLEN -o $FILE &
    XNEE_PID=$!

    verbose "XNEE PID = $XNEE_PID"
    sleep 2

    TMP=0
    while [ "$TMP" != "$LEN" ];
    do
      press_key "${STR:$TMP:1}"
      TMP=$(( $TMP + 1 ))
    done

    
    sleep 2
    verbose "shoot Xnee down"
    $KILL_1 $XNEE_PID
#    press_key a 
    sleep 3

    check_nr_of_loops $LEN $LEN $FILE
}


# main ..... I guess

verify_device swkeybd

rm k*.log

STRING="This is a simple test string for Xnee"
test_keyboard "$STRING"   k1.log
verbose  "starting...."


#rm k*.log

result_log $MYNAME 
exit