diff options
author | Sergey Udaltsov <svu@gnome.org> | 2006-03-12 04:20:01 +0000 |
---|---|---|
committer | Sergey Udaltsov <svu@gnome.org> | 2006-03-12 04:20:01 +0000 |
commit | 2c88cc80147b72eba939d6358939ef59d403c34e (patch) | |
tree | b6b145f6d50e1f4bba8145bef5963aee8a5f3180 /tests | |
parent | d7bc98fb5f9d55c37a08ceeedbc87cb70ee6f133 (diff) | |
download | libxklavier-2c88cc80147b72eba939d6358939ef59d403c34e.tar.gz |
branching 2.x, merging GLIBing to HEAD
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.indent.pro | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/test_config.c | 400 | ||||
-rw-r--r-- | tests/test_monitor.c | 187 |
4 files changed, 310 insertions, 284 deletions
diff --git a/tests/.indent.pro b/tests/.indent.pro new file mode 100644 index 0000000..dbec33f --- /dev/null +++ b/tests/.indent.pro @@ -0,0 +1,3 @@ +-kr +-i8 +-psl 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..ea35aa2 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -6,217 +6,223 @@ #include <string.h> #include <X11/Xlib.h> #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_rec_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" ); - printf( " -g - Dump the current config, load original system settings and revert back\n" ); - printf( " -s - Set the configuration given my -m -l -o options. Similar to setxkbmap\n" ); - printf( " -ws - Write the binary XKB config file (" PACKAGE ".xkm)\n" ); - printf( " -wb - Write the source XKB config file (" PACKAGE ".xkb)\n" ); - printf( " -d - Set the debug level (by default, 0)\n" ); - printf( " -h - Show this help\n" ); + printf + ("Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)|(-h)|(-ws)|(-wb)(-d <debugLevel>)\n"); + printf("Options:\n"); + printf + (" -g - Dump the current config, load original system settings and revert back\n"); + printf + (" -s - Set the configuration given my -m -l -o options. Similar to setxkbmap\n"); + printf(" -ws - Write the binary XKB config file (" PACKAGE + ".xkm)\n"); + printf(" -wb - Write the source XKB config file (" PACKAGE + ".xkb)\n"); + printf(" -d - Set the debug level (by default, 0)\n"); + printf(" -h - Show this help\n"); } -int main( int argc, char * const 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; - int debugLevel = -1; - int binary = 0; - Display *dpy; - - while (1) - { - c = getopt( argc, argv, "hsgm:l:o:d:w:" ); - 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; - case 'h': - printUsage(); - exit(0); - case 'd': - debugLevel = atoi( optarg ); - break; - case 'w': - action = ACTION_WRITE; - binary = ( 'b' == optarg[0] ); - default: - fprintf( stderr, "?? getopt returned character code 0%o ??\n", c ); - printUsage(); - } - } - - if ( action == ACTION_NONE ) - { - printUsage(); - exit( 0 ); - } + int c; + int action = ACTION_NONE; + const char *model = NULL; + const char *layouts = NULL; + const char *options = NULL; + int debug_level = -1; + int binary = 0; + Display *dpy; + + g_type_init_with_debug_flags(G_TYPE_DEBUG_OBJECTS | + G_TYPE_DEBUG_SIGNALS); + + while (1) { + c = getopt(argc, argv, "hsgm:l:o:d:w:"); + 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; + case 'h': + print_usage(); + exit(0); + case 'd': + 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); + print_usage(); + } + } + + if (action == ACTION_NONE) { + print_usage(); + exit(0); + } #ifdef HAVE_SETLOCALE - setlocale( LC_ALL, "" ); + setlocale( LC_ALL, "" ); #endif - dpy = XOpenDisplay( NULL ); - if ( dpy == NULL ) - { - fprintf( stderr, "Could not open display\n" ); - exit(1); - } - printf( "opened display: %p\n", dpy ); - if ( !XklInit( 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( ¤tConfig ); - XklConfigGetFromServer( ¤tConfig ); - - switch ( action ) - { - case ACTION_GET: - XklDebug( 0, "Got config from the server\n" ); - XklConfigDump( stdout, ¤tConfig ); - - XklConfigRecInit( &r2 ); - - if ( XklConfigGetFromBackup( &r2 ) ) - { - XklDebug( 0, "Got config from the backup\n" ); - XklConfigDump( stdout, &r2 ); - } - - if ( XklConfigActivate( &r2 ) ) - { - XklDebug( 0, "The backup configuration restored\n" ); - if ( XklConfigActivate( ¤tConfig ) ) - { - 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" ); - XklConfigDump( stdout, ¤tConfig ); - if ( XklConfigActivate( ¤tConfig ) ) - XklDebug( 0, "Set the config\n" ); - else - XklDebug( 0, "Could not set the config: %s\n", XklGetLastError() ); - break; - case ACTION_WRITE: - XklConfigWriteFile( binary ? ( PACKAGE ".xkm" ) : ( PACKAGE ".xkb" ), - ¤tConfig, - binary ); - XklDebug( 0, "The file " PACKAGE "%s is written\n", - binary ? ".xkm" : ".xkb" ); - break; - } - - XklConfigRecDestroy( ¤tConfig ); - - XklConfigFreeRegistry(); - XklConfigTerm(); - XklDebug( 0, "Xklavier registry freed\n" ); - XklDebug( 0, "Xklavier terminating\n" ); - XklTerm(); - } else - { - fprintf( stderr, "Could not init Xklavier: %s\n", XklGetLastError() ); - exit(2); - } - printf( "closing display: %p\n", dpy ); - XCloseDisplay(dpy); - return 0; + dpy = XOpenDisplay(NULL); + if (dpy == NULL) { + fprintf(stderr, "Could not open display\n"); + exit(1); + } + if (debug_level != -1) + xkl_set_debug_level(debug_level); + XklEngine *engine = xkl_engine_get_instance(dpy); + if (engine != NULL) { + XklConfigRec *current_config, *r2; + xkl_debug(0, "Xklavier initialized\n"); + XklConfigRegistry *config = + xkl_config_registry_get_instance(engine); + xkl_config_registry_load(config); + xkl_debug(0, "Xklavier registry loaded\n"); + xkl_debug(0, "Backend: [%s]\n", + xkl_engine_get_backend_name(engine)); + xkl_debug(0, "Supported features: 0x0%X\n", + xkl_engine_get_features(engine)); + xkl_debug(0, "Max number of groups: %d\n", + xkl_engine_get_max_num_groups(engine)); + + current_config = xkl_config_rec_new(); + xkl_config_rec_get_from_server(current_config, engine); + + switch (action) { + case ACTION_GET: + xkl_debug(0, "Got config from the server\n"); + xkl_config_rec_dump(stdout, current_config); + + r2 = xkl_config_rec_new(); + + if (xkl_config_rec_get_from_backup(r2, engine)) { + xkl_debug(0, + "Got config from the backup\n"); + xkl_config_rec_dump(stdout, r2); + } + + if (xkl_config_rec_activate(r2, engine)) { + xkl_debug(0, + "The backup configuration restored\n"); + if (xkl_config_rec_activate + (current_config, engine)) { + xkl_debug(0, + "Reverting the configuration change\n"); + } else { + xkl_debug(0, + "The configuration could not be reverted: %s\n", + xkl_get_last_error()); + } + } else { + xkl_debug(0, + "The backup configuration could not be restored: %s\n", + xkl_get_last_error()); + } + + g_object_unref(G_OBJECT(r2)); + break; + case ACTION_SET: + if (model != NULL) { + if (current_config->model != NULL) + g_free(current_config->model); + current_config->model = g_strdup(model); + } + + if (layouts != NULL) { + 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 (current_config->options != NULL) + g_strfreev(current_config-> + options); + + current_config->options = + g_new0(char *, 2); + current_config->options[0] = + g_strdup(options); + } + + xkl_debug(0, "New config:\n"); + xkl_config_rec_dump(stdout, current_config); + if (xkl_config_rec_activate + (current_config, engine)) + xkl_debug(0, "Set the config\n"); + else + xkl_debug(0, + "Could not set the config: %s\n", + xkl_get_last_error()); + break; + case ACTION_WRITE: + xkl_config_rec_write_to_file(engine, + binary ? (PACKAGE + ".xkm") + : (PACKAGE ".xkb"), + current_config, + binary); + xkl_debug(0, "The file " PACKAGE "%s is written\n", + binary ? ".xkm" : ".xkb"); + break; + } + + g_object_unref(G_OBJECT(current_config)); + + xkl_config_registry_free(config); + g_object_unref(G_OBJECT(config)); + xkl_debug(0, "Xklavier registry freed\n"); + xkl_debug(0, "Xklavier terminating\n"); + g_object_unref(G_OBJECT(engine)); + } else { + fprintf(stderr, "Could not init _xklavier\n"); + exit(2); + } + printf("closing display: %p\n", dpy); + XCloseDisplay(dpy); + return 0; } diff --git a/tests/test_monitor.c b/tests/test_monitor.c index 515c328..6928222 100644 --- a/tests/test_monitor.c +++ b/tests/test_monitor.c @@ -6,103 +6,120 @@ #include <X11/Xutil.h> #include <X11/XKBlib.h> #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" ); - printf( " -d - Set the debug level (by default, 0)\n" ); - printf( " -h - Show this help\n" ); - printf( " -l1 - listen to manage layouts\n" ); - printf( " -l2 - listen to manage window states\n" ); - printf( " -l3 - listen to track the keyboard state\n" ); + printf + ("Usage: test_monitor (-l1)(-l2)(-l3)(-h)(-d <debugLevel>)\n"); + printf("Options:\n"); + printf(" -d - Set the debug level (by default, 0)\n"); + printf(" -h - Show this help\n"); + printf(" -l1 - listen to manage layouts\n"); + printf(" -l2 - listen to manage window states\n"); + printf(" -l3 - listen to track the keyboard state\n"); } -int main( int argc, char * argv[] ) +void +state_changed(XklEngine * engine, XklEngineStateChange type, gint new_group, + gboolean restore) { - int c; - int debugLevel = -1; - XkbEvent ev; - Display* dpy; - int listenerType = 0, lt; - int listenerTypes[] = { XKLL_MANAGE_LAYOUTS, - XKLL_MANAGE_WINDOW_STATES, - XKLL_TRACK_KEYBOARD_STATE }; + xkl_debug(0, "State changed: %d,%d,%d\n", type, new_group, + restore); +} + +int +main(int argc, char *argv[]) +{ + int c; + int debug_level = -1; + XkbEvent ev; + Display *dpy; + int listener_type = 0, lt; + int listener_types[] = { XKLL_MANAGE_LAYOUTS, + XKLL_MANAGE_WINDOW_STATES, + XKLL_TRACK_KEYBOARD_STATE + }; + + g_type_init_with_debug_flags(G_TYPE_DEBUG_OBJECTS | + G_TYPE_DEBUG_SIGNALS); + + while (1) { + c = getopt(argc, argv, "hd:l:"); + if (c == -1) + break; + switch (c) { + case 'h': + print_usage(); + exit(0); + case 'd': + debug_level = atoi(optarg); + break; + case 'l': + lt = optarg[0] - '1'; + 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); + print_usage(); + exit(0); + } + } - while (1) - { - c = getopt( argc, argv, "hd:l:" ); - if ( c == -1 ) - break; - switch (c) - { - case 'h': - printUsage(); - exit(0); - case 'd': - debugLevel = atoi( optarg ); - break; - case 'l': - lt = optarg[0] - '1'; - if( lt >= 0 && lt < sizeof(listenerTypes)/sizeof(listenerTypes[0]) ) - listenerType |= listenerTypes[lt]; - break; - default: - fprintf( stderr, "?? getopt returned character code 0%o ??\n", c ); - printUsage(); - exit(0); - } - } + dpy = XOpenDisplay(NULL); + if (dpy == NULL) { + fprintf(stderr, "Could not open display\n"); + exit(1); + } + if (debug_level != -1) + xkl_set_debug_level(debug_level); + XklEngine *engine = xkl_engine_get_instance(dpy); + if (engine != NULL) { + XklConfigRec *current_config; + xkl_debug(0, "Xklavier initialized\n"); + XklConfigRegistry *config = + xkl_config_registry_get_instance(engine); + xkl_config_registry_load(config); + xkl_debug(0, "Xklavier registry loaded\n"); - dpy = XOpenDisplay( NULL ); - if ( dpy == NULL ) - { - fprintf( stderr, "Could not open display\n" ); - exit(1); - } - printf( "opened display: %p\n", dpy ); - if( !XklInit( dpy ) ) - { - XklConfigRec currentConfig; - if( debugLevel != -1 ) - XklSetDebugLevel( debugLevel ); - XklDebug( 0, "Xklavier initialized\n" ); - XklConfigInit(); - XklConfigLoadRegistry(); - XklDebug( 0, "Xklavier registry loaded\n" ); + current_config = xkl_config_rec_new(); + xkl_config_rec_get_from_server(current_config, engine); - XklConfigRecInit( ¤tConfig ); - XklConfigGetFromServer( ¤tConfig ); + g_signal_connect(engine, "X-state-changed", + G_CALLBACK(state_changed), NULL); - XklDebug( 0, "Now, listening...\n" ); - XklStartListen( listenerType ); + xkl_debug(0, "Now, listening: %X...\n", listener_type); + xkl_engine_start_listen(engine, listener_type); - while (1) - { - XNextEvent( dpy, &ev.core ); - if ( XklFilterEvents( &ev.core ) ) - XklDebug( 200, "Unknown event %d\n", ev.type ); - } + while (1) { + XNextEvent(dpy, &ev.core); + if (xkl_engine_filter_events(engine, &ev.core)) + xkl_debug(200, "Unknown event %d\n", + ev.type); + } - XklStopListen(); + xkl_engine_stop_listen(engine); - XklConfigRecDestroy( ¤tConfig ); + g_object_unref(G_OBJECT(current_config)); - XklConfigFreeRegistry(); - XklConfigTerm(); - XklDebug( 0, "Xklavier registry freed\n" ); - XklDebug( 0, "Xklavier terminating\n" ); - XklTerm(); - } else - { - fprintf( stderr, "Could not init Xklavier: %s\n", XklGetLastError() ); - exit(2); - } - printf( "closing display: %p\n", dpy ); - XCloseDisplay(dpy); - return 0; + xkl_config_registry_free(config); + g_object_unref(G_OBJECT(config)); + xkl_debug(0, "Xklavier registry freed\n"); + xkl_debug(0, "Xklavier terminating\n"); + g_object_unref(G_OBJECT(engine)); + } else { + fprintf(stderr, "Could not init Xklavier\n"); + exit(2); + } + printf("closing display: %p\n", dpy); + XCloseDisplay(dpy); + return 0; } |