nsCOMPtr <nsISaveAsCharset> saveAsCharset; res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL, NS_GET_IID(nsISaveAsCharset), getter_AddRefs(saveAsCharset));
nsCOMPtr <nsISaveAsCharset> saveAsCharset = do_CreateInstance(kSaveAsCharsetCID, &res);
static void TestSaveAsCharset(){  printf("==============================\n");  printf("Start nsISaveAsCharset Test \n");  printf("==============================\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++) {    printf("%c ", inString[i]);  }  printf("\n");  nsCOMPtr <nsISaveAsCharset> saveAsCharset;  res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL, NS_GET_IID(nsISaveAsCharset), getter_AddRefs(saveAsCharset));  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}    printf("ISO-8859-1 attr_plainTextDefault entityNone\n");  res = saveAsCharset->Init("ISO-8859-1",                                  nsISaveAsCharset::attr_plainTextDefault,                                  nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  if (NULL == outString) {printf("\tFailed!! output null\n");}  else {printf("%s\n", outString); nsMemory::Free(outString);}  printf("ISO-2022-JP attr_plainTextDefault entityNone\n");  res = saveAsCharset->Init("ISO-2022-JP",                                  nsISaveAsCharset::attr_plainTextDefault,                                 nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  if (NULL == outString) {printf("\tFailed!! output null\n");}  else {printf("%s\n", outString); nsMemory::Free(outString);}  if (NS_ERROR_UENC_NOMAPPING == res) {    outString = ToNewUTF8String(inString);    if (NULL == outString) {printf("\tFailed!! output null\n");}    else {printf("Fall back to UTF-8: %s\n", outString); nsMemory::Free(outString);}  }  printf("ISO-2022-JP attr_FallbackQuestionMark entityNone\n");  res = saveAsCharset->Init("ISO-2022-JP",                                  nsISaveAsCharset::attr_FallbackQuestionMark,                                 nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  if (NULL == outString) {printf("\tFailed!! output null\n");}  else {printf("%s\n", outString); nsMemory::Free(outString);}  printf("ISO-2022-JP attr_FallbackEscapeU entityNone\n");  res = saveAsCharset->Init("ISO-2022-JP",                                  nsISaveAsCharset::attr_FallbackEscapeU,                                 nsIEntityConverter::entityNone);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  if (NULL == outString) {printf("\tFailed!! output null\n");}  else {printf("%s\n", outString); nsMemory::Free(outString);}  printf("ISO-8859-1 attr_htmlTextDefault html40Latin1\n");  res = saveAsCharset->Init("ISO-8859-1",                                  nsISaveAsCharset::attr_htmlTextDefault,                                  nsIEntityConverter::html40Latin1);  if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  if (NULL == outString) {printf("\tFailed!! output null\n");}  else {printf("%s\n", outString); nsMemory::Free(outString);}  printf("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)) {printf("\tFailed!! return value != NS_OK\n");}  res = saveAsCharset->Convert(inString.get(), &outString);  if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}  if (NULL == outString) {printf("\tFailed!! output null\n");}  else {printf("%s\n", outString); nsMemory::Free(outString);}  printf("==============================\n");  printf("Finish nsISaveAsCharset Test \n");  printf("==============================\n\n");}