Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsTestUConv Class Reference

The main class of the program. More...

Collaboration diagram for nsTestUConv:
Collaboration graph
[legend]

List of all members.

Public Member Functions

nsresult Main (int aArgC, char **aArgV)
 Main method of the program.

Private Member Functions

nsresult TestEncoders ()
 Run the built-in set of self tests for encoders.
nsresult TestDecoders ()
 Run the built-in set of self tests for decoders.
nsresult TestCharsetManager ()
 Run the built-in set of self tests for the CharsetManager.
nsresult DisplayDetectors ()
 Display charset detectors and their attributes.
nsresult DisplayCharsets ()
 Display charsets and their attributes.
nsresult TestTempBug ()
 Run a temporary debug test.
nsresult Encode (PRUnichar **aSrc, PRUnichar *aSrcEnd, char **aDest, char *aDestEnd, const nsAFlatCString &aCharset)
nsresult ConvertEncode (PRUnichar **aSrc, PRUnichar *aSrcEnd, char **aDest, char *aDestEnd, nsIUnicodeEncoder *aEncoder)
 Bridge methods between the new argument style (poiters) and the old one (lengths).
nsresult FinishEncode (char **aDest, char *aDestEnd, nsIUnicodeEncoder *aEncoder)
 This wraps an encoder Finish() call.
void PrintSpaces (int aCount)

Private Attributes

nsTestLog mLog

Detailed Description

The main class of the program.

XXX Create a very general set of "bug and regression" test cases and the one in TestTempBug() XXX Apply the new argument style (pointers) to the converters interfaces

28/Mar/2000

Author:
Catalin Rotaru [CATA]

Definition at line 98 of file TestUConv.cpp.


Member Function Documentation

nsresult nsTestUConv::ConvertEncode ( PRUnichar **  aSrc,
PRUnichar aSrcEnd,
char **  aDest,
char *  aDestEnd,
nsIUnicodeEncoder aEncoder 
) [private]

Bridge methods between the new argument style (poiters) and the old one (lengths).

To be removed when the converter interfaces will switch to the new style.

This wraps an encoder Convert() call.

Definition at line 508 of file TestUConv.cpp.

{
  PRUnichar * src = (*aSrc);
  char * dest = (*aDest);
  PRInt32 srcLen = aSrcEnd - src;
  PRInt32 destLen = aDestEnd - dest;

  nsresult res = aEncoder->Convert(src, &srcLen, dest, &destLen);

  (*aSrc) = src + srcLen;
  (*aDest) = dest + destLen;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Display charsets and their attributes.

Definition at line 315 of file TestUConv.cpp.

{
  char * trace = "DisplayCharsets";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) {
    mLog.PrintError("NS_WITH_SERVICE", res);
    return res;
  }

  nsCOMPtr<nsIUTF8StringEnumerator> decoders;
  nsCOMPtr<nsIUTF8StringEnumerator> encoders;

  res = ccMan->GetDecoderList(getter_AddRefs(decoders));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetDecoderList()", res);
    return res;
  }

  res = ccMan->GetEncoderList(getter_AddRefs(encoders));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetEncoderList()", res);
    return res;
  }


  printf("***** Character Sets *****\n");

  PRUint32 encCount = 0, decCount = 0;
  PRUint32 basicEncCount = 0, basicDecCount = 0;

  nsCStringArray allCharsets;
  
  nsCAutoString charset;
  PRBool hasMore;
  encoders->HasMore(&hasMore);
  while (hasMore) {
    res = encoders->GetNext(charset);
    if (NS_SUCCEEDED(res))
      allCharsets.AppendCString(charset);

    encoders->HasMore(&hasMore);
  }

  nsAutoString prop, str;
  PRUint32 count = allCharsets.Count();
  for (PRUint32 i = 0; i < count; i++) {

    const nsCString* charset = allCharsets[i];
    printf("%s", charset->get());
    PrintSpaces(24 - charset->Length());  // align to hard coded column number


    nsCOMPtr<nsIUnicodeDecoder> dec = NULL;
    res = ccMan->GetUnicodeDecoder(charset->get(), getter_AddRefs(dec));
    if (NS_FAILED(res)) printf (" "); 
    else {
      printf("D");
      decCount++;
    }
#ifdef NS_DEBUG
    // show the "basic" decoder classes
    if (dec) {
      nsCOMPtr<nsIBasicDecoder> isBasic = do_QueryInterface(dec);
      if (isBasic) {
        basicDecCount++;
        printf("b");
      }
      else printf(" ");
    }
    else printf(" ");
#endif

    nsCOMPtr<nsIUnicodeEncoder> enc = NULL;
    res = ccMan->GetUnicodeEncoder(charset->get(), getter_AddRefs(enc));
    if (NS_FAILED(res)) printf (" "); 
    else {
      printf("E");
      encCount++;
    }

#ifdef NS_DEBUG
    if (enc) {
      nsCOMPtr<nsIBasicEncoder> isBasic = do_QueryInterface(enc);
      if (isBasic) {
        basicEncCount++;
        printf("b");
      }
      else printf(" ");
    }
    else printf(" ");
#endif
    
    printf(" ");

    prop.AssignLiteral(".notForBrowser");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((dec != NULL) && (NS_FAILED(res))) printf ("B"); 
    else printf("X");

    prop.AssignLiteral(".notForComposer");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((enc != NULL) && (NS_FAILED(res))) printf ("C"); 
    else printf("X");

    prop.AssignLiteral(".notForMailView");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((dec != NULL) && (NS_FAILED(res))) printf ("V"); 
    else printf("X");

    prop.AssignLiteral(".notForMailEdit");
    res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
    if ((enc != NULL) && (NS_FAILED(res))) printf ("E"); 
    else printf("X");

    printf("(%3d, %3d) ", encCount, decCount);
    res = ccMan->GetCharsetTitle(charset->get(), str);
    if (NS_FAILED(res)) str.SetLength(0);
    NS_LossyConvertUCS2toASCII buff2(str);
    printf(" \"%s\"\n", buff2.get());
  }

  printf("%u of %u decoders are basic (%d%%)\n",
         basicDecCount, decCount, (basicDecCount * 100) / decCount);

  printf("%u of %u encoders are basic (%d%%)\n",
         basicEncCount, encCount, (basicEncCount * 100) / encCount);
  mLog.DelTrace(trace);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Display charset detectors and their attributes.

Definition at line 268 of file TestUConv.cpp.

{
  char * trace = "DisplayDetectors";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) {
    mLog.PrintError("NS_WITH_SERVICE", res);
    return res;
  }

  // charset detectors
  nsCOMPtr<nsIUTF8StringEnumerator> detectors;

  res = ccMan->GetCharsetDetectorList(getter_AddRefs(detectors));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetCharsetDetectorList()", res);
    return res;
  }

  printf("***** Character Set Detectors *****\n");

  PRBool hasMore;
  detectors->HasMore(&hasMore);
  while (hasMore) {
    nsCAutoString detectorName;
    res = detectors->GetNext(detectorName);
    if (NS_FAILED(res)) {
      mLog.PrintError("GetNext()", res);
      return res;
    }

    printf("%s", detectorName.get());
    PrintSpaces(36 - detectorName.Length()); // align to hard coded column number

    nsAutoString title;
    res = ccMan->GetCharsetTitle(detectorName.get(), title);
    if (NS_FAILED(res)) title.SetLength(0);
    printf("\"%s\"\n", NS_LossyConvertUCS2toASCII(title).get());
  }
  
  mLog.DelTrace(trace);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTestUConv::Encode ( PRUnichar **  aSrc,
PRUnichar aSrcEnd,
char **  aDest,
char *  aDestEnd,
const nsAFlatCString aCharset 
) [private]

Definition at line 470 of file TestUConv.cpp.

{
  char * trace = "Encode";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) {
    mLog.PrintError("NS_WITH_SERVICE", res);
    return res;
  }

  nsCOMPtr<nsIUnicodeEncoder> enc;
  res = ccMan->GetUnicodeEncoder(aCharset.get(), getter_AddRefs(enc));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetUnicodeEncoder()", res);
    return res;
  }

  res = ConvertEncode(aSrc, aSrcEnd, aDest, aDestEnd, enc);
  if (NS_FAILED(res)) {
    mLog.PrintError("Convert()", res);
    return res;
  }

  res = FinishEncode(aDest, aDestEnd, enc);
  if (NS_FAILED(res)) {
    mLog.PrintError("Finish()", res);
    return res;
  }

  mLog.DelTrace(trace);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTestUConv::FinishEncode ( char **  aDest,
char *  aDestEnd,
nsIUnicodeEncoder aEncoder 
) [private]

This wraps an encoder Finish() call.

Definition at line 524 of file TestUConv.cpp.

{
  char * dest = (*aDest);
  PRInt32 destLen = aDestEnd - dest;

  nsresult res = aEncoder->Finish(dest, &destLen);

  (*aDest) = dest + destLen;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTestUConv::Main ( int  aArgC,
char **  aArgV 
)

Main method of the program.

Definition at line 541 of file TestUConv.cpp.

{
  char * trace = "Main";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  if (aArgC < 2) {
    // no arguments were passed to the program, so we just run the self tests
    res = TestCharsetManager();
    if (NS_SUCCEEDED(res)) res = TestEncoders();
    if (NS_SUCCEEDED(res)) res = TestDecoders();
  } else if (!strcmp(aArgV[1], "-tempbug")) {
    // we are testing a temporary bug
    res = TestTempBug();
  } else if (!strcmp(aArgV[1], "-display")) {
    // display all the available data
    res = DisplayDetectors();
    if (NS_SUCCEEDED(res)) res = DisplayCharsets();
  }

  mLog.DelTrace(trace);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTestUConv::PrintSpaces ( int  aCount) [private]

Definition at line 536 of file TestUConv.cpp.

{
  for (int i = 0; i < aCount; i++) printf(" ");
}

Here is the caller graph for this function:

Run the built-in set of self tests for the CharsetManager.

Definition at line 249 of file TestUConv.cpp.

{
  char * trace = "TestCharsetManager";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;
  nsAutoString name;
  nsCOMPtr<nsIAtom> csAtom;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) {
    mLog.PrintError("NS_WITH_SERVICE", res);
    return res;
  }

  mLog.DelTrace(trace);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Run the built-in set of self tests for decoders.

Definition at line 237 of file TestUConv.cpp.

{
  char * trace = "TestDecoders";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  // XXX write me

  mLog.DelTrace(trace);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Run the built-in set of self tests for encoders.

Definition at line 207 of file TestUConv.cpp.

{
  char * trace = "TestEncoders";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) return res;
  
  nsCOMPtr<nsIUTF8StringEnumerator> encoders;
  res = ccMan->GetEncoderList(getter_AddRefs(encoders));
  if (NS_FAILED(res)) return res;

  PRUint32 encoderCount=0;

  PRBool hasMore;
  encoders->HasMore(&hasMore);
  
  nsCAutoString charset;
  while (hasMore) {
    encoders->GetNext(charset);

    encoders->HasMore(&hasMore);
  }
  
  mLog.DelTrace(trace);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Run a temporary debug test.

This method is ment as a placeholder when some quick debugging is needed.

Definition at line 449 of file TestUConv.cpp.

{
  char * trace = "TestTempBug";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  NS_NAMED_LITERAL_CSTRING(charset, "ISO-2022-JP");
  PRUnichar src[] = {0x0043, 0x004e, 0x0045, 0x0054, 0x0020, 0x004A, 0x0061, 
    0x0070, 0x0061, 0x006E, 0x0020, 0x7DE8, 0x96C6, 0x5C40};
  PRUnichar * srcEnd = src + ARRAY_SIZE(src);
  char dest[BIG_BUFFER_SIZE];
  char * destEnd = dest + BIG_BUFFER_SIZE;

  PRUnichar * p = src;
  char * q = dest;
  res = Encode(&p, srcEnd, &q, destEnd, charset);

  mLog.DelTrace(trace);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 102 of file TestUConv.cpp.


The documentation for this class was generated from the following file: