2001-09-26 04:40:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
2002-08-12 23:16:16 +04:00
|
|
|
#include "nsUCSupport.h"
|
2000-04-22 20:36:47 +04:00
|
|
|
#include "nsString.h"
|
2003-06-11 22:16:03 +04:00
|
|
|
#include "nsIStringEnumerator.h"
|
2009-01-22 07:15:34 +03:00
|
|
|
#include "nsTArray.h"
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Global functions and data [declaration]
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(_array) (sizeof(_array) / sizeof(_array[0]))
|
|
|
|
#define SMALL_BUFFER_SIZE 512
|
|
|
|
#define MED_BUFFER_SIZE 1024
|
|
|
|
#define BIG_BUFFER_SIZE 2048
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class nsTestLog [declaration]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Logging class for test programs.
|
|
|
|
*
|
|
|
|
* This simple test program will not trigger a component registration. So
|
|
|
|
* Mozilla has to be run once before running this, so that the necessary
|
2000-09-14 03:57:52 +04:00
|
|
|
* components will be registered. Also, please observe that the ContractID's are
|
2000-04-22 20:36:47 +04:00
|
|
|
* case sensitive now!
|
|
|
|
*
|
|
|
|
* @created 28/Mar/2000
|
|
|
|
* @author Catalin Rotaru [CATA]
|
|
|
|
*/
|
|
|
|
class nsTestLog
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
static const char * kTraceDelimiter;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString mTrace;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-05-26 12:53:15 +04:00
|
|
|
void AddTrace(const char * aTrace);
|
|
|
|
void DelTrace(const char * aTrace);
|
|
|
|
void PrintError(const char * aCall, const int aError);
|
|
|
|
void PrintError(const char * aCall, const char * aMessage);
|
2000-04-22 20:36:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class nsTestUConv [declaration]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @created 28/Mar/2000
|
|
|
|
* @author Catalin Rotaru [CATA]
|
|
|
|
*/
|
|
|
|
class nsTestUConv
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
nsTestLog mLog;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the built-in set of self tests for encoders.
|
|
|
|
*/
|
|
|
|
nsresult TestEncoders();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the built-in set of self tests for decoders.
|
|
|
|
*/
|
|
|
|
nsresult TestDecoders();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the built-in set of self tests for the CharsetManager.
|
|
|
|
*/
|
|
|
|
nsresult TestCharsetManager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display charset detectors and their attributes.
|
|
|
|
*/
|
|
|
|
nsresult DisplayDetectors();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display charsets and their attributes.
|
|
|
|
*/
|
|
|
|
nsresult DisplayCharsets();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a temporary debug test. This method is ment as a placeholder when some
|
|
|
|
* quick debugging is needed.
|
|
|
|
*/
|
|
|
|
nsresult TestTempBug();
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult Encode(char16_t ** aSrc, char16_t * aSrcEnd, char ** aDest,
|
2003-06-11 22:16:03 +04:00
|
|
|
char * aDestEnd, const nsAFlatCString& aCharset);
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult ConvertEncode(char16_t ** aSrc, char16_t * aSrcEnd, char ** aDest,
|
2000-04-22 20:36:47 +04:00
|
|
|
char * aDestEnd, nsIUnicodeEncoder * aEncoder);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This wraps an encoder Finish() call.
|
|
|
|
*/
|
|
|
|
nsresult FinishEncode(char ** aDest, char * aDestEnd,
|
|
|
|
nsIUnicodeEncoder * aEncoder);
|
|
|
|
|
|
|
|
void PrintSpaces(int aCount);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main method of the program.
|
|
|
|
*/
|
|
|
|
nsresult Main(int aArgC, char ** aArgV);
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Global functions and data [implementation]
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
nsTestUConv testObj;
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
res = testObj.Main(argc, argv);
|
|
|
|
return (NS_FAILED(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class nsTestLog [implementation]
|
|
|
|
|
|
|
|
const char * nsTestLog::kTraceDelimiter = ".";
|
|
|
|
|
2009-05-26 12:53:15 +04:00
|
|
|
void nsTestLog::AddTrace(const char * aTrace)
|
2000-04-22 20:36:47 +04:00
|
|
|
{
|
|
|
|
mTrace.Append(aTrace);
|
|
|
|
mTrace.Append(kTraceDelimiter);
|
|
|
|
}
|
|
|
|
|
2009-05-26 12:53:15 +04:00
|
|
|
void nsTestLog::DelTrace(const char * aTrace)
|
2000-04-22 20:36:47 +04:00
|
|
|
{
|
|
|
|
mTrace.Truncate(mTrace.Length() - strlen(aTrace) - strlen(kTraceDelimiter));
|
|
|
|
}
|
|
|
|
|
2009-05-26 12:53:15 +04:00
|
|
|
void nsTestLog::PrintError(const char * aCall, const int aError)
|
2000-04-22 20:36:47 +04:00
|
|
|
{
|
2001-03-02 12:26:57 +03:00
|
|
|
const char * trace = mTrace.get();
|
2000-04-22 20:36:47 +04:00
|
|
|
printf("ERROR at %s%s code=0x%x.\n", trace, aCall, aError);
|
|
|
|
}
|
|
|
|
|
2009-05-26 12:53:15 +04:00
|
|
|
void nsTestLog::PrintError(const char * aCall, const char * aMessage)
|
2000-04-22 20:36:47 +04:00
|
|
|
{
|
2001-03-02 12:26:57 +03:00
|
|
|
const char * trace = mTrace.get();
|
2000-04-22 20:36:47 +04:00
|
|
|
printf("ERROR at %s%s reason: %s.\n", trace, aCall, aMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class nsTestUConv [implementation]
|
|
|
|
|
|
|
|
nsresult nsTestUConv::TestEncoders()
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "TestEncoders";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccMan =
|
2002-08-12 23:16:16 +04:00
|
|
|
do_GetService(kCharsetConverterManagerCID, &res);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> encoders;
|
2002-08-12 23:16:16 +04:00
|
|
|
res = ccMan->GetEncoderList(getter_AddRefs(encoders));
|
|
|
|
if (NS_FAILED(res)) return res;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore;
|
2003-06-11 22:16:03 +04:00
|
|
|
encoders->HasMore(&hasMore);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString charset;
|
2003-06-11 22:16:03 +04:00
|
|
|
while (hasMore) {
|
|
|
|
encoders->GetNext(charset);
|
|
|
|
|
|
|
|
encoders->HasMore(&hasMore);
|
|
|
|
}
|
2002-08-12 23:16:16 +04:00
|
|
|
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.DelTrace(trace);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::TestDecoders()
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "TestDecoders";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
|
|
|
// XXX write me
|
|
|
|
|
|
|
|
mLog.DelTrace(trace);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::TestCharsetManager()
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "TestCharsetManager";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
2003-03-25 21:55:59 +03:00
|
|
|
nsAutoString name;
|
2000-04-22 20:36:47 +04:00
|
|
|
nsCOMPtr<nsIAtom> csAtom;
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccMan =
|
2001-07-25 11:54:28 +04:00
|
|
|
do_GetService(kCharsetConverterManagerCID, &res);
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("NS_WITH_SERVICE", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLog.DelTrace(trace);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::DisplayDetectors()
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "DisplayDetectors";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccMan =
|
2001-07-25 11:54:28 +04:00
|
|
|
do_GetService(kCharsetConverterManagerCID, &res);
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("NS_WITH_SERVICE", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// charset detectors
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> detectors;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
res = ccMan->GetCharsetDetectorList(getter_AddRefs(detectors));
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("GetCharsetDetectorList()", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
printf("***** Character Set Detectors *****\n");
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore;
|
2003-06-11 22:16:03 +04:00
|
|
|
detectors->HasMore(&hasMore);
|
|
|
|
while (hasMore) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString detectorName;
|
2003-06-11 22:16:03 +04:00
|
|
|
res = detectors->GetNext(detectorName);
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
2003-06-11 22:16:03 +04:00
|
|
|
mLog.PrintError("GetNext()", res);
|
2000-04-22 20:36:47 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
printf("%s", detectorName.get());
|
|
|
|
PrintSpaces(36 - detectorName.Length()); // align to hard coded column number
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsAutoString title;
|
|
|
|
res = ccMan->GetCharsetTitle(detectorName.get(), title);
|
|
|
|
if (NS_FAILED(res)) title.SetLength(0);
|
2006-02-03 17:18:39 +03:00
|
|
|
printf("\"%s\"\n", NS_LossyConvertUTF16toASCII(title).get());
|
2005-08-22 15:15:53 +04:00
|
|
|
|
|
|
|
detectors->HasMore(&hasMore);
|
2000-04-22 20:36:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mLog.DelTrace(trace);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::DisplayCharsets()
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "DisplayCharsets";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccMan =
|
2001-07-25 11:54:28 +04:00
|
|
|
do_GetService(kCharsetConverterManagerCID, &res);
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("NS_WITH_SERVICE", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> decoders;
|
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> encoders;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
res = ccMan->GetDecoderList(getter_AddRefs(decoders));
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("GetDecoderList()", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
res = ccMan->GetEncoderList(getter_AddRefs(encoders));
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("GetEncoderList()", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
printf("***** Character Sets *****\n");
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t encCount = 0, decCount = 0;
|
|
|
|
uint32_t basicEncCount = 0, basicDecCount = 0;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
nsTArray<nsCString> allCharsets;
|
2003-06-11 22:16:03 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString charset;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore;
|
2003-06-11 22:16:03 +04:00
|
|
|
encoders->HasMore(&hasMore);
|
|
|
|
while (hasMore) {
|
|
|
|
res = encoders->GetNext(charset);
|
|
|
|
if (NS_SUCCEEDED(res))
|
2009-01-22 07:15:34 +03:00
|
|
|
allCharsets.AppendElement(charset);
|
2003-06-11 22:16:03 +04:00
|
|
|
|
|
|
|
encoders->HasMore(&hasMore);
|
|
|
|
}
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
nsAutoString prop, str;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = allCharsets.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
const nsCString& charset = allCharsets[i];
|
|
|
|
printf("%s", charset.get());
|
|
|
|
PrintSpaces(24 - charset.Length()); // align to hard coded column number
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
|
2012-08-24 11:49:00 +04:00
|
|
|
nsCOMPtr<nsIUnicodeDecoder> dec;
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetUnicodeDecoder(charset.get(), getter_AddRefs(dec));
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) printf (" ");
|
2002-08-12 23:16:16 +04:00
|
|
|
else {
|
|
|
|
printf("D");
|
|
|
|
decCount++;
|
|
|
|
}
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2002-08-12 23:16:16 +04:00
|
|
|
// show the "basic" decoder classes
|
|
|
|
if (dec) {
|
|
|
|
nsCOMPtr<nsIBasicDecoder> isBasic = do_QueryInterface(dec);
|
|
|
|
if (isBasic) {
|
|
|
|
basicDecCount++;
|
|
|
|
printf("b");
|
|
|
|
}
|
|
|
|
else printf(" ");
|
|
|
|
}
|
|
|
|
else printf(" ");
|
|
|
|
#endif
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2012-08-24 11:49:00 +04:00
|
|
|
nsCOMPtr<nsIUnicodeEncoder> enc;
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetUnicodeEncoder(charset.get(), getter_AddRefs(enc));
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) printf (" ");
|
2002-08-12 23:16:16 +04:00
|
|
|
else {
|
|
|
|
printf("E");
|
|
|
|
encCount++;
|
|
|
|
}
|
2000-04-22 20:36:47 +04:00
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2002-08-12 23:16:16 +04:00
|
|
|
if (enc) {
|
|
|
|
nsCOMPtr<nsIBasicEncoder> isBasic = do_QueryInterface(enc);
|
|
|
|
if (isBasic) {
|
|
|
|
basicEncCount++;
|
|
|
|
printf("b");
|
|
|
|
}
|
|
|
|
else printf(" ");
|
|
|
|
}
|
|
|
|
else printf(" ");
|
|
|
|
#endif
|
|
|
|
|
2000-04-22 20:36:47 +04:00
|
|
|
printf(" ");
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
prop.AssignLiteral(".notForBrowser");
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetCharsetData(charset.get(), prop.get(), str);
|
2012-08-24 11:49:00 +04:00
|
|
|
if (dec && (NS_FAILED(res))) printf ("B");
|
2000-04-22 20:36:47 +04:00
|
|
|
else printf("X");
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
prop.AssignLiteral(".notForComposer");
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetCharsetData(charset.get(), prop.get(), str);
|
2012-08-24 11:49:00 +04:00
|
|
|
if (enc && (NS_FAILED(res))) printf ("C");
|
2000-04-22 20:36:47 +04:00
|
|
|
else printf("X");
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
prop.AssignLiteral(".notForMailView");
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetCharsetData(charset.get(), prop.get(), str);
|
2012-08-24 11:49:00 +04:00
|
|
|
if (dec && (NS_FAILED(res))) printf ("V");
|
2000-04-22 20:36:47 +04:00
|
|
|
else printf("X");
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
prop.AssignLiteral(".notForMailEdit");
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetCharsetData(charset.get(), prop.get(), str);
|
2012-08-24 11:49:00 +04:00
|
|
|
if (enc && (NS_FAILED(res))) printf ("E");
|
2000-04-22 20:36:47 +04:00
|
|
|
else printf("X");
|
|
|
|
|
2002-08-12 23:16:16 +04:00
|
|
|
printf("(%3d, %3d) ", encCount, decCount);
|
2009-01-22 07:15:34 +03:00
|
|
|
res = ccMan->GetCharsetTitle(charset.get(), str);
|
2002-08-12 23:16:16 +04:00
|
|
|
if (NS_FAILED(res)) str.SetLength(0);
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_LossyConvertUTF16toASCII buff2(str);
|
2002-08-12 23:16:16 +04:00
|
|
|
printf(" \"%s\"\n", buff2.get());
|
2000-04-22 20:36:47 +04:00
|
|
|
}
|
|
|
|
|
2002-08-12 23:16:16 +04:00
|
|
|
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);
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.DelTrace(trace);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::TestTempBug()
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "TestTempBug";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
NS_NAMED_LITERAL_CSTRING(charset, "ISO-2022-JP");
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t src[] = {0x0043, 0x004e, 0x0045, 0x0054, 0x0020, 0x004A, 0x0061,
|
2000-04-22 20:36:47 +04:00
|
|
|
0x0070, 0x0061, 0x006E, 0x0020, 0x7DE8, 0x96C6, 0x5C40};
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t * srcEnd = src + ARRAY_SIZE(src);
|
2000-04-22 20:36:47 +04:00
|
|
|
char dest[BIG_BUFFER_SIZE];
|
|
|
|
char * destEnd = dest + BIG_BUFFER_SIZE;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t * p = src;
|
2000-04-22 20:36:47 +04:00
|
|
|
char * q = dest;
|
2003-06-11 22:16:03 +04:00
|
|
|
res = Encode(&p, srcEnd, &q, destEnd, charset);
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
mLog.DelTrace(trace);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsTestUConv::Encode(char16_t ** aSrc, char16_t * aSrcEnd,
|
2000-04-22 20:36:47 +04:00
|
|
|
char ** aDest, char * aDestEnd,
|
2003-06-11 22:16:03 +04:00
|
|
|
const nsAFlatCString& aCharset)
|
2000-04-22 20:36:47 +04:00
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "Encode";
|
2000-04-22 20:36:47 +04:00
|
|
|
mLog.AddTrace(trace);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccMan =
|
|
|
|
do_GetService(kCharsetConverterManagerCID, &res);
|
2000-04-22 20:36:47 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
mLog.PrintError("NS_WITH_SERVICE", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUnicodeEncoder> enc;
|
2003-06-11 22:16:03 +04:00
|
|
|
res = ccMan->GetUnicodeEncoder(aCharset.get(), getter_AddRefs(enc));
|
2000-04-22 20:36:47 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsTestUConv::ConvertEncode(char16_t ** aSrc, char16_t * aSrcEnd,
|
2000-04-22 20:36:47 +04:00
|
|
|
char ** aDest, char * aDestEnd,
|
|
|
|
nsIUnicodeEncoder * aEncoder)
|
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t * src = (*aSrc);
|
2000-04-22 20:36:47 +04:00
|
|
|
char * dest = (*aDest);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t srcLen = aSrcEnd - src;
|
|
|
|
int32_t destLen = aDestEnd - dest;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
nsresult res = aEncoder->Convert(src, &srcLen, dest, &destLen);
|
|
|
|
|
|
|
|
(*aSrc) = src + srcLen;
|
|
|
|
(*aDest) = dest + destLen;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::FinishEncode(char ** aDest, char * aDestEnd,
|
|
|
|
nsIUnicodeEncoder * aEncoder)
|
|
|
|
{
|
|
|
|
char * dest = (*aDest);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t destLen = aDestEnd - dest;
|
2000-04-22 20:36:47 +04:00
|
|
|
|
|
|
|
nsresult res = aEncoder->Finish(dest, &destLen);
|
|
|
|
|
|
|
|
(*aDest) = dest + destLen;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTestUConv::PrintSpaces(int aCount)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < aCount; i++) printf(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTestUConv::Main(int aArgC, char ** aArgV)
|
|
|
|
{
|
2009-05-26 12:53:15 +04:00
|
|
|
const char * trace = "Main";
|
2000-04-22 20:36:47 +04:00
|
|
|
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;
|
|
|
|
}
|