starting test scripts
[xorg/xkeyboard-config] / tests / testModels.pl
1 #!/bin/env perl
2
3 use strict;
4
5 my $origXkbRules;
6 my $origXkbModel;
7 my $origXkbLayouts;
8 my $origXkbOptions;
9 my $origXkbVariants;
10
11 sub backupXkbSettings
12 {
13   open (XPROP, "xprop -root |") or die "Could not start xprop";
14   PROP: while (<XPROP>)
15   {
16     if (/_XKB_RULES_NAMES\(STRING\) = \"(.*)\", \"(.*)\", \"(.*)\", \"(.*)\", \"(.*)\"/)
17     {
18       ( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions ) = 
19       ( $1, $2, $3, $4, $5 ) ;
20       last PROP;
21     }
22   }
23   close XPROP;
24 }
25
26 sub setXkbSettings
27 {
28   my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = @_;
29   ( system ( "setxkbmap", 
30        "-rules", $xkbRules,
31        "-model", $xkbModel,
32        "-layout", $xkbLayouts,
33        "-variant", $xkbVariants,
34        "-option", $xkbOptions ) == 0 ) or die "Could not set xkb configuration";
35 }
36
37 sub restoreXkbSettings
38 {
39   setXkbSettings( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
40 }
41
42 sub dumpXkbSettings
43 {
44   my ( $xkbRules, $xkbModel, $xkbLayouts, $xkbVariants, $xkbOptions ) = @_;
45   print "rules: [$xkbRules]\n" ;
46   print "model: [$xkbModel]\n" ;
47   print "layouts: [$xkbLayouts]\n" ;
48   print "variants: [$xkbVariants]\n" ;
49   print "options: [$xkbOptions]\n" ;
50 }
51
52 sub testLevel1
53 {
54   my ( $type, $idx ) = @_;
55
56   open ( XSLTPROC, "xsltproc --stringparam type $type listCIs.xsl ../rules/base.xml.in |" ) or
57     die ( "Could not start xsltproc" );
58   while (<XSLTPROC>)
59   {
60     chomp();
61     if (/(\w+)/)
62     {
63       my $paramValue=$1;
64       print "--- setting $type: [$paramValue]\n";
65       my @params = ( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
66       @params[$idx] = $paramValue;
67       dumpXkbSettings ( @params );
68       setXkbSettings ( @params );
69     }
70   }
71   close XSLTPROC;
72 }
73
74 backupXkbSettings();
75
76 dumpXkbSettings( $origXkbRules, $origXkbModel, $origXkbLayouts, $origXkbVariants, $origXkbOptions );
77
78 testLevel1( "model", 1 );
79
80 restoreXkbSettings();