Mail Archives: djgpp-workers/2003/10/31/01:34:07
>>> I don't have time to review them properly, but they basically
>>> look OK to me. I'll review them properly on Sunday, hopefully.
>>>
>>> Do you have any test programs for these functions?
>>>
>>> If there are any existing tests, do they still pass, after
>>> applying your patches?
>>
>> In general, without new setlocale() all locale patches should
>> do nothing more then all those functions currently do. They
>> only add the possibility to modify the behaviour of these
>> functions from external modules.
>
> Sure, it should work the same. ;) But how can you prove it
> without some regression tests?
Because of they obvious to me? ;)
>> For decimal point fixes I'll write the test cases where
>> decimal_point is set from the application to some odd character
>> (like comma or even ampersend) and test that conversion from
>> ASCII and to ASCII still stable.
>
> Sounds good.
Here is the test case:
== decimal.c ==
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
double d;
long double ld;
char buf[256];
char *end;
int main(int ac, char *av[])
{
localeconv()->decimal_point[0] = '$';
strcpy(buf, "12$26");
d = strtod(buf, &end);
if((d != 12.26) || (end != &buf[5]))
{
printf("strtod() failed\n");
return -1;
}
ld = _strtold(buf, &end);
if((ld != 12.26L) || (end != &buf[5]))
{
printf("strtold() failed\n");
return -2;
}
sprintf(buf, "%.2f", d);
if(strcmp(buf, "12$26"))
{
printf("sprintf failed\n");
return -3;
}
sscanf(buf, "%Lf", &ld);
if(ld != 12.26L)
{
printf("sscanf failed: %Lf\n", ld);
return -4;
}
printf("all tests passed\n");
return 0;
}
== end of file ==
>> For strcoll and strftime it is possible to modify static data
>> and test that the result is also changed. I tested it with new
>> setlocale() on Russian locale.
>
>Sounds good.
Here are very simple test case for these two:
== collate.c ==
#include <stdio.h>
#include <string.h>
extern unsigned char __dj_collate_table[256];
int main(int ac, char *av[])
{
int c;
__dj_collate_table['a'] = 'A';
__dj_collate_table['A'] = 'a';
c = strcoll("a", "A");
printf("strcoll: %s [%s] %s\n", "a", c ? (c > 0) ? ">" : "<" : "==", "A");
c = strcmp("a", "A");
printf("strcmp: %s [%s] %s\n", "a", c ? (c > 0) ? ">" : "<" : "==", "A");
return 0;
}
== end of file ==
== xstrftm.c ==
#include <stdio.h>
#include <string.h>
#include <time.h>
extern char __dj_date_format[10];
extern char __dj_time_format[16];
int main(int ac, char *av[])
{
char buf[99];
time_t t = time(NULL);
strcpy(__dj_date_format, "%d|%m|%Y");
strcpy(__dj_time_format, "[%H|%M|%S]");
strftime(buf, sizeof(buf), "%x %X", gmtime(&t));
printf("%s\n", buf);
return 0;
}
== end of file ==
--
Alexander Aganichev
url: http://aaganichev.narod.ru
e-mail: aaganichev AT yandex DOT ru
gsm: +7-095-786-1339
- Raw text -