icu/internaltests/ucnv_getMaxCharSize.c
author Pavel Heimlich <pavel.heimlich@oracle.com>
Tue, 02 Nov 2010 11:29:20 +0100
changeset 39 65491902381c
child 41 fb57b25feaf0
permissions -rw-r--r--
add internal tests for Oracle fixes/enhancements

//   Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

#include <unicode/utypes.h>
#include <unicode/ucnv.h>
#include <unicode/unistr.h>
#include <unicode/translit.h>

main(int ac, char **av)
{
    UConverter *convto = 0;
    UErrorCode err = U_ZERO_ERROR;
    int8_t i;

    printf("Checking ucnv_getMaxCharSize() return value of UTF-7 conversion:\n");
    convto = ucnv_open("UTF-7", &err);
    if (U_FAILURE(err)) {
	fprintf(stderr, "ucnv_open on UTF-7 error - exiting.\n");
	exit(-1);
    }

    i = ucnv_getMaxCharSize(convto);
    if (i == 5)
    	printf("ucnv_getMaxCharSize() for UTF-7 returned %d -- success.\n", i);
    else
    	printf("ucnv_getMaxCharSize() for UTF-7 returned %d -- failed.\n", i);
    if (convto) ucnv_close(convto);

    printf("\nChecking ucnv_getMaxCharSize() return value of MUTF-7 conversion:\n");
    convto = ucnv_open("MUTF-7", &err);
    if (U_FAILURE(err)) {
	fprintf(stderr, "ucnv_open on MUTF-7 error - exiting.\n");
	exit(-1);
    }

    i = ucnv_getMaxCharSize(convto);
    if (i == 8)
    	printf("ucnv_getMaxCharSize() for MUTF-7 returned %d -- success.\n", i);
    else
    	printf("ucnv_getMaxCharSize() for MUTF-7 returned %d -- failed.\n", i);
    if (convto) ucnv_close(convto);

    printf("\nChecking ucnv_getMaxCharSize() return value of ISO-2022-JP conversion:\n");
    convto = ucnv_open("ISO-2022-JP", &err);
    if (U_FAILURE(err)) {
	fprintf(stderr, "ucnv_open on ISO-2022-JP error - exiting.\n");
	exit(-1);
    }

    i = ucnv_getMaxCharSize(convto);
    if (i == 9)
    	printf("ucnv_getMaxCharSize() for ISO-2022-JP returned %d -- success.\n", i);
    else
    	printf("ucnv_getMaxCharSize() for ISO-2022-JP returned %d -- failed.\n", i);
    if (convto) ucnv_close(convto);

    printf("\nChecking ucnv_getMaxCharSize() return value of ISO-2022-KR conversion:\n");
    convto = ucnv_open("ISO-2022-KR", &err);
    if (U_FAILURE(err)) {
	fprintf(stderr, "ucnv_open on ISO-2022-KR error - exiting.\n");
	exit(-1);
    }

    i = ucnv_getMaxCharSize(convto);
    if (i == 8)
    	printf("ucnv_getMaxCharSize() for ISO-2022-KR returned %d -- success.\n", i);
    else
    	printf("ucnv_getMaxCharSize() for ISO-2022-KR returned %d -- failed.\n", i);
    if (convto) ucnv_close(convto);

    printf("\nChecking ucnv_getMaxCharSize() return value of ISO-2022 conversion:\n");
    convto = ucnv_open("ISO-2022", &err);
    if (U_FAILURE(err)) {
	fprintf(stderr, "ucnv_open on ISO-2022 error - exiting.\n");
	exit(-1);
    }

    i = ucnv_getMaxCharSize(convto);
    if (i == 9)
    	printf("ucnv_getMaxCharSize() for ISO-2022 returned %d -- success.\n", i);
    else
    	printf("ucnv_getMaxCharSize() for ISO-2022 returned %d -- failed.\n", i);
    if (convto) ucnv_close(convto);
}