Submitted by Anonymous on Sun, 05/06/2001 - 11:15.
Can anyone tell me the problem with the following code. It registers a rep type converter, then adds the reverse converter with XmRepTypeAddReverse and tries to make a couple of conversions. The reverse conversions do not work properly. I`ve looked at the openMotif reverse converter that gets added and it looks wrong to me, but I may not be using it correctly, Motif sometimes confuses me )
The code is also available as the LessTif test
test/Xm/reptype/test1.c
in case someone already has that code co`ed.
#include
#include
#include
#define TestRepType "TestRepType"
static char *FallBack[] = {
NULL
};
int
main(int argc, char **argv)
{
int target;
int GlobalErrors = 0;
XtAppContext app;
Widget Shell;
XmRepTypeId id;
XrmValue from, to;
XrmValue rev_from, rev_to;
static String value_names[] = {
"client",
"server",
};
static unsigned char values[] = {
100,
101,
};
XtSetLanguageProc(NULL, NULL, NULL);
Shell = XtVaAppInitialize(&app, "Shell",
NULL, 0,
&argc, argv,
FallBack,
NULL);
XtRealizeWidget(Shell);
id = XmRepTypeRegister(TestRepType,
value_names, values,
XtNumber(value_names));
XmRepTypeAddReverse(id);
printf("XmRepTypeId %i
", id);
for (target = 0; target < XtNumber(value_names); target++)
{
from.size = sizeof(String);
from.addr = value_names[target];
printf("Convert %s >%s< -> %s ",
XmRString,
from.addr,
TestRepType);
XtConvertAndStore(Shell, XmRString, &from, TestRepType, &to);
if (to.size != sizeof(unsigned char) || *(to.addr) != values[target])
{
printf("Convert error
");
GlobalErrors++;
}
else
{
printf(">%d< (okay)
", *(to.addr));
}
rev_from.size = to.size;
rev_from.addr = (XtPointer)&(values[target]);
printf("Convert %s >%d< -> XmRString ",
TestRepType,
*(rev_from.addr));
rev_to.size = 0;
rev_to.addr = NULL;
XtConvertAndStore(Shell, TestRepType, &rev_from, XmRString, &rev_to);
if (rev_to.size != sizeof(String)
|| strcmp(rev_to.addr, value_names[target]) != 0)
{
printf("Convert error
");
GlobalErrors++;
}
else
{
printf(">%s< (okay)
", rev_to.addr);
}
}
exit(GlobalErrors);
}