source: trunk/libs/newlib/src/newlib/testsuite/newlib.iconv/iconvnm.c @ 620

Last change on this file since 620 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2003, Artem B. Bityuckiy, SoftMine Corporation.
3 * Rights transferred to Franklin Electronic Publishers.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26#include <stdio.h>
27#include <stdlib.h>
28#include <iconv.h>
29#include <errno.h>
30#include <newlib.h>
31#include "check.h"
32
33#ifdef _ICONV_ENABLED
34
35char *good_names[] = {
36#ifdef _ICONV_CONVERTER_ISO_8859_5
37"iso_8859_5", "iso-8859-5", "iso-8859_5", "IsO-8859_5"
38#elif defined _ICONV_CONVERTER_US_ASCII
39"us_ascii", "US_ASCII", "us-ASCII", "US-ASCII"
40#elif defined _ICONV_CONVERTER_EUC_JP
41"euc-jp", "EUC_JP", "euc-JP", "EUC-JP" 
42#elif defined _ICONV_CONVERTER_UTF_8
43"utf_8", "UTF_8", "uTf-8", "UTF-8"
44#else
45#endif
46};
47
48char *bad_names[] =
49{" ", "iso", "8", "iso_8859_5 ", " iso_8859_5", "csisolatincyrillic ",
50 " csisolatincyrillic", "euc-", "p", "euc_jp ", "euc-jp-",
51 "us_as", "us_", "us_ascii ", " us_ascii",
52 "CCCP", "", "-1", "-", "_", "---", "___", "-_-_-", "_-_-_", NULL};
53   
54int main(int argc, char **argv)
55{
56    int i, failed = 0;
57    iconv_t cd;
58
59    puts("iconv names test");
60
61    CHECK(setenv("NLSPATH", "./", 0) != -1);
62
63    for (i = 0; i < sizeof(good_names)/sizeof(char *); i++)
64    {
65        printf("Trying iconv(%s, %s)", good_names[0], good_names[i]);
66        fflush(stdout);
67
68        cd = iconv_open(good_names[0], good_names[i]);
69       
70        if (cd == (iconv_t)-1)
71        {
72            puts(" ... FAILED");
73            failed += 1;
74        }
75        else
76        {
77            puts(" ... PASSED");
78            CHECK(iconv_close(cd) != -1);
79        }
80    }
81   
82    for (i = 0; i < sizeof(bad_names)/sizeof(char *); i++)
83    {
84        printf("Trying iconv(%s, \"%s\")", good_names[0], bad_names[i]);
85        fflush(stdout);
86
87        cd = iconv_open(good_names[0], bad_names[i]);
88       
89        if (cd != (iconv_t)-1)
90        {
91            puts(" ... FAILED");
92            failed += 1;
93        }
94        else
95            puts(" ... PASSED");
96    }
97   
98    if (failed)
99    {
100        printf("%d FAILTURES\n", failed);
101        abort();
102    }
103
104    exit(0);
105}
106#else
107int main(int argc, char **argv)
108{
109    puts("iconv library is disabled, skip name test");
110    exit(0);
111}
112#endif /* #ifdef _ICONV_ENABLED */
113
Note: See TracBrowser for help on using the repository browser.