/* test-XGetIMValues: test case for XGetIMValues() * * Copyright (C) 2010 Yann Droneaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Author: Yann Droneaud * */ #include #include #include #include #include #include #include #include int main(void) { Display *display; XIM im; XIMValuesList *imvl = NULL; XIMStyles *ims = NULL; XIMValuesList *icvl = NULL; char *name; char *p; char *invalid_name = "INVALID"; /* warning: don't test this on big endian */ void *invalid_arg = (void *) 0x004c754e; /* "NuL" */ setlocale(LC_ALL, ""); if (XSupportsLocale()) { printf("XLib support current locale\n"); } else { printf("Warning: XLib does support current locale: %s\n", setlocale(LC_ALL, NULL)); } display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "Can't open display '%s'\n", XDisplayName(NULL)); return 1; } p = XSetLocaleModifiers(""); if (p == NULL) { p = XSetLocaleModifiers("@im=none"); } if (p) { printf("Current locale modifier '%s'\n", p); } else { printf("can't set locale modifiers\n"); } im = XOpenIM(display, NULL, NULL, NULL); if (im == NULL) { p = XSetLocaleModifiers("@im=none"); im = XOpenIM(display, NULL, NULL, NULL); } if (im == NULL) { fprintf(stderr, "Can't open IM: leaving\n"); XCloseDisplay(display); return 1; } /* retrieve some values, and get an error */ name = XGetIMValues(im, XNQueryIMValuesList, &imvl, XNQueryInputStyle, &ims, XNQueryICValuesList, &icvl, invalid_name, &invalid_arg, NULL); if (name != NULL) { /* * name should point to the name * of the values which was not retrieved, eg. "INVALID" */ printf("XGetIMValues() returned: %p '%s'\n" " invalid name was : %p '%s'\n" " invalid arg was : %p\n", name, name, invalid_name, invalid_name, &invalid_arg); if (name == (char *) &invalid_arg) { fprintf(stderr, "ERROR: XGetIMValues() returned address of argument instead of its name\n"); fprintf(stderr, "ERROR: valid function return would be: %p '%s'\n", invalid_name, invalid_name); } } XFree(imvl); XFree(ims); XFree(icvl); XCloseIM(im); XCloseDisplay(display); return 0; }