custrtrn.c revision b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2
1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/******************************************************************** 2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * COPYRIGHT: 3b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * Copyright (c) 2001-2011, International Business Machines Corporation and 4b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * others. All Rights Reserved. 5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ********************************************************************/ 6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/******************************************************************************** 7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* File custrtrn.C 9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* Modification History: 11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* Name Description 12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* Ram String transformations test 13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru********************************************************************************* 14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/ 15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/****************************************************************************/ 16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <stdlib.h> 19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <stdio.h> 2050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include <string.h> 21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h" 22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ustring.h" 23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ures.h" 24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "ustr_imp.h" 25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cintltst.h" 26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cmemory.h" 27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cstring.h" 28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cwchar.h" 29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) 31b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 32b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid addUCharTransformTest(TestNode** root); 33b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 34b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strToUTF32(void); 35b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strToUTF32_surrogates(void); 36b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strFromUTF32(void); 37b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strFromUTF32_surrogates(void); 38b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_UChar_UTF8_API(void); 39c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic void Test_FromUTF8(void); 40b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_FromUTF8Lenient(void); 41b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_UChar_WCHART_API(void); 42b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_widestrs(void); 43b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_WCHART_LongString(void); 4450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void Test_strToJavaModifiedUTF8(void); 4550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void Test_strFromJavaModifiedUTF8(void); 4650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestNullEmptySource(void); 47b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 48b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 49b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruaddUCharTransformTest(TestNode** root) 50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 51b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru addTest(root, &Test_strToUTF32, "custrtrn/Test_strToUTF32"); 52b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru addTest(root, &Test_strToUTF32_surrogates, "custrtrn/Test_strToUTF32_surrogates"); 53b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru addTest(root, &Test_strFromUTF32, "custrtrn/Test_strFromUTF32"); 54b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru addTest(root, &Test_strFromUTF32_surrogates, "custrtrn/Test_strFromUTF32_surrogates"); 55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &Test_UChar_UTF8_API, "custrtrn/Test_UChar_UTF8_API"); 56c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru addTest(root, &Test_FromUTF8, "custrtrn/Test_FromUTF8"); 57b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &Test_FromUTF8Lenient, "custrtrn/Test_FromUTF8Lenient"); 58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &Test_UChar_WCHART_API, "custrtrn/Test_UChar_WCHART_API"); 59b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &Test_widestrs, "custrtrn/Test_widestrs"); 6027f654740f2a26ad62a5c155af9199af9e69b889claireho#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION 61b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru addTest(root, &Test_WCHART_LongString, "custrtrn/Test_WCHART_LongString"); 6250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif 6350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &Test_strToJavaModifiedUTF8, "custrtrn/Test_strToJavaModifiedUTF8"); 6450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &Test_strFromJavaModifiedUTF8, "custrtrn/Test_strFromJavaModifiedUTF8"); 6550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho addTest(root, &TestNullEmptySource, "custrtrn/TestNullEmptySource"); 66b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 67b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 68b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar32 src32[]={ 69b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00A8, 0x3003, 0x3005, 0x2015, 0xFF5E, 0x2016, 0x2026, 0x2018, 0x000D, 0x000A, 70b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x2019, 0x201C, 0x201D, 0x3014, 0x3015, 0x3008, 0x3009, 0x300A, 0x000D, 0x000A, 71b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x300B, 0x300C, 0x300D, 0x300E, 0x300F, 0x3016, 0x3017, 0x3010, 0x000D, 0x000A, 72b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x3011, 0x00B1, 0x00D7, 0x00F7, 0x2236, 0x2227, 0x7FC1, 0x8956, 0x000D, 0x000A, 73b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x9D2C, 0x9D0E, 0x9EC4, 0x5CA1, 0x6C96, 0x837B, 0x5104, 0x5C4B, 0x000D, 0x000A, 74b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61B6, 0x81C6, 0x6876, 0x7261, 0x4E59, 0x4FFA, 0x5378, 0x57F7, 0x000D, 0x000A, 75b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x57F4, 0x57F9, 0x57FA, 0x57FC, 0x5800, 0x5802, 0x5805, 0x5806, 0x000D, 0x000A, 76b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x580A, 0x581E, 0x6BB5, 0x6BB7, 0x6BBA, 0x6BBC, 0x9CE2, 0x977C, 0x000D, 0x000A, 77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x6BBF, 0x6BC1, 0x6BC5, 0x6BC6, 0x6BCB, 0x6BCD, 0x6BCF, 0x6BD2, 0x000D, 0x000A, 78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x6BD3, 0x6BD4, 0x6BD6, 0x6BD7, 0x6BD8, 0x6BDB, 0x6BEB, 0x6BEC, 0x000D, 0x000A, 79b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x6C05, 0x6C08, 0x6C0F, 0x6C11, 0x6C13, 0x6C23, 0x6C34, 0x0041, 0x000D, 0x000A, 80b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 81b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 82b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 83b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x005B, 0x9792, 0x9CCC, 0x9CCD, 0x9CCE, 0x9CCF, 0x9CD0, 0x9CD3, 0x000D, 0x000A, 84b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x9CD4, 0x9CD5, 0x9CD7, 0x9CD8, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A, 85b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x9785, 0x9791, 0x00BD, 0x0390, 0x0385, 0x0386, 0x0388, 0x0389, 0x000D, 0x000A, 86b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x038E, 0x038F, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x000D, 0x000A, 87b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x038A, 0x038C, 0x039C, 0x000D, 0x000A, 88b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test non-BMP code points */ 89b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0002A699, 90b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0002A69C, 0x0002A69D, 0x0002A69E, 0x0002A69F, 0x0002A6A0, 0x0002A6A5, 0x0002A6A6, 0x0002A6A7, 0x0002A6A8, 0x0002A6AB, 91b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0002A6AC, 0x0002A6AD, 0x0002A6AE, 0x0002A6AF, 0x0002A6B0, 0x0002A6B1, 0x0002A6B3, 0x0002A6B5, 0x0002A6B6, 0x0002A6B7, 92b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0002A6B8, 0x0002A6B9, 0x0002A6BA, 0x0002A6BB, 0x0002A6BC, 0x0002A6BD, 0x0002A6BE, 0x0002A6BF, 0x0002A6C0, 0x0002A6C1, 93b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0002A6C2, 0x0002A6C3, 0x0002A6C4, 0x0002A6C8, 0x0002A6CA, 0x0002A6CB, 0x0002A6CD, 0x0002A6CE, 0x0002A6CF, 0x0002A6D0, 94b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0002A6D1, 0x0002A6D2, 0x0002A6D3, 0x0002A6D4, 0x0002A6D5, 95b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x4DB3, 0x4DB4, 0x4DB5, 0x4E00, 0x4E00, 0x4E01, 0x4E02, 0x4E03, 0x000D, 0x000A, 97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x33E0, 0x33E6, 0x000D, 0x000A, 98b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x4E05, 0x4E07, 0x4E04, 0x4E08, 0x4E08, 0x4E09, 0x4E0A, 0x4E0B, 0x000D, 0x000A, 99b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x4E0C, 0x0021, 0x0022, 0x0023, 0x0024, 0xFF40, 0xFF41, 0xFF42, 0x000D, 0x000A, 100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0x000D, 0x000A,0x0000 101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const UChar src16[] = { 104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00A8, 0x3003, 0x3005, 0x2015, 0xFF5E, 0x2016, 0x2026, 0x2018, 0x000D, 0x000A, 105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x2019, 0x201C, 0x201D, 0x3014, 0x3015, 0x3008, 0x3009, 0x300A, 0x000D, 0x000A, 106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x300B, 0x300C, 0x300D, 0x300E, 0x300F, 0x3016, 0x3017, 0x3010, 0x000D, 0x000A, 107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x3011, 0x00B1, 0x00D7, 0x00F7, 0x2236, 0x2227, 0x7FC1, 0x8956, 0x000D, 0x000A, 108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x9D2C, 0x9D0E, 0x9EC4, 0x5CA1, 0x6C96, 0x837B, 0x5104, 0x5C4B, 0x000D, 0x000A, 109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61B6, 0x81C6, 0x6876, 0x7261, 0x4E59, 0x4FFA, 0x5378, 0x57F7, 0x000D, 0x000A, 110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x57F4, 0x57F9, 0x57FA, 0x57FC, 0x5800, 0x5802, 0x5805, 0x5806, 0x000D, 0x000A, 111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x580A, 0x581E, 0x6BB5, 0x6BB7, 0x6BBA, 0x6BBC, 0x9CE2, 0x977C, 0x000D, 0x000A, 112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x6BBF, 0x6BC1, 0x6BC5, 0x6BC6, 0x6BCB, 0x6BCD, 0x6BCF, 0x6BD2, 0x000D, 0x000A, 113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x6BD3, 0x6BD4, 0x6BD6, 0x6BD7, 0x6BD8, 0x6BDB, 0x6BEB, 0x6BEC, 0x000D, 0x000A, 114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x6C05, 0x6C08, 0x6C0F, 0x6C11, 0x6C13, 0x6C23, 0x6C34, 0x0041, 0x000D, 0x000A, 115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x005B, 0x9792, 0x9CCC, 0x9CCD, 0x9CCE, 0x9CCF, 0x9CD0, 0x9CD3, 0x000D, 0x000A, 119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x9CD4, 0x9CD5, 0x9CD7, 0x9CD8, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A, 120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x9785, 0x9791, 0x00BD, 0x0390, 0x0385, 0x0386, 0x0388, 0x0389, 0x000D, 0x000A, 121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x038E, 0x038F, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x000D, 0x000A, 122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x038A, 0x038C, 0x039C, 0x000D, 0x000A, 123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test non-BMP code points */ 125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDE99, 0xD869, 0xDE9C, 0xD869, 0xDE9D, 0xD869, 0xDE9E, 0xD869, 0xDE9F, 126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDEA0, 0xD869, 0xDEA5, 0xD869, 0xDEA6, 0xD869, 0xDEA7, 0xD869, 0xDEA8, 127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDEAB, 0xD869, 0xDEAC, 0xD869, 0xDEAD, 0xD869, 0xDEAE, 0xD869, 0xDEAF, 128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDEB0, 0xD869, 0xDEB1, 0xD869, 0xDEB3, 0xD869, 0xDEB5, 0xD869, 0xDEB6, 129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDEB7, 0xD869, 0xDEB8, 0xD869, 0xDEB9, 0xD869, 0xDEBA, 0xD869, 0xDEBB, 130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDEBC, 0xD869, 0xDEBD, 0xD869, 0xDEBE, 0xD869, 0xDEBF, 0xD869, 0xDEC0, 131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDEC1, 0xD869, 0xDEC2, 0xD869, 0xDEC3, 0xD869, 0xDEC4, 0xD869, 0xDEC8, 132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDECA, 0xD869, 0xDECB, 0xD869, 0xDECD, 0xD869, 0xDECE, 0xD869, 0xDECF, 133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDED0, 0xD869, 0xDED1, 0xD869, 0xDED2, 0xD869, 0xDED3, 0xD869, 0xDED4, 134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xD869, 0xDED5, 135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x4DB3, 0x4DB4, 0x4DB5, 0x4E00, 0x4E00, 0x4E01, 0x4E02, 0x4E03, 0x000D, 0x000A, 137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x33E0, 0x33E6, 0x000D, 0x000A, 138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x4E05, 0x4E07, 0x4E04, 0x4E08, 0x4E08, 0x4E09, 0x4E0A, 0x4E0B, 0x000D, 0x000A, 139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x4E0C, 0x0021, 0x0022, 0x0023, 0x0024, 0xFF40, 0xFF41, 0xFF42, 0x000D, 0x000A, 140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0x000D, 0x000A,0x0000 141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 144b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strToUTF32(void){ 145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 146b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar32 u32Target[400]; 147b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t u32DestLen; 148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int i= 0; 149b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 150b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* first with length */ 151b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u32DestLen = -2; 152b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, 0, &u32DestLen, src16, LENGTHOF(src16),&err); 153b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != LENGTHOF(src32)) { 154b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(preflight with length): " 155b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", 156b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)u32DestLen, (long)LENGTHOF(src32), u_errorName(err)); 157b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 158b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 159b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 160b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u32DestLen = -2; 161b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, LENGTHOF(src32)+1, &u32DestLen, src16, LENGTHOF(src16),&err); 162b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || u32DestLen != LENGTHOF(src32)) { 163b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(with length): " 164b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_ZERO_ERROR\n", 165b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)u32DestLen, (long)LENGTHOF(src32), u_errorName(err)); 166b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 167b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 168b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /*for(i=0; i< u32DestLen; i++){ 169b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru printf("0x%08X, ",uTarget[i]); 170b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(i%10==0){ 171b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru printf("\n"); 172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 173b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }*/ 174b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0; i< LENGTHOF(src32); i++){ 175b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(u32Target[i] != src32[i]){ 176b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strToUTF32(with length) failed expected: %04X got: %04X at index: %i \n", src32[i], u32Target[i],i); 177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 178b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 179b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(u32Target[i] != 0){ 180b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strToUTF32(with length) failed expected: %04X got: %04X at index: %i \n", 0, u32Target[i],i); 181b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 182b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 183b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* now NUL-terminated */ 184b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u32DestLen = -2; 185b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(NULL,0, &u32DestLen, src16, -1,&err); 186b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != LENGTHOF(src32)-1) { 187b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(preflight with NUL-termination): " 188b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", 189b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)u32DestLen, (long)LENGTHOF(src32)-1, u_errorName(err)); 190b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 191b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 192b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 193b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u32DestLen = -2; 194b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, LENGTHOF(src32), &u32DestLen, src16, -1,&err); 195b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || u32DestLen != LENGTHOF(src32)-1) { 196b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(with NUL-termination): " 197b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_ZERO_ERROR\n", 198b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)u32DestLen, (long)LENGTHOF(src32)-1, u_errorName(err)); 199b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 200b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 201b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 202b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0; i< LENGTHOF(src32); i++){ 203b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(u32Target[i] != src32[i]){ 204b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strToUTF32(NUL-termination) failed expected: %04X got: %04X \n", src32[i], u32Target[i]); 205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 206b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 207b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 209b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* test unpaired surrogates */ 210b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strToUTF32_surrogates() { 211b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 212b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar32 u32Target[400]; 213b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t len16, u32DestLen; 214b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t numSubstitutions; 215b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int i; 216b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 217b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar surr16[] = { 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; 218b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar32 expected[] = { 0x5a, 0x50000, 0x7a, 0 }; 219b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar32 expected_FFFD[] = { 0x41, 0xfffd, 0x61, 0xfffd, 0x5a, 0x50000, 0x7a, 0 }; 220b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar32 expected_12345[] = { 0x41, 0x12345, 0x61, 0x12345, 0x5a, 0x50000, 0x7a, 0 }; 221b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru len16 = LENGTHOF(surr16); 222b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i = 0; i < 4; ++i) { 223b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 224b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, 0, &u32DestLen, surr16+i, len16-i, &err); 225b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 226b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(preflight surr16+%ld) sets %s != U_INVALID_CHAR_FOUND\n", 227b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 228b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 229b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 231b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 232b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+i, len16-i, &err); 233b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 234b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(surr16+%ld) sets %s != U_INVALID_CHAR_FOUND\n", 235b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 236b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 238b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 239b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 240b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(NULL, 0, &u32DestLen, surr16+i, -1, &err); 241b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 242b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(preflight surr16+%ld/NUL) sets %s != U_INVALID_CHAR_FOUND\n", 243b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 244b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 246b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 247b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 248b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+i, -1, &err); 249b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 250b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(surr16+%ld/NUL) sets %s != U_INVALID_CHAR_FOUND\n", 251b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 252b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 254b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 256b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 257b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, 0, &u32DestLen, surr16+4, len16-4-1, &err); 258b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 3) { 259b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(preflight surr16+4) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 260b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 261b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 264b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 265b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+4, len16-4-1, &err); 266b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || u32DestLen != 3 || uprv_memcmp(u32Target, expected, 4*4)) { 267b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(surr16+4) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 268b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 269b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 270b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 271b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 272b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 273b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(NULL, 0, &u32DestLen, surr16+4, -1, &err); 274b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 3) { 275b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(preflight surr16+4/NUL) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 276b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 277b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 278b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 279b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 280b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 281b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16+4, -1, &err); 282b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || u32DestLen != 3 || uprv_memcmp(u32Target, expected, 4*4)) { 283b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32(surr16+4/NUL) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 284b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 285b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 286b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 287b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 288b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* with substitution character */ 289b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru numSubstitutions = -1; 290b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 291b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32WithSub(u32Target, 0, &u32DestLen, surr16, len16-1, 0xfffd, &numSubstitutions, &err); 292b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 7 || numSubstitutions != 2) { 293b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32WithSub(preflight surr16) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 294b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 295b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 296b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 297b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 298b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 299b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32WithSub(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16, len16-1, 0xfffd, &numSubstitutions, &err); 300b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || u32DestLen != 7 || numSubstitutions != 2 || uprv_memcmp(u32Target, expected_FFFD, 8*4)) { 301b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32WithSub(surr16) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 302b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 303b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 304b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 305b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 306b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 307b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32WithSub(NULL, 0, &u32DestLen, surr16, -1, 0x12345, &numSubstitutions, &err); 308b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || u32DestLen != 7 || numSubstitutions != 2) { 309b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32WithSub(preflight surr16/NUL) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 310b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 311b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 312b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 313b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 314b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 315b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strToUTF32WithSub(u32Target, LENGTHOF(u32Target), &u32DestLen, surr16, -1, 0x12345, &numSubstitutions, &err); 316b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || u32DestLen != 7 || numSubstitutions != 2 || uprv_memcmp(u32Target, expected_12345, 8*4)) { 317b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strToUTF32WithSub(surr16/NUL) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 318b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 319b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 320b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 321b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 322b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 323b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strFromUTF32(void){ 324b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 325b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar uTarget[400]; 326b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t uDestLen; 327b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int i= 0; 328b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 329b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* first with length */ 330b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uDestLen = -2; 331b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget,0,&uDestLen,src32,LENGTHOF(src32),&err); 332b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != LENGTHOF(src16)) { 333b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(preflight with length): " 334b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", 335b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)uDestLen, (long)LENGTHOF(src16), u_errorName(err)); 336b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 337b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 338b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 339b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uDestLen = -2; 340b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, LENGTHOF(src16)+1,&uDestLen,src32,LENGTHOF(src32),&err); 341b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || uDestLen != LENGTHOF(src16)) { 342b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(with length): " 343b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_ZERO_ERROR\n", 344b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)uDestLen, (long)LENGTHOF(src16), u_errorName(err)); 345b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 346b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 347b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /*for(i=0; i< uDestLen; i++){ 348b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru printf("0x%04X, ",uTarget[i]); 349b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(i%10==0){ 350b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru printf("\n"); 351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 352b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru }*/ 353b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 354b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0; i< uDestLen; i++){ 355b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(uTarget[i] != src16[i]){ 356b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strFromUTF32(with length) failed expected: %04X got: %04X at index: %i \n", src16[i] ,uTarget[i],i); 357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 358b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 359b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(uTarget[i] != 0){ 360b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strFromUTF32(with length) failed expected: %04X got: %04X at index: %i \n", 0,uTarget[i],i); 361b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 363b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* now NUL-terminated */ 364b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uDestLen = -2; 365b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(NULL,0,&uDestLen,src32,-1,&err); 366b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != LENGTHOF(src16)-1) { 367b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(preflight with NUL-termination): " 368b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_BUFFER_OVERFLOW_ERROR\n", 369b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)uDestLen, (long)LENGTHOF(src16)-1, u_errorName(err)); 370b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 371b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 372b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 373b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru uDestLen = -2; 374b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, LENGTHOF(src16),&uDestLen,src32,-1,&err); 375b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || uDestLen != LENGTHOF(src16)-1) { 376b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(with NUL-termination): " 377b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "length %ld != %ld and %s != U_ZERO_ERROR\n", 378b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)uDestLen, (long)LENGTHOF(src16)-1, u_errorName(err)); 379b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 380b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 381b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 382b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0; i< uDestLen; i++){ 383b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(uTarget[i] != src16[i]){ 384b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strFromUTF32(with NUL-termination) failed expected: %04X got: %04X \n", src16[i] ,uTarget[i]); 385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 386b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 387b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 389b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* test surrogate code points */ 390b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Querustatic void Test_strFromUTF32_surrogates() { 391b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 392b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UChar uTarget[400]; 393b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t len32, uDestLen; 394b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int32_t numSubstitutions; 395b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru int i; 396b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 397b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar32 surr32[] = { 0x41, 0xd900, 0x61, 0xdc00, -1, 0x110000, 0x5a, 0x50000, 0x7a, 0 }; 398b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar expected[] = { 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; 399b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar expected_FFFD[] = { 0x41, 0xfffd, 0x61, 0xfffd, 0xfffd, 0xfffd, 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; 400b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru static const UChar expected_12345[] = { 0x41, 0xd808, 0xdf45, 0x61, 0xd808, 0xdf45, 0xd808, 0xdf45, 0xd808, 0xdf45, 401b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 0x5a, 0xd900, 0xdc00, 0x7a, 0 }; 402b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru len32 = LENGTHOF(surr32); 403b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i = 0; i < 6; ++i) { 404b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 405b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, 0, &uDestLen, surr32+i, len32-i, &err); 406b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 407b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(preflight surr32+%ld) sets %s != U_INVALID_CHAR_FOUND\n", 408b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 409b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 410b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 412b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 413b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+i, len32-i, &err); 414b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 415b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(surr32+%ld) sets %s != U_INVALID_CHAR_FOUND\n", 416b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 417b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 419b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 420b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 421b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(NULL, 0, &uDestLen, surr32+i, -1, &err); 422b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 423b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(preflight surr32+%ld/NUL) sets %s != U_INVALID_CHAR_FOUND\n", 424b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 425b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 427b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 428b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 429b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+i, -1, &err); 430b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_INVALID_CHAR_FOUND) { 431b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(surr32+%ld/NUL) sets %s != U_INVALID_CHAR_FOUND\n", 432b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (long)i, u_errorName(err)); 433b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 435b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 437b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 438b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, 0, &uDestLen, surr32+6, len32-6-1, &err); 439b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 4) { 440b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(preflight surr32+6) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 441b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 442b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 443b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 444b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 445b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 446b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+6, len32-6-1, &err); 447b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || uDestLen != 4 || u_memcmp(uTarget, expected, 5)) { 448b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(surr32+6) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 449b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 450b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 451b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 452b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 453b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 454b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(NULL, 0, &uDestLen, surr32+6, -1, &err); 455b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 4) { 456b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(preflight surr32+6/NUL) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 457b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 458b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 459b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 460b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 461b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 462b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32(uTarget, LENGTHOF(uTarget), &uDestLen, surr32+6, -1, &err); 463b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || uDestLen != 4 || u_memcmp(uTarget, expected, 5)) { 464b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32(surr32+6/NUL) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 465b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 466b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 467b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 468b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 469b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru /* with substitution character */ 470b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru numSubstitutions = -1; 471b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 472b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32WithSub(uTarget, 0, &uDestLen, surr32, len32-1, 0xfffd, &numSubstitutions, &err); 473b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 10 || numSubstitutions != 4) { 474b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32WithSub(preflight surr32) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 475b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 476b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 479b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 480b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32WithSub(uTarget, LENGTHOF(uTarget), &uDestLen, surr32, len32-1, 0xfffd, &numSubstitutions, &err); 481b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || uDestLen != 10 || numSubstitutions != 4 || u_memcmp(uTarget, expected_FFFD, 11)) { 482b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32WithSub(surr32) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 483b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 484b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 485b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 486b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 487b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 488b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32WithSub(NULL, 0, &uDestLen, surr32, -1, 0x12345, &numSubstitutions, &err); 489b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_BUFFER_OVERFLOW_ERROR || uDestLen != 14 || numSubstitutions != 4) { 490b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32WithSub(preflight surr32/NUL) sets %s != U_BUFFER_OVERFLOW_ERROR or an unexpected length\n", 491b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 492b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 493b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 494b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 495b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru err = U_ZERO_ERROR; 496b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_strFromUTF32WithSub(uTarget, LENGTHOF(uTarget), &uDestLen, surr32, -1, 0x12345, &numSubstitutions, &err); 497b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(err != U_ZERO_ERROR || uDestLen != 14 || numSubstitutions != 4 || u_memcmp(uTarget, expected_12345, 15)) { 498b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_err("u_strFromUTF32WithSub(surr32/NUL) sets %s != U_ZERO_ERROR or does not produce the expected string\n", 499b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru u_errorName(err)); 500b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru return; 501b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 502b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru} 503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_UChar_UTF8_API(void){ 505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar uTemp[1]; 508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru char u8Temp[1]; 509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar* uTarget=uTemp; 510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* u8Src; 511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t u8SrcLen = 0; 512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uTargetLength = 0; 513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uDestLen=0; 514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar* uSrc = src16; 515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uSrcLen = sizeof(src16)/2; 516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru char* u8Target = u8Temp; 517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t u8TargetLength =0; 518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t u8DestLen =0; 519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool failed = FALSE; 520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int i= 0; 521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t numSubstitutions; 522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflight */ 525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8Temp[0] = 0x12; 526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8(u8Target,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err); 527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR && u8Temp[0] == 0x12){ 528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8Target = (char*) malloc (sizeof(uint8_t) * (u8DestLen+1)); 530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8TargetLength = u8DestLen; 531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8Target[u8TargetLength] = (char)0xfe; 533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8DestLen = -1; 534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8(u8Target,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err); 535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || u8DestLen != u8TargetLength || u8Target[u8TargetLength] != (char)0xfe){ 536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToUTF8 failed after preflight. Error: %s\n", u_errorName(err)); 537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else { 542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR"); 543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = FALSE; 545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*for(i=0; i< u8DestLen; i++){ 546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("0x%04X, ",u8Target[i]); 547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(i%10==0){ 548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("\n"); 549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }*/ 551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*for(i=0; i< u8DestLen; i++){ 552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(u8Target[i] != src8[i]){ 553b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strToUTF8() failed expected: %04X got: %04X \n", src8[i], u8Target[i]); 554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToUTF8() failed \n"); 559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }*/ 560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8Src = u8Target; 561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8SrcLen = u8DestLen; 562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflight */ 564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTemp[0] = 0x1234; 565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8(uTarget,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err); 566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR && uTemp[0] == 0x1234){ 567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTarget = (UChar*) malloc( sizeof(UChar) * (uDestLen+1)); 569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTargetLength = uDestLen; 570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTarget[uTargetLength] = 0xfff0; 572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = -1; 573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8(uTarget,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err); 574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 575b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else { 576b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8(preflight) should have gotten U_BUFFER_OVERFLOW_ERROR\n"); 577b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 578b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*for(i=0; i< uDestLen; i++){ 579b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("0x%04X, ",uTarget[i]); 580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(i%10==0){ 581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("\n"); 582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }*/ 584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || uDestLen != uTargetLength || uTarget[uTargetLength] != 0xfff0) { 586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = TRUE; 587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 588b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i< uSrcLen; i++){ 589b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(uTarget[i] != src16[i]){ 590b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_verbose("u_strFromUTF8() failed expected: \\u%04X got: \\u%04X at index: %i \n", src16[i] ,uTarget[i],i); 591b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 592b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 593b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 594b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 595b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8(after preflighting) failed\n"); 596b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 597b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(u8Target); 599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(uTarget); 600b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 601b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 602b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8SrcLen = -1; 603b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTargetLength = 0; 604b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uSrcLen =-1; 605b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8TargetLength=0; 606b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = FALSE; 607b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflight */ 608b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8(NULL,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err); 609b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 610b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 611b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8Target = (char*) malloc (sizeof(uint8_t) * (u8DestLen+1)); 612b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8TargetLength = u8DestLen; 613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8(u8Target,u8TargetLength, &u8DestLen, uSrc, uSrcLen,&err); 615b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 616b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 617b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else { 618b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR"); 619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = FALSE; 621b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*for(i=0; i< u8DestLen; i++){ 622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("0x%04X, ",u8Target[i]); 623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(i%10==0){ 624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("\n"); 625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }*/ 627b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*for(i=0; i< u8DestLen; i++){ 628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(u8Target[i] != src8[i]){ 629b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru log_verbose("u_strToUTF8() failed expected: %04X got: %04X \n", src8[i], u8Target[i]); 630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToUTF8() failed \n"); 635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }*/ 636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8Src = u8Target; 637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8SrcLen = u8DestLen; 638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflight */ 640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8(NULL,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err); 641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTarget = (UChar*) malloc( sizeof(UChar) * (uDestLen+1)); 644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uTargetLength = uDestLen; 645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8(uTarget,uTargetLength,&uDestLen,u8Src,u8SrcLen,&err); 647b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else { 649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("Should have gotten U_BUFFER_OVERFLOW_ERROR"); 650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /*for(i=0; i< uDestLen; i++){ 652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("0x%04X, ",uTarget[i]); 653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(i%10==0){ 654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru printf("\n"); 655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }*/ 657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i< uSrcLen; i++){ 659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(uTarget[i] != src16[i]){ 660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_verbose("u_strFromUTF8() failed expected: \\u%04X got: \\u%04X at index: %i \n", src16[i] ,uTarget[i],i); 661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToUTF8() failed \n"); 666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(u8Target); 669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(uTarget); 670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 671b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test UTF-8 with single surrogates - illegal in Unicode 3.2 */ 673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru static const UChar 675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withLead16[]={ 0x1800, 0xd89a, 0x0061 }, 676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16[]={ 0x1800, 0xdcba, 0x0061, 0 }, 677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16SubFFFD[]={ 0x1800, 0xfffd, 0x0061, 0 }, /* sub==U+FFFD */ 678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16Sub50005[]={ 0x1800, 0xd900, 0xdc05, 0x0061, 0 }; /* sub==U+50005 */ 679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru static const uint8_t 680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withLead8[]={ 0xe1, 0xa0, 0x80, 0xed, 0xa2, 0x9a, 0x61 }, 681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail8[]={ 0xe1, 0xa0, 0x80, 0xed, 0xb2, 0xba, 0x61, 0 }, 682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail8Sub1A[]={ 0xe1, 0xa0, 0x80, 0x1a, 0x61, 0 }, /* sub==U+001A */ 683b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail8SubFFFD[]={ 0xe1, 0xa0, 0x80, 0xef, 0xbf, 0xbd, 0x61, 0 }; /* sub==U+FFFD */ 684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar out16[10]; 685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru char out8[10]; 686b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if( 688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (err=U_ZERO_ERROR, u_strToUTF8(out8, LENGTHOF(out8), NULL, withLead16, LENGTHOF(withLead16), &err), err!=U_INVALID_CHAR_FOUND) || 689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (err=U_ZERO_ERROR, u_strToUTF8(out8, LENGTHOF(out8), NULL, withTrail16, -1, &err), err!=U_INVALID_CHAR_FOUND) || 690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (err=U_ZERO_ERROR, u_strFromUTF8(out16, LENGTHOF(out16), NULL, (const char *)withLead8, LENGTHOF(withLead8), &err), err!=U_INVALID_CHAR_FOUND) || 691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (err=U_ZERO_ERROR, u_strFromUTF8(out16, LENGTHOF(out16), NULL, (const char *)withTrail8, -1, &err), err!=U_INVALID_CHAR_FOUND) 692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strTo/FromUTF8(string with single surrogate) fails to report error\n"); 694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 695b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 696b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test error handling with substitution characters */ 697b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 698b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* from UTF-8 with length */ 699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out16[0]=0x55aa; 702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen=0; 703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, 704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (const char *)withTrail8, uprv_strlen((const char *)withTrail8), 705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x50005, &numSubstitutions, 706b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 707b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || uDestLen!=u_strlen(withTrail16Sub50005) || 708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen+1) || 709b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=1) { 710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8WithSub(length) failed\n"); 711b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 712b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 713b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* from UTF-8 with NUL termination */ 714b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 715b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 716b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out16[0]=0x55aa; 717b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen=0; 718b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, 719b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (const char *)withTrail8, -1, 720b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, &numSubstitutions, 721b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 722b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || uDestLen!=u_strlen(withTrail16SubFFFD) || 723b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=u_memcmp(withTrail16SubFFFD, out16, uDestLen+1) || 724b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=1) { 725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8WithSub(NUL termination) failed\n"); 726b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 727b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 728b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflight from UTF-8 with NUL termination */ 729b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 730b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 731b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out16[0]=0x55aa; 732b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen=0; 733b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8WithSub(out16, 1, &uDestLen, 734b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (const char *)withTrail8, -1, 735b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x50005, &numSubstitutions, 736b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 737b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err!=U_BUFFER_OVERFLOW_ERROR || uDestLen!=u_strlen(withTrail16Sub50005) || numSubstitutions!=1) { 738b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8WithSub(preflight/NUL termination) failed\n"); 739b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 740b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 741b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* to UTF-8 with length */ 742b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 743b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 744b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out8[0]=(char)0xf5; 745b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8DestLen=0; 746b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, 747b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16, u_strlen(withTrail16), 748b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, &numSubstitutions, 749b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 750b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || u8DestLen!=uprv_strlen((const char *)withTrail8SubFFFD) || 751b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out8, u8DestLen+1) || 752b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=1) { 753b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strToUTF8WithSub(length) failed\n"); 754b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 755b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 756b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* to UTF-8 with NUL termination */ 757b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 758b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out8[0]=(char)0xf5; 760b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8DestLen=0; 761b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, 762b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16, -1, 763b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x1a, &numSubstitutions, 764b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || u8DestLen!=uprv_strlen((const char *)withTrail8Sub1A) || 766b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=uprv_memcmp((const char *)withTrail8Sub1A, out8, u8DestLen+1) || 767b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=1) { 768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strToUTF8WithSub(NUL termination) failed\n"); 769b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 770b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflight to UTF-8 with NUL termination */ 772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out8[0]=(char)0xf5; 775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8DestLen=0; 776b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8WithSub(out8, 1, &u8DestLen, 777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16, -1, 778b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, &numSubstitutions, 779b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err!=U_BUFFER_OVERFLOW_ERROR || u8DestLen!=uprv_strlen((const char *)withTrail8SubFFFD) || 781b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=1) { 782b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strToUTF8WithSub(preflight/NUL termination) failed\n"); 783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test that numSubstitutions==0 if there are no substitutions */ 786b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 787b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* from UTF-8 with length (just first 3 bytes which are valid) */ 788b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out16[0]=0x55aa; 791b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen=0; 792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, 793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (const char *)withTrail8, 3, 794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x50005, &numSubstitutions, 795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 796b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || uDestLen!=1 || 797b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen) || 798b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=0) { 799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8WithSub(no subs) failed\n"); 800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* to UTF-8 with length (just first UChar which is valid) */ 803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out8[0]=(char)0xf5; 806b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8DestLen=0; 807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, 808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16, 1, 809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, &numSubstitutions, 810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || u8DestLen!=3 || 812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out8, u8DestLen) || 813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=0) { 814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strToUTF8WithSub(no subs) failed\n"); 815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test that numSubstitutions==0 if subchar==U_SENTINEL (no subchar) */ 818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* from UTF-8 with length (just first 3 bytes which are valid) */ 820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out16[0]=0x55aa; 823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen=0; 824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromUTF8WithSub(out16, LENGTHOF(out16), &uDestLen, 825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (const char *)withTrail8, 3, 826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru U_SENTINEL, &numSubstitutions, 827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || uDestLen!=1 || 829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=u_memcmp(withTrail16Sub50005, out16, uDestLen) || 830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=0) { 831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strFromUTF8WithSub(no subchar) failed\n"); 832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* to UTF-8 with length (just first UChar which is valid) */ 835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 836b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions=-1; 837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru out8[0]=(char)0xf5; 838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u8DestLen=0; 839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToUTF8WithSub(out8, LENGTHOF(out8), &u8DestLen, 840b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru withTrail16, 1, 841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru U_SENTINEL, &numSubstitutions, 842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru &err); 843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err) || u8DestLen!=3 || 844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0!=uprv_memcmp((const char *)withTrail8SubFFFD, out8, u8DestLen) || 845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numSubstitutions!=0) { 846b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("error: u_strToUTF8WithSub(no subchar) failed\n"); 847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 851b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* compare if two strings are equal, but match 0xfffd in the second string with anything in the first */ 852b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic UBool 853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruequalAnyFFFD(const UChar *s, const UChar *t, int32_t length) { 854b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar c1, c2; 855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while(length>0) { 857b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru c1=*s++; 858b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru c2=*t++; 859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(c1!=c2 && c2!=0xfffd) { 860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return FALSE; 861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru --length; 863b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 864b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return TRUE; 865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* test u_strFromUTF8Lenient() */ 868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void 869c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste QueruTest_FromUTF8(void) { 870c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 871c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Test case from icu-support list 20071130 "u_strFromUTF8() returns U_INVALID_CHAR_FOUND(10)" 872c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 873c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru static const uint8_t bytes[]={ 0xe0, 0xa5, 0x9c, 0 }; 874c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UChar dest[64]; 875c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UChar *destPointer; 876c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru int32_t destLength; 877c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UErrorCode errorCode; 878c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 879c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 3 bytes input, one UChar output (U+095C) */ 880c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 881c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destLength=-99; 882c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destPointer=u_strFromUTF8(NULL, 0, &destLength, (const char *)bytes, 3, &errorCode); 883c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if(errorCode!=U_BUFFER_OVERFLOW_ERROR || destPointer!=NULL || destLength!=1) { 884c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru log_err("error: u_strFromUTF8(preflight srcLength=3) fails: destLength=%ld - %s\n", 885c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru (long)destLength, u_errorName(errorCode)); 886c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 887c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 888c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 4 bytes input, two UChars output (U+095C U+0000) */ 889c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 890c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destLength=-99; 891c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destPointer=u_strFromUTF8(NULL, 0, &destLength, (const char *)bytes, 4, &errorCode); 892c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if(errorCode!=U_BUFFER_OVERFLOW_ERROR || destPointer!=NULL || destLength!=2) { 893c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru log_err("error: u_strFromUTF8(preflight srcLength=4) fails: destLength=%ld - %s\n", 894c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru (long)destLength, u_errorName(errorCode)); 895c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 896c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 897c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* NUL-terminated 3 bytes input, one UChar output (U+095C) */ 898c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 899c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destLength=-99; 900c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destPointer=u_strFromUTF8(NULL, 0, &destLength, (const char *)bytes, -1, &errorCode); 901c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if(errorCode!=U_BUFFER_OVERFLOW_ERROR || destPointer!=NULL || destLength!=1) { 902c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru log_err("error: u_strFromUTF8(preflight srcLength=-1) fails: destLength=%ld - %s\n", 903c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru (long)destLength, u_errorName(errorCode)); 904c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 905c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 906c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru /* 3 bytes input, one UChar output (U+095C), transform not just preflight */ 907c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 908c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru dest[0]=dest[1]=99; 909c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destLength=-99; 910c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru destPointer=u_strFromUTF8(dest, LENGTHOF(dest), &destLength, (const char *)bytes, 3, &errorCode); 911c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if(U_FAILURE(errorCode) || destPointer!=dest || destLength!=1 || dest[0]!=0x95c || dest[1]!=0) { 912c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru log_err("error: u_strFromUTF8(transform srcLength=3) fails: destLength=%ld - %s\n", 913c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru (long)destLength, u_errorName(errorCode)); 914c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 915c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru} 916c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 917c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru/* test u_strFromUTF8Lenient() */ 918c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic void 919b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTest_FromUTF8Lenient(void) { 920b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 921b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Multiple input strings, each NUL-terminated. 922b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Terminate with a string starting with 0xff. 923b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 924b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru static const uint8_t bytes[]={ 925b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* well-formed UTF-8 */ 926b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61, 0xc3, 0x9f, 0xe0, 0xa0, 0x80, 0xf0, 0xa0, 0x80, 0x80, 927b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x62, 0xc3, 0xa0, 0xe0, 0xa0, 0x81, 0xf0, 0xa0, 0x80, 0x81, 0, 928b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 929b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* various malformed sequences */ 930b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xc3, 0xc3, 0x9f, 0xc3, 0xa0, 0xe0, 0x80, 0x8a, 0xf0, 0x41, 0x42, 0x43, 0, 931b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 932b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* truncated input */ 933b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xc3, 0, 934b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xe0, 0, 935b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xe0, 0xa0, 0, 936b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xf0, 0, 937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xf0, 0x90, 0, 938b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xf0, 0x90, 0x80, 0, 939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* non-ASCII characters in the last few bytes */ 941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61, 0xc3, 0x9f, 0xe0, 0xa0, 0x80, 0, 942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61, 0xe0, 0xa0, 0x80, 0xc3, 0x9f, 0, 943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* empty string */ 945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 946b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 947b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* finish */ 948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xff, 0 949b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 950b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 951b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Multiple output strings, each NUL-terminated. 0xfffd matches anything. */ 952b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru static const UChar uchars[]={ 953b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61, 0xdf, 0x800, 0xd840, 0xdc00, 954b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x62, 0xe0, 0x801, 0xd840, 0xdc01, 0, 955b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 956b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0x9f, 0xe0, 0xa, 0xfffd, 0xfffd, 0, 957b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 958b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0, 959b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0, 960b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0, 961b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0, 962b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0, 963b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0xfffd, 0, 964b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 965b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61, 0xdf, 0x800, 0, 966b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x61, 0x800, 0xdf, 0, 967b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 968b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, 969b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 970b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0 971b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 972b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 973b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar dest[64]; 974b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *pb; 975b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar *pu, *pDest; 976b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t srcLength, destLength0, destLength; 977b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int number; 978b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode errorCode; 979b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 980b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* verify checking for some illegal arguments */ 981b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=0x1234; 982b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 983b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 984b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, 1, &destLength, NULL, -1, &errorCode); 985b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0x1234) { 986b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(src=NULL) failed\n"); 987b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 988b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 989b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=0x1234; 990b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 991b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 992b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(NULL, 1, &destLength, (const char *)bytes, -1, &errorCode); 993b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) { 994b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(dest=NULL[1]) failed\n"); 995b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 996b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 997b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=0x1234; 998b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 999b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_MEMORY_ALLOCATION_ERROR; 1000b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, 1, &destLength, (const char *)bytes, -1, &errorCode); 1001b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(errorCode!=U_MEMORY_ALLOCATION_ERROR || dest[0]!=0x1234) { 1002b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(U_MEMORY_ALLOCATION_ERROR) failed\n"); 1003b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1004b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1005b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=0x1234; 1006b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1007b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_MEMORY_ALLOCATION_ERROR; 1008b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, 1, &destLength, (const char *)bytes, -1, NULL); 1009b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(dest[0]!=0x1234) { 1010b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(pErrorCode=NULL) failed\n"); 1011b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1012b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test normal behavior */ 1014b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru number=0; /* string number for log_err() */ 1015b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1016b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(pb=(const char *)bytes, pu=uchars; 1017b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *pb!=(char)0xff; 1018b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pb+=srcLength+1, pu+=destLength0+1, ++number 1019b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1020b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru srcLength=uprv_strlen(pb); 1021b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength0=u_strlen(pu); 1022b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1023b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflighting with NUL-termination */ 1024b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=0x1234; 1025b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1026b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1027b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(NULL, 0, &destLength, pb, -1, &errorCode); 1028b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!= (destLength0==0 ? U_STRING_NOT_TERMINATED_WARNING : U_BUFFER_OVERFLOW_ERROR) || 1029b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=NULL || dest[0]!=0x1234 || destLength!=destLength0 1030b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1031b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d preflighting with NUL-termination) failed\n", number); 1032b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1033b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1034b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflighting/some capacity with NUL-termination */ 1035b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(srcLength>0) { 1036b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[destLength0-1]=0x1234; 1037b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1038b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1039b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, destLength0-1, &destLength, pb, -1, &errorCode); 1040b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_BUFFER_OVERFLOW_ERROR || 1041b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[destLength0-1]!=0x1234 || destLength!=destLength0 1042b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1043b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d preflighting/some capacity with NUL-termination) failed\n", number); 1044b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1045b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1046b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1047b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* conversion with NUL-termination, much capacity */ 1048b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=dest[destLength0]=0x1234; 1049b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1050b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1051b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, LENGTHOF(dest), &destLength, pb, -1, &errorCode); 1052b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_ZERO_ERROR || 1053b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=dest || dest[destLength0]!=0 || 1054b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) 1055b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1056b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d conversion with NUL-termination, much capacity) failed\n", number); 1057b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1058b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1059b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* conversion with NUL-termination, exact capacity */ 1060b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=dest[destLength0]=0x1234; 1061b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1062b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1063b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, destLength0, &destLength, pb, -1, &errorCode); 1064b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_STRING_NOT_TERMINATED_WARNING || 1065b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=dest || dest[destLength0]!=0x1234 || 1066b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) 1067b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1068b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d conversion with NUL-termination, exact capacity) failed\n", number); 1069b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1070b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1071b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflighting with length */ 1072b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=0x1234; 1073b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1074b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1075b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(NULL, 0, &destLength, pb, srcLength, &errorCode); 1076b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!= (destLength0==0 ? U_STRING_NOT_TERMINATED_WARNING : U_BUFFER_OVERFLOW_ERROR) || 1077b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=NULL || dest[0]!=0x1234 || destLength!=srcLength 1078b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1079b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d preflighting with length) failed\n", number); 1080b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1081b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1082b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* preflighting/some capacity with length */ 1083b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(srcLength>0) { 1084b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[srcLength-1]=0x1234; 1085b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1086b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1087b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, srcLength-1, &destLength, pb, srcLength, &errorCode); 1088b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_BUFFER_OVERFLOW_ERROR || 1089b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[srcLength-1]!=0x1234 || destLength!=srcLength 1090b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1091b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d preflighting/some capacity with length) failed\n", number); 1092b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1093b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1094b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1095b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* conversion with length, much capacity */ 1096b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=dest[destLength0]=0x1234; 1097b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1098b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1099b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, LENGTHOF(dest), &destLength, pb, srcLength, &errorCode); 1100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_ZERO_ERROR || 1101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=dest || dest[destLength0]!=0 || 1102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) 1103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d conversion with length, much capacity) failed\n", number); 1105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* conversion with length, srcLength capacity */ 1108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dest[0]=dest[srcLength]=dest[destLength0]=0x1234; 1109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength=-1; 1110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errorCode=U_ZERO_ERROR; 1111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest=u_strFromUTF8Lenient(dest, srcLength, &destLength, pb, srcLength, &errorCode); 1112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(srcLength==destLength0) { 1113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_STRING_NOT_TERMINATED_WARNING || 1114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=dest || dest[destLength0]!=0x1234 || 1115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) 1116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d conversion with length, srcLength capacity/not terminated) failed\n", number); 1118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (errorCode!=U_ZERO_ERROR || 1121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru pDest!=dest || dest[destLength0]!=0 || 1122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru destLength!=destLength0 || !equalAnyFFFD(dest, pu, destLength) 1123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ) { 1124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromUTF8Lenient(%d conversion with length, srcLength capacity/terminated) failed\n", number); 1125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const uint16_t src16j[] = { 1131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 1132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 1133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 1134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 1135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0000, 1136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Test only ASCII */ 1137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 1139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const uint16_t src16WithNulls[] = { 1140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0000, 1141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0048, 0x0049, 0x004A, 0x000D, 0x000A, 0x0000, 1142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0000, 1143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0050, 0x0051, 0x0052, 0x000D, 0x000A, 0x0000, 1144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0000, 1145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 0x0000, 1146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0000, 1147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0058, 0x0059, 0x005A, 0x000D, 0x000A, 0x0000, 1148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test only ASCII */ 1149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 1151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 1152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 1153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 1154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 1155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 1156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 1157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0x0054, 0x0000 */ 1158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}; 1160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_UChar_WCHART_API(void){ 1161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) 1162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 1163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar* uSrc = src16j; 1164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uSrcLen = sizeof(src16j)/2; 1165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wchar_t* wDest = NULL; 1166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t wDestLen = 0; 1167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t reqLen= 0 ; 1168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool failed = FALSE; 1169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar* uDest = NULL; 1170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uDestLen = 0; 1171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int i =0; 1172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Bad UErrorCode arguments. Make sure that the API doesn't crash, and that Purify doesn't complain. */ 1174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (u_strFromWCS(NULL,0,NULL,NULL,0,NULL) != NULL) { 1175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromWCS() should return NULL with a bad argument\n"); 1176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (u_strToWCS(NULL,0,NULL,NULL,0,NULL) != NULL) { 1178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToWCS() should return NULL with a bad argument\n"); 1179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 118150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* NULL source & destination. */ 1182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 1183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(NULL,0,NULL,NULL,0,&err); 118450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (err != U_STRING_NOT_TERMINATED_WARNING) { 118550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromWCS(NULL, NULL) failed. Error: %s \n", u_errorName(err)); 1186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 1188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(NULL,0,NULL,NULL,0,&err); 118950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (err != U_STRING_NOT_TERMINATED_WARNING) { 119050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToWCS(NULL, NULL) failed. Error: %s \n", u_errorName(err)); 1191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 1193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight*/ 1195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,uSrcLen-1,&err); 1196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 1198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 1199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDest =(wchar_t*) malloc(sizeof(wchar_t) * (reqLen+1)); 1200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen = reqLen+1; 1201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,uSrcLen-1,&err); 1202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight */ 1205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,reqLen,&err); 1206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 1209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err =U_ZERO_ERROR; 1210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDest = (UChar*) malloc(sizeof(UChar) * (reqLen+1)); 1211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = reqLen + 1; 1212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,reqLen,&err); 1213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }else if(U_FAILURE(err)){ 1214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromWCS() failed. Error: %s \n", u_errorName(err)); 1216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 1217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i< uSrcLen; i++){ 1220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(uDest[i] != src16j[i]){ 1221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_verbose("u_str*WCS() failed for unterminated string expected: \\u%04X got: \\u%04X at index: %i \n", src16j[i] ,uDest[i],i); 1222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 1223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err)){ 1227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = TRUE; 1228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 1230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToWCS() failed \n"); 1231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(wDest); 1233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(uDest); 1234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* test with embeded nulls */ 1237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uSrc = src16WithNulls; 1238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uSrcLen = sizeof(src16WithNulls)/2; 1239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen =0; 1240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen =0; 1241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDest = NULL; 1242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDest = NULL; 1243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight*/ 1244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,uSrcLen-1,&err); 1245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 1247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 1248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDest =(wchar_t*) malloc(sizeof(wchar_t) * (reqLen+1)); 1249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen = reqLen+1; 1250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,uSrcLen-1,&err); 1251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight */ 1254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,reqLen,&err); 1255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 1257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err =U_ZERO_ERROR; 1258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDest = (UChar*) malloc(sizeof(UChar) * (reqLen+1)); 1259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = reqLen + 1; 1260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,reqLen,&err); 1261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1263b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(!U_FAILURE(err)) { 1264b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0; i< uSrcLen; i++){ 1265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(uDest[i] != src16WithNulls[i]){ 1266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_verbose("u_str*WCS() failed for string with nulls expected: \\u%04X got: \\u%04X at index: %i \n", src16WithNulls[i] ,uDest[i],i); 1267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 1268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1269b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err)){ 1273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = TRUE; 1274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 1276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToWCS() failed \n"); 1277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(wDest); 1279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(uDest); 1280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uSrc = src16j; 1286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uSrcLen = sizeof(src16j)/2; 1287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen =0; 1288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen =0; 1289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDest = NULL; 1290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDest = NULL; 1291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen = 0; 1292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight*/ 1293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&err); 1294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 1296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 1297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDest =(wchar_t*) malloc(sizeof(wchar_t) * (reqLen+1)); 1298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen = reqLen+1; 1299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&err); 1300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = 0; 1302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight */ 1303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&err); 1304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err == U_BUFFER_OVERFLOW_ERROR){ 1306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err =U_ZERO_ERROR; 1307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDest = (UChar*) malloc(sizeof(UChar) * (reqLen+1)); 1308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = reqLen + 1; 1309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&err); 1310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1313b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru if(!U_FAILURE(err)) { 1314b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru for(i=0; i< uSrcLen; i++){ 1315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(uDest[i] != src16j[i]){ 1316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 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); 1317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 1318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1319b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 1320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(err)){ 1323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = TRUE; 1324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 1326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToWCS() failed \n"); 1327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(wDest); 1329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(uDest); 1330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* 1333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test u_terminateWChars(). 1334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * All u_terminateXYZ() use the same implementation macro; 1335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * we test this function to improve API coverage. 1336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wchar_t buffer[10]; 1339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 1341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buffer[3]=0x20ac; 1342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen=u_terminateWChars(buffer, LENGTHOF(buffer), 3, &err); 1343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err!=U_ZERO_ERROR || wDestLen!=3 || buffer[3]!=0) { 1344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_terminateWChars(buffer, all, 3, zero) failed: %s length %d [3]==U+%04x\n", 1345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_errorName(err), wDestLen, buffer[3]); 1346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 1349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buffer[3]=0x20ac; 1350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen=u_terminateWChars(buffer, 3, 3, &err); 1351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err!=U_STRING_NOT_TERMINATED_WARNING || wDestLen!=3 || buffer[3]!=0x20ac) { 1352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_terminateWChars(buffer, 3, 3, zero) failed: %s length %d [3]==U+%04x\n", 1353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_errorName(err), wDestLen, buffer[3]); 1354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_STRING_NOT_TERMINATED_WARNING; 1357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buffer[3]=0x20ac; 1358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen=u_terminateWChars(buffer, LENGTHOF(buffer), 3, &err); 1359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err!=U_ZERO_ERROR || wDestLen!=3 || buffer[3]!=0) { 1360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_terminateWChars(buffer, all, 3, not-terminated) failed: %s length %d [3]==U+%04x\n", 1361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_errorName(err), wDestLen, buffer[3]); 1362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err=U_ZERO_ERROR; 1365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buffer[3]=0x20ac; 1366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen=u_terminateWChars(buffer, 2, 3, &err); 1367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(err!=U_BUFFER_OVERFLOW_ERROR || wDestLen!=3 || buffer[3]!=0x20ac) { 1368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_terminateWChars(buffer, 2, 3, zero) failed: %s length %d [3]==U+%04x\n", 1369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_errorName(err), wDestLen, buffer[3]); 1370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#else 1373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_info("Not testing u_str*WCS because (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) and wchar is neither utf16 nor utf32"); 1374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 1375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void Test_widestrs() 1378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 1379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) 1380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wchar_t ws[100]; 1381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar rts[100]; 1382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t wcap = sizeof(ws) / sizeof(*ws); 1383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t wl; 1384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t rtcap = sizeof(rts) / sizeof(*rts); 1385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t rtl; 1386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wchar_t *wcs; 1387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar *cp; 1388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *errname; 1389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar ustr[] = {'h', 'e', 'l', 'l', 'o', 0}; 1390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t ul = sizeof(ustr)/sizeof(*ustr) -1; 1391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru char astr[100]; 1392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode err; 1394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 1396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wcs = u_strToWCS(ws, wcap, &wl, ustr, ul, &err); 1397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(err)) { 1398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errname = u_errorName(err); 1399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("test_widestrs: u_strToWCS error: %s!\n",errname); 1400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(ul!=wl){ 1402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToWCS: ustr = %s, ul = %d, ws = %S, wl = %d!\n", u_austrcpy(astr, ustr), ul, ws, wl); 1403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru err = U_ZERO_ERROR; 1405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wl = (int32_t)uprv_wcslen(wcs); 1406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru cp = u_strFromWCS(rts, rtcap, &rtl, wcs, wl, &err); 1407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(err)) { 1408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errname = u_errorName(err); 1409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru fprintf(stderr, "test_widestrs: ucnv_wcstombs error: %s!\n",errname); 1410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(wl != rtl){ 1412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strFromWCS: wcs = %S, wl = %d,rts = %s, rtl = %d!\n", wcs, wl, u_austrcpy(astr, rts), rtl); 1413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#else 1415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_info("Not testing u_str*WCS because (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) and wchar is neither utf16 nor utf32"); 1416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 1417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void 1420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTest_WCHART_LongString(){ 1421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) 1422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* testdatapath=loadTestData(&status); 1424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UResourceBundle *theBundle = ures_open(testdatapath, "testtypes", &status); 1425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t strLen =0; 1426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar* str = ures_getStringByKey(theBundle, "testinclude",&strLen,&status); 1427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UChar* uSrc = str; 1428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uSrcLen = strLen; 1429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t wDestLen =0, reqLen=0, i=0; 1430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t uDestLen =0; 1431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wchar_t* wDest = NULL; 1432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar* uDest = NULL; 1433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool failed = FALSE; 1434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1435b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("Loaded string of %d UChars\n", uSrcLen); 1436b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 1437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)){ 1438c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru log_data_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status)); 1439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 1440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight*/ 1443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&status); 1444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(status == U_BUFFER_OVERFLOW_ERROR){ 1446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status=U_ZERO_ERROR; 1447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDest =(wchar_t*) malloc(sizeof(wchar_t) * (reqLen+1)); 1448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru wDestLen = reqLen+1; 1449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&status); 1450b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("To %d*%d-byte wchar_ts\n", reqLen,sizeof(wchar_t)); 1451b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 1452b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 1453b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho { 1454b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int j; 1455b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho for(j=0;j>=0&&j<reqLen;j++) { 1456b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if(wDest[j]!=uSrc[j]) { 1457b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("Diff %04X vs %04X @ %d\n", wDest[j],uSrc[j],j); 1458b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 1459b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 1460b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 1461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1462b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 1463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = 0; 1464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* pre-flight */ 1465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&status); 1466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(status == U_BUFFER_OVERFLOW_ERROR){ 1467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status =U_ZERO_ERROR; 1468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDest = (UChar*) malloc(sizeof(UChar) * (reqLen+1)); 1469b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho u_memset(uDest,0xFFFF,reqLen+1); 1470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uDestLen = reqLen + 1; 1471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&status); 1472b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("Back to %d UChars\n", reqLen); 1473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1474b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#if defined(U_WCHAR_IS_UTF16) 1475b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("U_WCHAR_IS_UTF16\n"); 1476b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#elif defined(U_WCHAR_IS_UTF32) 1477b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("U_WCHAR_IS_UTF32\n"); 1478b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#else 1479b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("U_WCHAR_IS_idunno (not UTF)\n"); 1480b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho#endif 1481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1482b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if(reqLen!=uSrcLen) { 1483b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_err("Error: dest len is %d but expected src len %d\n", reqLen, uSrcLen); 1484b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 1485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i< uSrcLen; i++){ 1487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(uDest[i] != str[i]){ 1488b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("u_str*WCS() failed for null terminated string expected: \\u%04X got: \\u%04X at index: %i \n", str[i], uDest[i],i); 1489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed =TRUE; 1490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)){ 1494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failed = TRUE; 1495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(failed){ 1497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_err("u_strToWCS() failed \n"); 1498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(wDest); 1500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru free(uDest); 1501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* close the bundle */ 1502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ures_close(theBundle); 1503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#else 1504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru log_info("Not testing u_str*WCS because (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) and wchar is neither utf16 nor utf32"); 1505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 1506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 150850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void Test_strToJavaModifiedUTF8() { 150950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar src[]={ 151050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63, 0xe1, 0xe2, 0xe3, 151150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe01, 0xe02, 0xe03, 0xe001, 0xe002, 0xe003, 151250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xd800, 0xdc00, 0xdc00, 0xd800, 0, 151350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xdbff, 0xdfff, 151450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0xed, 0xe0e, 0x6f 151550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 151650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t expected[]={ 151750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63, 0xc3, 0xa1, 0xc3, 0xa2, 0xc3, 0xa3, 151850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0, 0xb8, 0x81, 0xe0, 0xb8, 0x82, 0xe0, 0xb8, 0x83, 151950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xee, 0x80, 0x81, 0xee, 0x80, 0x82, 0xee, 0x80, 0x83, 152050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80, 0xed, 0xb0, 0x80, 0xed, 0xa0, 0x80, 0xc0, 0x80, 152150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf, 152250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0xc3, 0xad, 0xe0, 0xb8, 0x8e, 0x6f 152350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 152450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar shortSrc[]={ 152550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe01, 0xe1, 0x61 152650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 152750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t shortExpected[]={ 152850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0, 0xb8, 0x81, 0xc3, 0xa1, 0x61 152950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 153050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar asciiNul[]={ 153150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63, 0 153250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 153350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t asciiNulExpected[]={ 153450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63 153550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 153650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char dest[200]; 153750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char *p; 153850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t length, expectedTerminatedLength; 153950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode errorCode; 154050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 154150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho expectedTerminatedLength=(int32_t)(strstr((const char *)expected, "\xc0\x80")- 154250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)expected); 154350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 154450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 154550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 154650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, 154750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 154850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 154950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || 155050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 155150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 155250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(normal) failed - %s\n", u_errorName(errorCode)); 155350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 155450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 155550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 155650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 155750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, 155850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 155950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 156050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0!=memcmp(dest, expected, LENGTHOF(expected)) || 156150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[LENGTHOF(expected)]!=0 156250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 156350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(normal, pLength=NULL) failed - %s\n", u_errorName(errorCode)); 156450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 156550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 156650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 156750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 156850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, LENGTHOF(expected), &length, 156950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 157050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || 157150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || 157250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=(char)0xff 157350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 157450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(tight) failed - %s\n", u_errorName(errorCode)); 157550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 157650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 157750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 157850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 157950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, src, -1, &errorCode); 158050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 158150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || 158250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 158350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 158450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(NUL-terminated) failed - %s\n", u_errorName(errorCode)); 158550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 158650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 158750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 158850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 158950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, src, -1, &errorCode); 159050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 159150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0!=memcmp(dest, expected, expectedTerminatedLength) || 159250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[expectedTerminatedLength]!=0 159350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 159450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(NUL-terminated, pLength=NULL) failed - %s\n", u_errorName(errorCode)); 159550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 159650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 159750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 159850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 159950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, LENGTHOF(expected)/2, &length, 160050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 160150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_BUFFER_OVERFLOW_ERROR || 160250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || dest[LENGTHOF(expected)/2]!=(char)0xff 160350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 160450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(overflow) failed - %s\n", u_errorName(errorCode)); 160550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 160650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 160750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 160850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 160950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(NULL, 0, &length, 161050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 161150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_BUFFER_OVERFLOW_ERROR || 161250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || dest[0]!=(char)0xff 161350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 161450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(pure preflighting) failed - %s\n", u_errorName(errorCode)); 161550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 161650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 161750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 161850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 161950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, 162050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho shortSrc, LENGTHOF(shortSrc), &errorCode); 162150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 162250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(shortExpected) || 0!=memcmp(dest, shortExpected, length) || 162350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 162450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 162550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(short) failed - %s\n", u_errorName(errorCode)); 162650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 162750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 162850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 162950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 163050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, 163150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho asciiNul, -1, &errorCode); 163250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 163350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(asciiNulExpected) || 0!=memcmp(dest, asciiNulExpected, length) || 163450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 163550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 163650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(asciiNul) failed - %s\n", u_errorName(errorCode)); 163750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 163850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 163950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 164050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 164150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, 164250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho NULL, 0, &errorCode); 164350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 164450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=0 || dest[0]!=0 164550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 164650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(empty) failed - %s\n", u_errorName(errorCode)); 164750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 164850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 164950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* illegal arguments */ 165050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 165150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 165250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 165350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(NULL, sizeof(dest), &length, 165450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 165550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { 165650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(dest=NULL) failed - %s\n", u_errorName(errorCode)); 165750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 165850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 165950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 166050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 166150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, -1, &length, 166250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho src, LENGTHOF(src), &errorCode); 166350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { 166450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(destCapacity<0) failed - %s\n", u_errorName(errorCode)); 166550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 166650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 166750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 166850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 166950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, sizeof(dest), &length, 167050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho NULL, LENGTHOF(src), &errorCode); 167150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { 167250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(src=NULL) failed - %s\n", u_errorName(errorCode)); 167350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 167450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 167550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 167650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=-5; 167750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strToJavaModifiedUTF8(dest, sizeof(dest), &length, 167850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho NULL, -1, &errorCode); 167950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=(char)0xff) { 168050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(src=NULL, srcLength<0) failed - %s\n", u_errorName(errorCode)); 168150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 168250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 168350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 168450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void Test_strFromJavaModifiedUTF8() { 168550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t src[]={ 168650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63, 0xc3, 0xa1, 0xc3, 0xa2, 0xc3, 0xa3, 168750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0, 0xb8, 0x81, 0xe0, 0xb8, 0x82, 0xe0, 0xb8, 0x83, 168850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xee, 0x80, 0x81, 0xee, 0x80, 0x82, 0xee, 0x80, 0x83, 168950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80, 0xed, 0xb0, 0x80, 0xed, 0xa0, 0x80, 0, 169050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf, 169150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x81, 0xc0, 0xe0, 0xb8, 0xf0, 0x90, 0x80, 0x80, /* invalid sequences */ 169250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 169350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0, 0x81, 0xac, 0xe0, 0x83, 0xad, /* non-shortest forms are allowed */ 169450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0, 0xb8, 0x8e, 0x6f 169550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 169650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar expected[]={ 169750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63, 0xe1, 0xe2, 0xe3, 169850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe01, 0xe02, 0xe03, 0xe001, 0xe002, 0xe003, 169950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xd800, 0xdc00, 0xdc00, 0xd800, 0, 170050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xdbff, 0xdfff, 170150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, 0xfffd, 0xfffd, 0xfffd, 170250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 170350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x6c, 0xed, 170450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0e, 0x6f 170550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 170650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t shortSrc[]={ 170750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe0, 0xb8, 0x81, 0xc3, 0xa1, 0x61 170850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 170950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar shortExpected[]={ 171050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xe01, 0xe1, 0x61 171150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 171250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t asciiNul[]={ 171350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63, 0 171450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 171550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar asciiNulExpected[]={ 171650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x61, 0x62, 0x63 171750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 171850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const uint8_t invalid[]={ 171950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x81, 0xc0, 0xe0, 0xb8, 0xf0, 0x90, 0x80, 0x80 172050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 172150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar invalidExpectedFFFD[]={ 172250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, 0xfffd, 0xfffd, 0xfffd 172350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 172450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho static const UChar invalidExpected50000[]={ 172550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xd900, 0xdc00, 0xd900, 0xdc00, 0xd900, 0xdc00, 0xd900, 0xdc00 172650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 172750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar dest[200]; 172850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *p; 172950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t length, expectedTerminatedLength; 173050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t numSubstitutions; 173150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode errorCode; 173250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 173350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho expectedTerminatedLength=(int32_t)(u_strchr(expected, 0)-expected); 173450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 173550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 173650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 173750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 173850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 173950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 174050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 174150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || 174250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 || 174350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=LENGTHOF(invalidExpectedFFFD) 174450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 174550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(normal) failed - %s\n", u_errorName(errorCode)); 174650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 174750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 174850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 174950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 175050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), NULL, 175150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 175250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 175350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 175450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0!=memcmp(dest, expected, LENGTHOF(expected)) || 175550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[LENGTHOF(expected)]!=0 || 175650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=LENGTHOF(invalidExpectedFFFD) 175750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 175850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(normal, pLength=NULL) failed - %s\n", u_errorName(errorCode)); 175950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 176050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 176150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 176250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 176350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 176450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 176550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, NULL, &errorCode); 176650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 176750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || 176850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 176950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 177050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(normal, pNumSubstitutions=NULL) failed - %s\n", u_errorName(errorCode)); 177150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 177250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 177350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 177450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 177550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, LENGTHOF(expected), &length, 177650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 177750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 177850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || 177950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || 178050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0xffff || 178150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=LENGTHOF(invalidExpectedFFFD) 178250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 178350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(tight) failed - %s\n", u_errorName(errorCode)); 178450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 178550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 178650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 178750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 178850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 178950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, -1, 179050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 179150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 179250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || 179350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 || 179450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=0 179550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 179650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(NUL-terminated) failed - %s\n", u_errorName(errorCode)); 179750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 179850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 179950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 180050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 180150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), NULL, 180250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, -1, 180350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 180450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 180550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0!=memcmp(dest, expected, expectedTerminatedLength) || 180650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[expectedTerminatedLength]!=0 || 180750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=0 180850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 180950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(NUL-terminated, pLength=NULL) failed - %s\n", u_errorName(errorCode)); 181050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 181150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 181250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 181350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 181450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 181550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, -1, 181650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, NULL, &errorCode); 181750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 181850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=expectedTerminatedLength || 0!=memcmp(dest, expected, length) || 181950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 182050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 182150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(NUL-terminated, pNumSubstitutions=NULL) failed - %s\n", u_errorName(errorCode)); 182250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 182350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 182450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 182550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 182650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, LENGTHOF(expected)/2, &length, 182750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 182850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 182950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_BUFFER_OVERFLOW_ERROR || 183050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || dest[LENGTHOF(expected)/2]!=0xffff 183150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 183250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(overflow) failed - %s\n", u_errorName(errorCode)); 183350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 183450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 183550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 183650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 183750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(NULL, 0, &length, 183850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 183950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 184050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_BUFFER_OVERFLOW_ERROR || 184150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(expected) || dest[0]!=0xffff 184250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 184350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(pure preflighting) failed - %s\n", u_errorName(errorCode)); 184450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 184550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 184650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 184750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 184850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 184950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)shortSrc, LENGTHOF(shortSrc), 185050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 185150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 185250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(shortExpected) || 0!=memcmp(dest, shortExpected, length) || 185350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 || 185450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=0 185550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 185650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(short) failed - %s\n", u_errorName(errorCode)); 185750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 185850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 185950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 186050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 186150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 186250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)asciiNul, -1, 186350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 186450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 186550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(asciiNulExpected) || 0!=memcmp(dest, asciiNulExpected, length) || 186650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 || 186750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=0 186850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 186950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(asciiNul) failed - %s\n", u_errorName(errorCode)); 187050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 187150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 187250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 187350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 187450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 187550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho NULL, 0, 0xfffd, &numSubstitutions, &errorCode); 187650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 187750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=0 || dest[0]!=0 || 187850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=0 187950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 188050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(empty) failed - %s\n", u_errorName(errorCode)); 188150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 188250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 188350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 188450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 188550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 188650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)invalid, LENGTHOF(invalid), 188750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 188850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 188950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(invalidExpectedFFFD) || 0!=memcmp(dest, invalidExpectedFFFD, length) || 189050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 || 189150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=LENGTHOF(invalidExpectedFFFD) 189250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 189350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(invalid->fffd) failed - %s\n", u_errorName(errorCode)); 189450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 189550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 189650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 189750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 189850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 189950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)invalid, LENGTHOF(invalid), 190050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x50000, &numSubstitutions, &errorCode); 190150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( U_FAILURE(errorCode) || p!=dest || 190250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length!=LENGTHOF(invalidExpected50000) || 0!=memcmp(dest, invalidExpected50000, length) || 190350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest[length]!=0 || 190450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=LENGTHOF(invalidExpectedFFFD) /* not ...50000 */ 190550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 190650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(invalid->50000) failed - %s\n", u_errorName(errorCode)); 190750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 190850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 190950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 191050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 191150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 191250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)invalid, LENGTHOF(invalid), 191350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho U_SENTINEL, &numSubstitutions, &errorCode); 191450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_INVALID_CHAR_FOUND || dest[0]!=0xffff || numSubstitutions!=0) { 191550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(invalid->error) failed - %s\n", u_errorName(errorCode)); 191650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 191750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 191850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 191950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 192050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, (int32_t)sizeof(dest), &length, 192150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 192250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho U_SENTINEL, &numSubstitutions, &errorCode); 192350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if( errorCode!=U_INVALID_CHAR_FOUND || 192450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length>=LENGTHOF(expected) || dest[LENGTHOF(expected)-1]!=0xffff || 192550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho numSubstitutions!=0 192650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ) { 192750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(normal->error) failed - %s\n", u_errorName(errorCode)); 192850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 192950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 193050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* illegal arguments */ 193150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 193250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 193350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 193450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(NULL, sizeof(dest), &length, 193550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 193650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 193750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { 193850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(dest=NULL) failed - %s\n", u_errorName(errorCode)); 193950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 194050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 194150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 194250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 194350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, -1, &length, 194450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 194550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 194650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { 194750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(destCapacity<0) failed - %s\n", u_errorName(errorCode)); 194850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 194950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 195050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 195150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 195250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, 195350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho NULL, LENGTHOF(src), 195450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xfffd, &numSubstitutions, &errorCode); 195550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { 195650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(src=NULL) failed - %s\n", u_errorName(errorCode)); 195750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 195850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 195950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 196050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 196150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, 196250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho NULL, -1, 0xfffd, &numSubstitutions, &errorCode); 196350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { 196450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(src=NULL, srcLength<0) failed - %s\n", u_errorName(errorCode)); 196550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 196650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 196750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 196850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 196950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, 197050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 197150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0x110000, &numSubstitutions, &errorCode); 197250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { 197350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(subchar=U_SENTINEL) failed - %s\n", u_errorName(errorCode)); 197450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 197550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho memset(dest, 0xff, sizeof(dest)); 197650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 197750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=numSubstitutions=-5; 197850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho p=u_strFromJavaModifiedUTF8WithSub(dest, sizeof(dest), &length, 197950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho (const char *)src, LENGTHOF(src), 198050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 0xdfff, &numSubstitutions, &errorCode); 198150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || dest[0]!=0xffff) { 198250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(subchar is surrogate) failed - %s\n", u_errorName(errorCode)); 198350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 198450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 198550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 198650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/* test that string transformation functions permit NULL source pointer when source length==0 */ 198750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic void TestNullEmptySource() { 198850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char dest8[4]={ 3, 3, 3, 3 }; 198950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar dest16[4]={ 3, 3, 3, 3 }; 199050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar32 dest32[4]={ 3, 3, 3, 3 }; 199150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) 199250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho wchar_t destW[4]={ 3, 3, 3, 3 }; 199350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif 199450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 199550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t length; 199650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode errorCode; 199750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 199850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* u_strFromXyz() */ 199950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 200050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 200150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 200250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 200350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromUTF8(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); 200450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 200550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromUTF8(source=NULL, sourceLength=0) failed\n"); 200650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 200750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 200850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 200950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 201050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 201150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromUTF8WithSub(dest16, LENGTHOF(dest16), &length, NULL, 0, 0xfffd, NULL, &errorCode); 201250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 201350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromUTF8WithSub(source=NULL, sourceLength=0) failed\n"); 201450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 201550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 201650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 201750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 201850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 201950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromUTF8Lenient(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); 202050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 202150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromUTF8Lenient(source=NULL, sourceLength=0) failed\n"); 202250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 202350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 202450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 202550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 202650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 202750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromUTF32(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); 202850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 202950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromUTF32(source=NULL, sourceLength=0) failed\n"); 203050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 203150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 203250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 203350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 203450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 203550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromUTF32WithSub(dest16, LENGTHOF(dest16), &length, NULL, 0, 0xfffd, NULL, &errorCode); 203650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 203750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromUTF32WithSub(source=NULL, sourceLength=0) failed\n"); 203850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 203950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 204050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 204150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 204250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 204350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromJavaModifiedUTF8WithSub(dest16, LENGTHOF(dest16), &length, NULL, 0, 0xfffd, NULL, &errorCode); 204450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 204550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromJavaModifiedUTF8WithSub(source=NULL, sourceLength=0) failed\n"); 204650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 204750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 204850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* u_strToXyz() */ 204950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 205050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest8[0]=3; 205150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 205250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 205350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strToUTF8(dest8, LENGTHOF(dest8), &length, NULL, 0, &errorCode); 205450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { 205550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToUTF8(source=NULL, sourceLength=0) failed\n"); 205650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 205750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 205850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest8[0]=3; 205950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 206050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 206150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strToUTF8WithSub(dest8, LENGTHOF(dest8), &length, NULL, 0, 0xfffd, NULL, &errorCode); 206250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { 206350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToUTF8(source=NULL, sourceLength=0) failed\n"); 206450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 206550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 206650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest32[0]=3; 206750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 206850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 206950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strToUTF32(dest32, LENGTHOF(dest32), &length, NULL, 0, &errorCode); 207050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest32[0]!=0 || dest32[1]!=3) { 207150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToUTF32(source=NULL, sourceLength=0) failed\n"); 207250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 207350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 207450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest32[0]=3; 207550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 207650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 207750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strToUTF32WithSub(dest32, LENGTHOF(dest32), &length, NULL, 0, 0xfffd, NULL, &errorCode); 207850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest32[0]!=0 || dest32[1]!=3) { 207950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToUTF32WithSub(source=NULL, sourceLength=0) failed\n"); 208050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 208150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 208250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest8[0]=3; 208350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 208450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 208550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strToJavaModifiedUTF8(dest8, LENGTHOF(dest8), &length, NULL, 0, &errorCode); 208650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest8[0]!=0 || dest8[1]!=3) { 208750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToJavaModifiedUTF8(source=NULL, sourceLength=0) failed\n"); 208850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 208950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 209050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if (defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32)) || (!UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION) 209150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 209250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dest16[0]=3; 209350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 209450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 209550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strFromWCS(dest16, LENGTHOF(dest16), &length, NULL, 0, &errorCode); 209650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || dest16[0]!=0 || dest16[1]!=3) { 209750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strFromWCS(source=NULL, sourceLength=0) failed\n"); 209850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 209950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 210050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho destW[0]=3; 210150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho length=3; 210250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho errorCode=U_ZERO_ERROR; 210350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho u_strToWCS(destW, LENGTHOF(destW), &length, NULL, 0, &errorCode); 210450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if(errorCode!=U_ZERO_ERROR || length!=0 || destW[0]!=0 || destW[1]!=3) { 210550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho log_err("u_strToWCS(source=NULL, sourceLength=0) failed\n"); 210650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 210750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 210850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif 210950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 2110