aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/xkeyboard-config/tests/xkbTestFunc.pm
blob: 77f03144fc62da369f2129b9a7717a2f31990c98 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package xkbTestFunc;

use strict;
use warnings;

our $VERSION='1.00';

our $origXkbRules;
our $origXkbModel;
our $origXkbLayouts;
our $origXkbOptions;
our $origXkbVariants;

sub backupXkbSettings
{
  ( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions ) = getXkbSettings();
}

sub getXkbSettings
{
  my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions );

  open (XPROP, "xprop -root |") or die "Could not start xprop";
  PROP: while (<XPROP>)
  {
    if (/_XKB_RULES_NAMES\(STRING\) = \"(.*)\", \"(.*)\", \"(.*)\", \"(.*)\", \"(.*)\"/)
    {
      ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = 
      ( $1, $2, $3, $4, $5 ) ;
      last PROP;
    }
  }
  close XPROP;
  
  return ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions );
}

sub setXkbSettings
{
  my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = @_;
  my $outfile = ".test.out.xkb";
  ( system ( "setxkbmap -rules \"$xkbRules\" " .
             "-model \"$xkbModel\" " .
             "-layout \"$xkbLayouts\" " .
             "-variant \"$xkbVariants\" " .
             "-option \"$xkbOptions\" " .
             "-print | xkbcomp - -xkb $outfile" ) == 0 ) or die "Could not set xkb configuration";
  unlink($outfile);
}

sub restoreXkbSettings
{
  setXkbSettings( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
}

sub defaultXkbSettings
{
  return ( "base", "pc105", "us", "", "" );
}

sub dumpXkbSettings
{
  my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = @_;
  print "rules: [$xkbRules]\n" ;
  print "model: [$xkbModel]\n" ;
  print "layouts: [$xkbLayouts]\n" ;
  print "variants: [$xkbVariants]\n" ;
  print "options: [$xkbOptions]\n" ;
}

sub dumpXkbSettingsBackup
{
  dumpXkbSettings( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
}

sub testLevel1
{
  my ( $type, $idx ) = @_;

  open ( XSLTPROC, "xsltproc --stringparam type $type listCIs.xsl ../rules/base.xml.in |" ) or
    die ( "Could not start xsltproc" );
  while (<XSLTPROC>)
  {
    chomp();
    if (/(\S+)/)
    {
      my $paramValue=$1;
      print "--- setting $type: [$paramValue]\n";
      my @params = defaultXkbSettings();
      $params[$idx] = $paramValue;
      dumpXkbSettings ( @params );
      setXkbSettings ( @params );
      #print "--- dump:\n";
      #dumpXkbSettings( getXkbSettings() );
    }
  }
  close XSLTPROC;
}

sub testLevel2
{
  my ( $type, $subtype, $idx, $delim1, $delim2, $ifCheckLevel1, $ifAddLevel1, $ifResetToDefault ) = @_;

  open ( XSLTPROC, "xsltproc --stringparam type $type listCIs.xsl ../rules/base.xml.in |" ) or
    die ( "Could not start xsltproc" );
  while (<XSLTPROC>)
  {
    chomp();
    if (/(\S+)/)
    {
      my $paramValue=$1;
      print "--- scanning $type: [$paramValue]\n";

      if ( $ifCheckLevel1 )
      {
        my @params = defaultXkbSettings();
        if ( $ifResetToDefault )
        {
          setXkbSettings ( @params );
        }
        $params[$idx] = "$paramValue";
        dumpXkbSettings ( @params );
        setXkbSettings ( @params );
        #print "--- dump:\n";
        #dumpXkbSettings( getXkbSettings() );
      }

      open ( XSLTPROC2, "xsltproc --stringparam type $subtype --stringparam parentId $paramValue listCI2.xsl ../rules/base.xml.in |" ) or
        die ( "Could not start xsltproc" );
      while (<XSLTPROC2>)
      {
        chomp();
        if (/(\S+)/)
        {
          my $paramValue2=$1;
          print "  --- $subtype: [$paramValue2]\n";
          my @params = defaultXkbSettings();
          if ( $ifResetToDefault )
          {
            setXkbSettings ( @params );
          }
          if ( $ifAddLevel1 )
          {
            $params[$idx] = "$paramValue$delim1$paramValue2$delim2";
          }
          else
          {
            $params[$idx] = "$paramValue2";
          }
          dumpXkbSettings ( @params );
          setXkbSettings ( @params );
          #print "--- dump:\n";
          #dumpXkbSettings( getXkbSettings() );
        }
      }
      close XSLTPROC2;
    }
  }
  close XSLTPROC;
}

1;
__END__

No docs yet