summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Udaltsov <svu@gnome.org>2006-02-19 00:56:04 +0000
committerSergey Udaltsov <svu@gnome.org>2006-02-19 00:56:04 +0000
commitfc6495bb5902fdd5ab3841a70aeb103d7ae92827 (patch)
tree7121224abbf13d1982dbfce1cc858dba18a3e4e1
parent164d8dbd499e5dc5ce7a43c0616fee055b481426 (diff)
downloadlibxklavier-fc6495bb5902fdd5ab3841a70aeb103d7ae92827.tar.gz
tests glibified
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/test_config.c160
-rw-r--r--tests/test_monitor.c70
3 files changed, 105 insertions, 129 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9d844da..3690756 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,7 @@ test_config_SOURCES=test_config.c
test_monitor_SOURCES=test_monitor.c
-AM_CFLAGS=-Wall -Werror -I$(includedir) -I$(x_includes) -I$(top_srcdir)
+AM_CFLAGS=-Wall -Werror -I$(includedir) -I$(x_includes) -I$(top_srcdir) $(GLIB_CFLAGS)
-AM_LDFLAGS=$(top_builddir)/libxklavier/libxklavier.la -L$(x_libraries) -lX11
+AM_LDFLAGS=$(top_builddir)/libxklavier/libxklavier.la -L$(x_libraries) -lX11 $(GLIB_LIBS)
diff --git a/tests/test_config.c b/tests/test_config.c
index 9cc17be..a39957d 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -8,22 +8,12 @@
#include <libxklavier/xklavier.h>
#include <libxklavier/xklavier_config.h>
-#ifdef HAVE_SETLOCALE
-# include <locale.h>
-#endif
-
-#ifdef __STRICT_ANSI__
-/* these are functions which are NOT in ANSI C.
- Probably we should provide the implementation */
-extern char *strdup( const char *s );
-#endif
-
-extern void XklConfigDump( FILE* file,
- XklConfigRecPtr data );
+extern void xkl_config_dump( FILE* file,
+ XklConfigRec *data );
enum { ACTION_NONE, ACTION_GET, ACTION_SET, ACTION_WRITE };
-static void printUsage(void)
+static void print_usage(void)
{
printf( "Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)|(-h)|(-ws)|(-wb)(-d <debugLevel>)\n" );
printf( "Options:\n" );
@@ -37,12 +27,12 @@ static void printUsage(void)
int main( int argc, char * const argv[] )
{
- int c, i;
+ int c;
int action = ACTION_NONE;
const char* model = NULL;
const char* layouts = NULL;
const char* options = NULL;
- int debugLevel = -1;
+ int debug_level = -1;
int binary = 0;
Display *dpy;
@@ -71,30 +61,26 @@ int main( int argc, char * const argv[] )
printf( "Options: [%s]\n", options = optarg );
break;
case 'h':
- printUsage();
+ print_usage();
exit(0);
case 'd':
- debugLevel = atoi( optarg );
+ debug_level = atoi( optarg );
break;
case 'w':
action = ACTION_WRITE;
binary = ( 'b' == optarg[0] );
default:
fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
- printUsage();
+ print_usage();
}
}
if ( action == ACTION_NONE )
{
- printUsage();
+ print_usage();
exit( 0 );
}
-#ifdef HAVE_SETLOCALE
- setlocale( LC_ALL, "" );
-#endif
-
dpy = XOpenDisplay( NULL );
if ( dpy == NULL )
{
@@ -102,118 +88,108 @@ int main( int argc, char * const argv[] )
exit(1);
}
printf( "opened display: %p\n", dpy );
- if ( !XklInit( dpy ) )
+ if ( !xkl_init( dpy ) )
{
- XklConfigRec currentConfig, r2;
- if( debugLevel != -1 )
- XklSetDebugLevel( debugLevel );
- XklDebug( 0, "Xklavier initialized\n" );
- XklConfigInit();
- XklConfigLoadRegistry();
- XklDebug( 0, "Xklavier registry loaded\n" );
- XklDebug( 0, "Backend: [%s]\n", XklGetBackendName() );
- XklDebug( 0, "Supported features: 0x0%X\n", XklGetBackendFeatures() );
- XklDebug( 0, "Max number of groups: %d\n", XklGetMaxNumGroups() );
-
- XklConfigRecInit( &currentConfig );
- XklConfigGetFromServer( &currentConfig );
+ XklConfigRec current_config, r2;
+ if( debug_level != -1 )
+ xkl_set_debug_level( debug_level );
+ xkl_debug( 0, "Xklavier initialized\n" );
+ xkl_config_init();
+ xkl_config_registry_load();
+ xkl_debug( 0, "Xklavier registry loaded\n" );
+ xkl_debug( 0, "Backend: [%s]\n", xkl_backend_get_name() );
+ xkl_debug( 0, "Supported features: 0x0%X\n", xkl_backend_get_features() );
+ xkl_debug( 0, "Max number of groups: %d\n", xkl_groups_get_max_num() );
+
+ xkl_config_rec_init( &current_config );
+ xkl_config_get_from_server( &current_config );
switch ( action )
{
case ACTION_GET:
- XklDebug( 0, "Got config from the server\n" );
- XklConfigDump( stdout, &currentConfig );
+ xkl_debug( 0, "Got config from the server\n" );
+ xkl_config_dump( stdout, &current_config );
- XklConfigRecInit( &r2 );
+ xkl_config_rec_init( &r2 );
- if ( XklConfigGetFromBackup( &r2 ) )
+ if ( xkl_config_get_from_backup( &r2 ) )
{
- XklDebug( 0, "Got config from the backup\n" );
- XklConfigDump( stdout, &r2 );
+ xkl_debug( 0, "Got config from the backup\n" );
+ xkl_config_dump( stdout, &r2 );
}
- if ( XklConfigActivate( &r2 ) )
+ if ( xkl_config_activate( &r2 ) )
{
- XklDebug( 0, "The backup configuration restored\n" );
- if ( XklConfigActivate( &currentConfig ) )
+ xkl_debug( 0, "The backup configuration restored\n" );
+ if ( xkl_config_activate( &current_config ) )
{
- XklDebug( 0, "Reverting the configuration change\n" );
+ xkl_debug( 0, "Reverting the configuration change\n" );
} else
{
- XklDebug( 0, "The configuration could not be reverted: %s\n", XklGetLastError() );
+ xkl_debug( 0, "The configuration could not be reverted: %s\n", xkl_get_last_error() );
}
} else
{
- XklDebug( 0, "The backup configuration could not be restored: %s\n", XklGetLastError() );
+ xkl_debug( 0, "The backup configuration could not be restored: %s\n", xkl_get_last_error() );
}
- XklConfigRecDestroy( &r2 );
+ xkl_config_rec_destroy( &r2 );
break;
case ACTION_SET:
if ( model != NULL )
{
- if ( currentConfig.model != NULL ) free ( currentConfig.model );
- currentConfig.model = strdup( model );
+ if ( current_config.model != NULL ) g_free ( current_config.model );
+ current_config.model = g_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 ( current_config.layouts != NULL )
+ g_strfreev (current_config.layouts);
+ if ( current_config.variants != NULL )
+ g_strfreev (current_config.variants);
+
+ current_config.layouts = g_new0( char *, 2 );
+ current_config.layouts[0] = g_strdup( layouts );
+ current_config.variants = g_new0( char *, 2 );
+ current_config.variants[0] = g_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 );
+ if ( current_config.options != NULL )
+ g_strfreev (current_config.options);
+
+ current_config.options = g_new0( char *, 2 );
+ current_config.options[0] = g_strdup( options );
}
- XklDebug( 0, "New config:\n" );
- XklConfigDump( stdout, &currentConfig );
- if ( XklConfigActivate( &currentConfig ) )
- XklDebug( 0, "Set the config\n" );
+ xkl_debug( 0, "New config:\n" );
+ xkl_config_dump( stdout, &current_config );
+ if ( xkl_config_activate( &current_config ) )
+ xkl_debug( 0, "Set the config\n" );
else
- XklDebug( 0, "Could not set the config: %s\n", XklGetLastError() );
+ xkl_debug( 0, "Could not set the config: %s\n", xkl_get_last_error() );
break;
case ACTION_WRITE:
- XklConfigWriteFile( binary ? ( PACKAGE ".xkm" ) : ( PACKAGE ".xkb" ),
- &currentConfig,
- binary );
- XklDebug( 0, "The file " PACKAGE "%s is written\n",
+ xkl_config_write_file( binary ? ( PACKAGE ".xkm" ) : ( PACKAGE ".xkb" ),
+ &current_config,
+ binary );
+ xkl_debug( 0, "The file " PACKAGE "%s is written\n",
binary ? ".xkm" : ".xkb" );
break;
}
- XklConfigRecDestroy( &currentConfig );
+ xkl_config_rec_destroy( &current_config );
- XklConfigFreeRegistry();
- XklConfigTerm();
- XklDebug( 0, "Xklavier registry freed\n" );
- XklDebug( 0, "Xklavier terminating\n" );
- XklTerm();
+ xkl_config_registry_free();
+ xkl_config_term();
+ xkl_debug( 0, "Xklavier registry freed\n" );
+ xkl_debug( 0, "Xklavier terminating\n" );
+ xkl_term();
} else
{
- fprintf( stderr, "Could not init Xklavier: %s\n", XklGetLastError() );
+ fprintf( stderr, "Could not init _xklavier: %s\n", xkl_get_last_error() );
exit(2);
}
printf( "closing display: %p\n", dpy );
diff --git a/tests/test_monitor.c b/tests/test_monitor.c
index 515c328..e880307 100644
--- a/tests/test_monitor.c
+++ b/tests/test_monitor.c
@@ -8,10 +8,10 @@
#include <libxklavier/xklavier.h>
#include <libxklavier/xklavier_config.h>
-extern void XklConfigDump( FILE* file,
- XklConfigRecPtr data );
+extern void xkl_config_dump( FILE* file,
+ XklConfigRec *data );
-static void printUsage()
+static void print_usage()
{
printf( "Usage: test_monitor (-l1)(-l2)(-l3)(-h)(-d <debugLevel>)\n" );
printf( "Options:\n" );
@@ -25,13 +25,13 @@ static void printUsage()
int main( int argc, char * argv[] )
{
int c;
- int debugLevel = -1;
+ int debug_level = -1;
XkbEvent ev;
Display* dpy;
- int listenerType = 0, lt;
- int listenerTypes[] = { XKLL_MANAGE_LAYOUTS,
- XKLL_MANAGE_WINDOW_STATES,
- XKLL_TRACK_KEYBOARD_STATE };
+ int listener_type = 0, lt;
+ int listener_types[] = { XKLL_MANAGE_LAYOUTS,
+ XKLL_MANAGE_WINDOW_STATES,
+ XKLL_TRACK_KEYBOARD_STATE };
while (1)
{
@@ -41,19 +41,19 @@ int main( int argc, char * argv[] )
switch (c)
{
case 'h':
- printUsage();
+ print_usage();
exit(0);
case 'd':
- debugLevel = atoi( optarg );
+ debug_level = atoi( optarg );
break;
case 'l':
lt = optarg[0] - '1';
- if( lt >= 0 && lt < sizeof(listenerTypes)/sizeof(listenerTypes[0]) )
- listenerType |= listenerTypes[lt];
+ if( lt >= 0 && lt < sizeof(listener_types)/sizeof(listener_types[0]) )
+ listener_type |= listener_types[lt];
break;
default:
fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
- printUsage();
+ print_usage();
exit(0);
}
}
@@ -65,41 +65,41 @@ int main( int argc, char * argv[] )
exit(1);
}
printf( "opened display: %p\n", dpy );
- if( !XklInit( dpy ) )
+ if( !xkl_init( dpy ) )
{
- XklConfigRec currentConfig;
- if( debugLevel != -1 )
- XklSetDebugLevel( debugLevel );
- XklDebug( 0, "Xklavier initialized\n" );
- XklConfigInit();
- XklConfigLoadRegistry();
- XklDebug( 0, "Xklavier registry loaded\n" );
+ XklConfigRec current_config;
+ if( debug_level != -1 )
+ xkl_set_debug_level( debug_level );
+ xkl_debug( 0, "Xklavier initialized\n" );
+ xkl_config_init();
+ xkl_config_registry_load();
+ xkl_debug( 0, "Xklavier registry loaded\n" );
- XklConfigRecInit( &currentConfig );
- XklConfigGetFromServer( &currentConfig );
+ xkl_config_rec_init( &current_config );
+ xkl_config_get_from_server( &current_config );
- XklDebug( 0, "Now, listening...\n" );
- XklStartListen( listenerType );
+ xkl_debug( 0, "Now, listening...\n" );
+ xkl_listen_start( listener_type );
while (1)
{
XNextEvent( dpy, &ev.core );
- if ( XklFilterEvents( &ev.core ) )
- XklDebug( 200, "Unknown event %d\n", ev.type );
+ if ( xkl_events_filter( &ev.core ) )
+ xkl_debug( 200, "Unknown event %d\n", ev.type );
}
- XklStopListen();
+ xkl_listen_stop();
- XklConfigRecDestroy( &currentConfig );
+ xkl_config_rec_destroy( &current_config );
- XklConfigFreeRegistry();
- XklConfigTerm();
- XklDebug( 0, "Xklavier registry freed\n" );
- XklDebug( 0, "Xklavier terminating\n" );
- XklTerm();
+ xkl_config_registry_free();
+ xkl_config_term();
+ xkl_debug( 0, "Xklavier registry freed\n" );
+ xkl_debug( 0, "Xklavier terminating\n" );
+ xkl_term();
} else
{
- fprintf( stderr, "Could not init Xklavier: %s\n", XklGetLastError() );
+ fprintf( stderr, "Could not init Xklavier: %s\n", xkl_get_last_error() );
exit(2);
}
printf( "closing display: %p\n", dpy );