if (NULL == outString) {cout << "\tFailed!! output null\n";} else {cout << "Fall back to UTF-8: " << outString << "\n"; nsMemory::Free(outString);}
if (NULL == outString) {printf("\tFailed!! output null\n");} else {printf("Fall back to UTF-8: %s\n", outString); nsMemory::Free(outString);}
static void TestSaveAsCharset(){  cout << "==============================\n";  cout << "Start nsISaveAsCharset Test \n";  cout << "==============================\n";  nsresult res;  nsString inString;  inString.Assign(NS_ConvertASCIItoUCS2("\x61\x62\x80\xA0\x63"));  char *outString;    // first, dump input string  for (PRUint32 i = 0; i < inString.Length(); i++) {    cout << inString[i] << " ";  }  cout << "\n";  nsCOMPtr <nsISaveAsCharset> saveAsCharset;  res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL, NS_GET_IID(nsISaveAsCharset), getter_AddRefs(saveAsCharset));  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}    cout << "ISO-8859-1 " << "attr_plainTextDefault " << "entityNone " << "\n";  res = saveAsCharset->Init("ISO-8859-1",                                  nsISaveAsCharset::attr_plainTextDefault,                                  nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  if (NULL == outString) {cout << "\tFailed!! output null\n";}  else {cout << outString << "\n"; nsMemory::Free(outString);}  cout << "ISO-2022-JP " << "attr_plainTextDefault " << "entityNone " << "\n";  res = saveAsCharset->Init("ISO-2022-JP",                                  nsISaveAsCharset::attr_plainTextDefault,                                 nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  if (NULL == outString) {cout << "\tFailed!! output null\n";}  else {cout << outString << "\n"; nsMemory::Free(outString);}  if (NS_ERROR_UENC_NOMAPPING == res) {    outString = ToNewUTF8String(inString);    if (NULL == outString) {cout << "\tFailed!! output null\n";}    else {cout << "Fall back to UTF-8: " << outString << "\n"; nsMemory::Free(outString);}  }  cout << "ISO-2022-JP " << "attr_FallbackQuestionMark " << "entityNone " << "\n";  res = saveAsCharset->Init("ISO-2022-JP",                                  nsISaveAsCharset::attr_FallbackQuestionMark,                                 nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  if (NULL == outString) {cout << "\tFailed!! output null\n";}  else {cout << outString << "\n"; nsMemory::Free(outString);}  cout << "ISO-2022-JP " << "attr_FallbackEscapeU " << "entityNone " << "\n";  res = saveAsCharset->Init("ISO-2022-JP",                                  nsISaveAsCharset::attr_FallbackEscapeU,                                 nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  if (NULL == outString) {cout << "\tFailed!! output null\n";}  else {cout << outString << "\n"; nsMemory::Free(outString);}  cout << "ISO-8859-1 " << "attr_htmlTextDefault " << "html40Latin1 " << "\n";  res = saveAsCharset->Init("ISO-8859-1",                                  nsISaveAsCharset::attr_htmlTextDefault,                                  nsIEntityConverter::html40Latin1);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  if (NULL == outString) {cout << "\tFailed!! output null\n";}  else {cout << outString << "\n"; nsMemory::Free(outString);}  cout << "ISO-8859-1 " << "attr_FallbackHexNCR+attr_EntityAfterCharsetConv " << "html40Latin1 " << "\n";  res = saveAsCharset->Init("ISO-8859-1",                                  nsISaveAsCharset::attr_FallbackHexNCR +                                  nsISaveAsCharset::attr_EntityAfterCharsetConv,                                  nsIEntityConverter::html40Latin1);  if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";}  if (NULL == outString) {cout << "\tFailed!! output null\n";}  else {cout << outString << "\n"; nsMemory::Free(outString);}  cout << "==============================\n";  cout << "Finish nsISaveAsCharset Test \n";  cout << "==============================\n\n";}