TestModernIconv.c 1.04 KB
Newer Older
1 2 3 4 5 6 7 8
#ifdef HAVE_ICONV_H
#include <iconv.h>
#endif
#ifdef HAVE_SYS_ICONV_H
#include <sys/iconv.h>
#endif
#include <stdlib.h>

9
int check(const char *from, const char *to)
10
{
11
    iconv_t myConverter = iconv_open(to, from);
12

13 14 15 16 17
    if (myConverter != (iconv_t) - 1) {
        iconv_close(myConverter);
        return 0;
    } else {
        return 1;
18 19 20
    }
}

21
int main(int argc, char **argv)
22
{
23 24 25 26 27 28
    const char *from[] = { "CP874", "CP932", "CP936", "CP949",
                           "CP950", "CP1250", "CP1251", "CP1252",
                           "CP1253", "CP1254", "CP1255", "CP1256",
                           "CP1257", "koi8-r", 0
                         };
    const char *to[] = { "UNICODELITTLE", "UNICODEBIG", 0 };
29 30 31
    int fromIndex = 0;
    int toIndex = 0;

32 33 34 35 36 37 38 39 40
    while (to[ toIndex ] != 0) {
        while (from[ fromIndex ] != 0) {
            if (check(from[ fromIndex ], to[ toIndex ]) != 0) {
                exit(1);
            }
            fromIndex = fromIndex + 1;
        }
        toIndex = toIndex + 1;
        fromIndex = 0;
41
    }
42
    exit(0);
43
}