Update contrib.
2 * Copyright (c) 1997-2007 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
25 #define TELLME "Tell Me The Answer"
30 @SYMTestCaseID SYSLIB-STDLIB-CT-1081
31 @SYMTestCaseDesc Tests for multibyte to wide character conversions
33 @SYMTestActions Tests for conversions from multibyte to wide character and wide character to multibyte
34 @SYMTestExpectedResults Test must not fail
42 char *pmbc = (char *)malloc(MB_CUR_MAX);
44 wchar_t *pwcnull = NULL;
45 wchar_t *pwc = (wchar_t *)malloc( sizeof( wchar_t ) );
47 char * narrowstring = (char*)malloc(50);
48 wchar_t * pwcstring = (wchar_t *)malloc(sizeof(wchar_t)*50);
50 wchar_t greek[] = {0x03a3, 0x03bf, 0x03bc, 0x03b4, 0x03b5, 0x0345, 0x03a9, 0x0392, 0x0395, 0x03a1, 0};
54 test_Title("Wide/Multibyte character conversions.");
56 test_Next("Convert a NULL wide character to multibyte character");
57 i = wctomb( pmbc, L'\0');
62 test_Next("Convert a wide character to multibyte character:");
67 test_Next("Convert multibyte character back to a wide character");
68 i = mbtowc(pwc, pmbc, 20);
73 test_Next("Attempt to convert when target is NULL");
74 i = mbtowc(pwcnull, pmbc, MB_CUR_MAX);
77 test_Next( "Attempt to convert a NULL pointer to a wide character");
79 i = mbtowc( pwc, pmbc, MB_CUR_MAX );
82 test_Next("Convert narrow string to unicode");
83 strcpy(narrowstring, TELLME);
84 i = mbstowcs(pwcstring, narrowstring, 50);
85 test(i==(int)strlen(TELLME)); //should be same
87 test_Next("Convert unicode string back to UTF8");
88 i = wcstombs(narrowstring, pwcstring, 50);
89 test(i==(int)strlen(TELLME)); //should be same
90 test(strcmp(narrowstring, TELLME) == 0);
92 test_Next("Get length of dest string");
93 i = wcstombs(NULL, pwcstring, 50);
94 // test(i==strlen(TELLME)); //should be same
95 // test(strcmp(narrowstring, TELLME) == 0);
98 test_Next("Convert first 10 wide characters");
99 strcpy(narrowstring,"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
100 i = wcstombs(narrowstring, pwcstring, 10);
102 test(memcmp(narrowstring,TELLME,10)==0);
105 test_Next("Convert greek characters to unicode and back");
106 i = wcstombs(narrowstring, &greek[0], 50);
108 i = mbstowcs(pwcstring, narrowstring, 50);
110 test(0==memcmp(pwcstring, greek, sizeof(greek)));
112 test_Next("onto mblen");
116 test_Next("length of a greek character");
117 i = mblen(narrowstring,6);
120 test_Next("test an empty string");
124 test_Next("test a null pointer");
128 test_Next("test a failure");
129 i = mblen(narrowstring,1);