Yahoo! Models test pased ok!
[xorg/xkeyboard-config] / tests / xkbTestFunc.pm
1 package xkbTestFunc;
2
3 use strict;
4 use warnings;
5
6 our $VERSION='1.00';
7
8 our $origXkbRules;
9 our $origXkbModel;
10 our $origXkbLayouts;
11 our $origXkbOptions;
12 our $origXkbVariants;
13
14 sub backupXkbSettings
15 {
16   ( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions ) = getXkbSettings();
17 }
18
19 sub getXkbSettings
20 {
21   my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions );
22
23   open (XPROP, "xprop -root |") or die "Could not start xprop";
24   PROP: while (<XPROP>)
25   {
26     if (/_XKB_RULES_NAMES\(STRING\) = \"(.*)\", \"(.*)\", \"(.*)\", \"(.*)\", \"(.*)\"/)
27     {
28       ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = 
29       ( $1, $2, $3, $4, $5 ) ;
30       last PROP;
31     }
32   }
33   close XPROP;
34   
35   return ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions );
36 }
37
38 sub setXkbSettings
39 {
40   my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = @_;
41   ( system ( "setxkbmap", "-synch",
42        "-rules", $xkbRules,
43        "-model", $xkbModel,
44        "-layout", $xkbLayouts,
45        "-variant", $xkbVariants,
46        "-option", $xkbOptions ) == 0 ) or die "Could not set xkb configuration";
47 }
48
49 sub restoreXkbSettings
50 {
51   setXkbSettings( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
52 }
53
54 sub defaultXkbSettings
55 {
56   return ( "base", "pc105", "us", "", "" );
57 }
58
59 sub dumpXkbSettings
60 {
61   my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = @_;
62   print "rules: [$xkbRules]\n" ;
63   print "model: [$xkbModel]\n" ;
64   print "layouts: [$xkbLayouts]\n" ;
65   print "variants: [$xkbVariants]\n" ;
66   print "options: [$xkbOptions]\n" ;
67 }
68
69 sub dumpXkbSettingsBackup
70 {
71   dumpXkbSettings( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
72 }
73
74 sub testLevel1
75 {
76   my ( $type, $idx ) = @_;
77
78   open ( XSLTPROC, "xsltproc --stringparam type $type listCIs.xsl ../rules/base.xml.in |" ) or
79     die ( "Could not start xsltproc" );
80   while (<XSLTPROC>)
81   {
82     chomp();
83     if (/(\S+)/)
84     {
85       my $paramValue=$1;
86       print "--- setting $type: [$paramValue]\n";
87       my @params = defaultXkbSettings();
88       $params[$idx] = $paramValue;
89       dumpXkbSettings ( @params );
90       setXkbSettings ( @params );
91       #print "--- dump:\n";
92       #dumpXkbSettings( getXkbSettings() );
93     }
94   }
95   close XSLTPROC;
96 }
97
98 sub testLevel2
99 {
100   my ( $type, $subtype, $idx, $delim1, $delim2 ) = @_;
101
102   open ( XSLTPROC, "xsltproc --stringparam type $type listCIs.xsl ../rules/base.xml.in |" ) or
103     die ( "Could not start xsltproc" );
104   while (<XSLTPROC>)
105   {
106     chomp();
107     if (/(\S+)/)
108     {
109       my $paramValue=$1;
110       print "--- scanning $type: [$paramValue]\n";
111
112       my @params = defaultXkbSettings();
113       $params[$idx] = "$paramValue";
114       dumpXkbSettings ( @params );
115       setXkbSettings ( @params );
116       #print "--- dump:\n";
117       #dumpXkbSettings( getXkbSettings() );
118
119       open ( XSLTPROC2, "xsltproc --stringparam type $subtype --stringparam parentId $paramValue listCI2.xsl ../rules/base.xml.in |" ) or
120         die ( "Could not start xsltproc" );
121       while (<XSLTPROC2>)
122       {
123         chomp();
124         if (/(\S+)/)
125         {
126           my $paramValue2=$1;
127           print "  --- $subtype: [$paramValue2]\n";
128           my @params = defaultXkbSettings();
129           $params[$idx] = "$paramValue$delim1$paramValue2$delim2";
130           dumpXkbSettings ( @params );
131           setXkbSettings ( @params );
132           #print "--- dump:\n";
133           #dumpXkbSettings( getXkbSettings() );
134         }
135       }
136       close XSLTPROC2;
137     }
138   }
139   close XSLTPROC;
140 }
141
142 1;
143 __END__
144
145 No docs yet