summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Udaltsov <svu@gnome.org>2004-09-24 00:18:59 +0000
committerSergey Udaltsov <svu@gnome.org>2004-09-24 00:18:59 +0000
commit07e6566c3d07ab5b3004419cc2a92babd3c3e632 (patch)
treeb26d826670b1d1fe198845bc8dbbece35f4e2d2c /tests
parent8c9220ed5ad91f9d075b27fcf0101db40220b055 (diff)
downloadlibxklavier-07e6566c3d07ab5b3004419cc2a92babd3c3e632.tar.gz
command line options give use some flexibility in testing
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config.c152
1 files changed, 124 insertions, 28 deletions
diff --git a/tests/test_config.c b/tests/test_config.c
index f7c6f05..874de45 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -1,8 +1,11 @@
#include <stdio.h>
+#include <unistd.h>
#include <X11/Xlib.h>
#include <libxklavier/xklavier.h>
#include <libxklavier/xklavier_config.h>
+enum { ACTION_NONE, ACTION_GET, ACTION_SET };
+
static void dump( XklConfigRecPtr ptr )
{
int i,j;
@@ -25,8 +28,49 @@ static void dump( XklConfigRecPtr ptr )
XklDebug( 0, " %d: [%s]\n", j++, *p++ );
}
-int main( int argc, const char * argv[] )
+int main( int argc, char * const argv[] )
{
+ int c, i;
+ int action = ACTION_NONE;
+ const char* model = NULL;
+ const char* layouts = NULL;
+ const char* options = NULL;
+
+ while (1)
+ {
+ c = getopt( argc, argv, "sgm:l:o:" );
+ if ( c == -1 )
+ break;
+ switch(c)
+ {
+ case 's':
+ printf( "Set the config\n" );
+ action = ACTION_SET;
+ break;
+ case 'g':
+ printf( "Get the config\n" );
+ action = ACTION_GET;
+ break;
+ case 'm':
+ printf( "Model: [%s]\n", model = optarg );
+ break;
+ case 'l':
+ printf( "Layouts: [%s]\n", layouts = optarg );
+ break;
+ case 'o':
+ printf( "Options: [%s]\n", options = optarg );
+ break;
+ default:
+ printf( "?? getopt returned character code 0%o ??\n", c );
+ }
+ }
+
+ if ( action == ACTION_NONE )
+ {
+ fprintf( stderr, "No action specified, terminating\n" );
+ exit( 0 );
+ }
+
Display* dpy = XOpenDisplay( NULL );
if ( dpy == NULL )
{
@@ -36,7 +80,7 @@ int main( int argc, const char * argv[] )
printf( "opened display: %p\n", dpy );
if ( !XklInit( dpy ) )
{
- XklConfigRec r1, r2;
+ XklConfigRec currentConfig, r2;
XklDebug( 0, "Xklavier initialized\n" );
XklConfigInit();
XklConfigLoadRegistry();
@@ -44,37 +88,89 @@ int main( int argc, const char * argv[] )
XklDebug( 0, "Multiple layouts are %ssupported\n",
XklMultipleLayoutsSupported() ? "" : "not " );
- XklConfigRecInit( &r1 );
- XklConfigRecInit( &r2 );
+ XklConfigRecInit( &currentConfig );
+ XklConfigGetFromServer( &currentConfig );
- if ( XklConfigGetFromServer( &r1 ) )
+ switch ( action )
{
- XklDebug( 0, "Got config from the server\n" );
- dump( &r1 );
- }
- if ( XklConfigGetFromBackup( &r2 ) )
- {
- XklDebug( 0, "Got config from the backup\n" );
- dump( &r2 );
- }
+ case ACTION_GET:
+ XklDebug( 0, "Got config from the server\n" );
+ dump( &currentConfig );
- if ( XklConfigActivate( &r2, NULL ) )
- {
- XklDebug( 0, "The backup configuration restored\n" );
- if ( XklConfigActivate( &r1, NULL ) )
- {
- XklDebug( 0, "Reverting the configuration change\n" );
- } else
- {
- XklDebug( 0, "The configuration could not be reverted: %s\n", XklGetLastError() );
- }
- } else
- {
- XklDebug( 0, "The backup configuration could not be restored: %s\n", XklGetLastError() );
+ XklConfigRecInit( &r2 );
+
+ if ( XklConfigGetFromBackup( &r2 ) )
+ {
+ XklDebug( 0, "Got config from the backup\n" );
+ dump( &r2 );
+ }
+
+ if ( XklConfigActivate( &r2, NULL ) )
+ {
+ XklDebug( 0, "The backup configuration restored\n" );
+ if ( XklConfigActivate( &currentConfig, NULL ) )
+ {
+ XklDebug( 0, "Reverting the configuration change\n" );
+ } else
+ {
+ XklDebug( 0, "The configuration could not be reverted: %s\n", XklGetLastError() );
+ }
+ } else
+ {
+ XklDebug( 0, "The backup configuration could not be restored: %s\n", XklGetLastError() );
+ }
+
+ XklConfigRecDestroy( &r2 );
+ break;
+ case ACTION_SET:
+ if ( model != NULL )
+ {
+ if ( currentConfig.model != NULL ) free ( currentConfig.model );
+ currentConfig.model = strdup( model );
+ }
+
+ if ( layouts != NULL )
+ {
+ if ( currentConfig.layouts != NULL )
+ {
+ for ( i = currentConfig.numLayouts; --i >=0; )
+ free ( currentConfig.layouts[i] );
+ free ( currentConfig.layouts );
+ for ( i = currentConfig.numVariants; --i >=0; )
+ free ( currentConfig.variants[i] );
+ free ( currentConfig.variants );
+ }
+ currentConfig.numLayouts =
+ currentConfig.numVariants = 1;
+ currentConfig.layouts = malloc( sizeof ( char* ) );
+ currentConfig.layouts[0] = strdup( layouts );
+ currentConfig.variants = malloc( sizeof ( char* ) );
+ currentConfig.variants[0] = strdup( "" );
+ }
+
+ if ( options != NULL )
+ {
+ if ( currentConfig.options != NULL )
+ {
+ for ( i = currentConfig.numOptions; --i >=0; )
+ free ( currentConfig.options[i] );
+ free ( currentConfig.options );
+ }
+ currentConfig.numOptions = 1;
+ currentConfig.options = malloc( sizeof ( char* ) );
+ currentConfig.options[0] = strdup( options );
+ }
+
+ XklDebug( 0, "New config:\n" );
+ dump( &currentConfig );
+ if ( XklConfigActivate( &currentConfig, NULL ) )
+ XklDebug( 0, "Set the config\n" );
+ else
+ XklDebug( 0, "Could not set the config: %s\n", XklGetLastError() );
+ break;
}
- XklConfigRecDestroy( &r2 );
- XklConfigRecDestroy( &r1 );
+ XklConfigRecDestroy( &currentConfig );
XklConfigFreeRegistry();
XklConfigTerm();