+
+static void Test_widestrs()
+{
+ wchar_t ws[100];
+ UChar rts[100];
+ int32_t wcap = sizeof(ws) / sizeof(*ws);
+ int32_t wl;
+ int32_t rtcap = sizeof(rts) / sizeof(*rts);
+ int32_t rtl;
+ wchar_t *wcs;
+ UChar *cp;
+ const char *errname;
+ UChar ustr[] = {'h', 'e', 'l', 'l', 'o', 0};
+ int32_t ul = sizeof(ustr)/sizeof(*ustr) -1;
+ char astr[100];
+
+ UErrorCode err;
+
+ err = U_ZERO_ERROR;
+ wcs = u_strToWCS(ws, wcap, &wl, ustr, ul, &err);
+ if (U_FAILURE(err)) {
+ errname = u_errorName(err);
+ log_err("test_widestrs: u_strToWCS error: %s!\n",errname);
+ }
+ if(ul!=wl){
+ log_err("u_strToWCS: ustr = %s, ul = %d, ws = %S, wl = %d!\n", u_austrcpy(astr, ustr), ul, ws, wl);
+ }
+ err = U_ZERO_ERROR;
+ wl = (int32_t)uprv_wcslen(wcs);
+ cp = u_strFromWCS(rts, rtcap, &rtl, wcs, wl, &err);
+ if (U_FAILURE(err)) {
+ errname = u_errorName(err);
+ fprintf(stderr, "test_widestrs: ucnv_wcstombs error: %s!\n",errname);
+ }
+ if(wl != rtl){
+ log_err("u_strFromWCS: wcs = %S, wl = %d,rts = %s, rtl = %d!\n", wcs, wl, u_austrcpy(astr, rts), rtl);
+ }
+}
+
+static void
+Test_WCHART_LongString(){
+ UErrorCode status = U_ZERO_ERROR;
+ const char* testdatapath=loadTestData(&status);
+ UResourceBundle *theBundle = ures_open(testdatapath, "testtypes", &status);
+ int32_t strLen =0;
+ const UChar* str = ures_getStringByKey(theBundle, "testinclude",&strLen,&status);
+ const UChar* uSrc = str;
+ int32_t uSrcLen = strLen;
+ int32_t wDestLen =0, reqLen=0, i=0;
+ int32_t uDestLen =0;
+ wchar_t* wDest = NULL;
+ UChar* uDest = NULL;
+ UBool failed = FALSE;
+
+ if(U_FAILURE(status)){
+ log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status));
+ return;
+ }
+
+ /* pre-flight*/
+ u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&status);
+
+ if(status == U_BUFFER_OVERFLOW_ERROR){
+ status=U_ZERO_ERROR;
+ wDest =(wchar_t*) malloc(sizeof(wchar_t) * (reqLen+1));
+ wDestLen = reqLen+1;
+ u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&status);
+ }
+ uDestLen = 0;
+ /* pre-flight */
+ u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&status);
+
+ if(status == U_BUFFER_OVERFLOW_ERROR){
+ status =U_ZERO_ERROR;
+ uDest = (UChar*) malloc(sizeof(UChar) * (reqLen+1));
+ uDestLen = reqLen + 1;
+ u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&status);
+ }
+
+
+ for(i=0; i< uSrcLen; i++){
+ if(uDest[i] != str[i]){
+ log_verbose("u_str*WCS() failed for null terminated string expected: \\u%04X got: \\u%04X at index: %i \n", src16j[i] ,uDest[i],i);
+ failed =TRUE;
+ }
+ }
+
+ if(U_FAILURE(status)){
+ failed = TRUE;
+ }
+ if(failed){
+ log_err("u_strToWCS() failed \n");
+ }
+ free(wDest);
+ free(uDest);
+ /* close the bundle */
+ ures_close(theBundle);
+
+}
+