зеркало из https://github.com/mozilla/pjs.git
Bug 315089 - Convert intl tests to use the XPCOM glue, r=smontagu
This commit is contained in:
Родитель
ae4d035a61
Коммит
2a4e4f05d1
|
@ -39,6 +39,9 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsICharsetDetector.h"
|
||||
#include "nsICharsetDetectionObserver.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(XP_WIN) || defined(XP_OS2)
|
||||
|
|
|
@ -42,8 +42,6 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
|
||||
REQUIRES = xpcom \
|
||||
chardet \
|
||||
$(NULL)
|
||||
|
@ -52,10 +50,12 @@ PROGRAM = DetectCharset$(BIN_SUFFIX)
|
|||
|
||||
CPPSRCS = DetectCharset.cpp
|
||||
|
||||
LIBS = $(XPCOM_LIBS) $(NSPR_LIBS)
|
||||
LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
INCLUDES += -I$(srcdir)/../public
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ VPATH = @srcdir@
|
|||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PROGRAM = TestLineBreak$(BIN_SUFFIX)
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
|
@ -51,9 +50,12 @@ REQUIRES = xpcom \
|
|||
|
||||
CPPSRCS = TestLineBreak.cpp
|
||||
|
||||
LIBS = $(XPCOM_LIBS) $(NSPR_LIBS)
|
||||
LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir)/../public
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@
|
|||
#include "nsILineBreaker.h"
|
||||
#include "nsIWordBreaker.h"
|
||||
#include "nsLWBrkCIID.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsEmbedString.h"
|
||||
|
||||
#define WORK_AROUND_SERVICE_MANAGER_ASSERT
|
||||
|
||||
|
@ -99,7 +99,7 @@ PRBool TestASCIILB(nsILineBreaker *lb,
|
|||
const char* in, const PRUint32 len,
|
||||
const PRUint32* out, PRUint32 outlen)
|
||||
{
|
||||
nsAutoString eng1; eng1.AssignWithConversion(in);
|
||||
NS_ConvertASCIItoUTF16 eng1(in);
|
||||
PRUint32 i,j;
|
||||
PRUint32 res[256];
|
||||
PRBool ok = PR_TRUE;
|
||||
|
@ -152,7 +152,7 @@ PRBool TestASCIIWB(nsIWordBreaker *lb,
|
|||
const char* in, const PRUint32 len,
|
||||
const PRUint32* out, PRUint32 outlen)
|
||||
{
|
||||
nsAutoString eng1; eng1.AssignWithConversion(in);
|
||||
NS_ConvertASCIItoUTF16 eng1(in);
|
||||
|
||||
PRUint32 i,j;
|
||||
PRUint32 res[256];
|
||||
|
@ -371,33 +371,27 @@ void SamplePrintWordWithBreak()
|
|||
CallGetService(kWBrkCID, &wbk);
|
||||
|
||||
nsAutoString result;
|
||||
nsAutoString tmp;
|
||||
|
||||
for(PRUint32 i = 0; i < numOfFragment; i++)
|
||||
{
|
||||
nsAutoString fragText; fragText.AssignWithConversion(wb[i]);
|
||||
NS_ConvertASCIItoUTF16 fragText(wb[i]);
|
||||
|
||||
PRInt32 cur = 0;
|
||||
cur = wbk->NextWord(fragText.get(), fragText.Length(), cur);
|
||||
PRUint32 start = 0;
|
||||
for(PRUint32 j = 0; cur != NS_WORDBREAKER_NEED_MORE_TEXT ; j++)
|
||||
{
|
||||
tmp.Truncate();
|
||||
fragText.Mid(tmp, start, cur - start);
|
||||
result.Append(tmp);
|
||||
result.AppendLiteral("^");
|
||||
result.Append(Substring(fragText, start, cur - start));
|
||||
result.Append('^');
|
||||
start = (cur >= 0 ? cur : cur - start);
|
||||
cur = wbk->NextWord(fragText.get(), fragText.Length(), cur);
|
||||
}
|
||||
|
||||
tmp.Truncate();
|
||||
fragText.Mid(tmp, start, fragText.Length() - start);
|
||||
result.Append(tmp);
|
||||
|
||||
result.Append(Substring(fragText, fragText.Length() - start));
|
||||
|
||||
if( i != (numOfFragment -1 ))
|
||||
{
|
||||
nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[i+1]);
|
||||
NS_ConvertASCIItoUTF16 nextFragText(wb[i+1]);
|
||||
|
||||
PRBool canBreak = PR_TRUE;
|
||||
canBreak = wbk->BreakInBetween( fragText.get(),
|
||||
|
@ -405,13 +399,13 @@ void SamplePrintWordWithBreak()
|
|||
nextFragText.get(),
|
||||
nextFragText.Length());
|
||||
if(canBreak)
|
||||
result.AppendLiteral("^");
|
||||
result.Append('^');
|
||||
|
||||
fragText = nextFragText;
|
||||
fragText.Assign(nextFragText);
|
||||
}
|
||||
}
|
||||
printf("Output From SamplePrintWordWithBreak() \n\n");
|
||||
printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get());
|
||||
printf("[%s]\n", NS_ConvertUTF16toUTF8(result).get());
|
||||
|
||||
NS_IF_RELEASE(wbk);
|
||||
}
|
||||
|
@ -423,20 +417,19 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset)
|
|||
|
||||
CallGetService(kWBrkCID, &wbk);
|
||||
|
||||
nsAutoString fragText; fragText.AssignWithConversion(wb[fragN]);
|
||||
NS_ConvertASCIItoUTF16 fragText(wb[fragN]);
|
||||
|
||||
nsAutoString result;
|
||||
nsWordRange res = wbk->FindWord(fragText.get(), fragText.Length(), offset);
|
||||
|
||||
PRBool canBreak;
|
||||
fragText.Mid(result, res.mBegin, res.mEnd-res.mBegin);
|
||||
nsAutoString result(Substring(fragText, res.mBegin, res.mEnd-res.mBegin));
|
||||
|
||||
if((PRUint32)fragText.Length() == res.mEnd) // if we hit the end of the fragment
|
||||
{
|
||||
nsAutoString curFragText = fragText;
|
||||
for(PRUint32 p = fragN +1; p < numOfFragment ;p++)
|
||||
{
|
||||
nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[p]);
|
||||
NS_ConvertASCIItoUTF16 nextFragText(wb[p]);
|
||||
canBreak = wbk->BreakInBetween(curFragText.get(),
|
||||
curFragText.Length(),
|
||||
nextFragText.get(),
|
||||
|
@ -447,14 +440,12 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset)
|
|||
nsWordRange r = wbk->FindWord(nextFragText.get(), nextFragText.Length(),
|
||||
0);
|
||||
|
||||
nsAutoString tmp;
|
||||
nextFragText.Mid(tmp,r.mBegin,r.mEnd-r.mBegin);
|
||||
result.Append(tmp);
|
||||
result.Append(Substring(nextFragText, r.mBegin, r.mEnd - r.mBegin));
|
||||
|
||||
if((PRUint32)nextFragText.Length() != r.mEnd)
|
||||
break;
|
||||
|
||||
nextFragText = curFragText;
|
||||
nextFragText.Assign(curFragText);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,7 +454,7 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset)
|
|||
nsAutoString curFragText = fragText;
|
||||
for(PRUint32 p = fragN ; p > 0 ;p--)
|
||||
{
|
||||
nsAutoString prevFragText; prevFragText.AssignWithConversion(wb[p-1]);
|
||||
NS_ConvertASCIItoUTF16 prevFragText(wb[p-1]);
|
||||
canBreak = wbk->BreakInBetween(prevFragText.get(),
|
||||
prevFragText.Length(),
|
||||
curFragText.get(),
|
||||
|
@ -474,19 +465,17 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset)
|
|||
nsWordRange r = wbk->FindWord(prevFragText.get(), prevFragText.Length(),
|
||||
prevFragText.Length());
|
||||
|
||||
nsAutoString tmp;
|
||||
prevFragText.Mid(tmp,r.mBegin,r.mEnd-r.mBegin);
|
||||
result.Insert(tmp,0);
|
||||
result.Insert(Substring(prevFragText, r.mBegin, r.mEnd - r.mBegin), 0);
|
||||
|
||||
if(0 != r.mBegin)
|
||||
break;
|
||||
|
||||
prevFragText = curFragText;
|
||||
prevFragText.Assign(curFragText);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Output From SamplePrintWordWithBreak() \n\n");
|
||||
printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get());
|
||||
printf("[%s]\n", NS_ConvertUTF16toUTF8(result).get());
|
||||
|
||||
NS_IF_RELEASE(wbk);
|
||||
}
|
||||
|
|
|
@ -42,8 +42,6 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
|
||||
CPPSRCS = StringBundleTest.cpp
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
|
@ -63,6 +61,7 @@ EXPORT_RESOURCE = \
|
|||
$(NULL)
|
||||
|
||||
LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
|
||||
$(MOZ_JS_LIBS) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include <stdio.h>
|
||||
|
@ -46,11 +45,15 @@
|
|||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsEmbedString.h"
|
||||
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
//
|
||||
#define TEST_URL "resource://gre/res/strres.properties"
|
||||
|
||||
|
@ -69,14 +72,20 @@
|
|||
nsresult
|
||||
getCountry(const nsAString &lc_name, nsAString &aCountry)
|
||||
{
|
||||
PRInt32 dash = lc_name.FindChar('-');
|
||||
if (dash > 0) {
|
||||
aCountry = lc_name;
|
||||
aCountry.Cut(dash, (lc_name.Length()-dash-1));
|
||||
const PRUnichar* data;
|
||||
PRUint32 length = NS_StringGetData(lc_name, &data);
|
||||
|
||||
PRUint32 dash;
|
||||
for (dash = 0; dash < length; ++dash) {
|
||||
if (data[dash] == '-')
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (dash == length)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
aCountry.Assign(lc_name);
|
||||
aCountry.Cut(dash, (lc_name.Length()-dash-1));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -131,9 +140,7 @@ main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
nsAutoString v;
|
||||
PRUnichar *ptrv = nsnull;
|
||||
char *value = nsnull;
|
||||
|
||||
// 123
|
||||
ret = bundle->GetStringFromID(123, &ptrv);
|
||||
|
@ -141,22 +148,17 @@ main(int argc, char *argv[])
|
|||
printf("cannot get string from ID 123, ret=%d\n", ret);
|
||||
return 1;
|
||||
}
|
||||
v = ptrv;
|
||||
value = ToNewCString(v);
|
||||
printf("123=\"%s\"\n", value);
|
||||
|
||||
printf("123=\"%s\"\n", NS_ConvertUTF16toUTF8(ptrv).get());
|
||||
|
||||
// file
|
||||
nsString strfile;
|
||||
strfile.AssignLiteral("file");
|
||||
const PRUnichar *ptrFile = strfile.get();
|
||||
ret = bundle->GetStringFromName(ptrFile, &ptrv);
|
||||
ret = bundle->GetStringFromName(NS_LITERAL_STRING("file").get(), &ptrv);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot get string from name\n");
|
||||
return 1;
|
||||
}
|
||||
v = ptrv;
|
||||
value = ToNewCString(v);
|
||||
printf("file=\"%s\"\n", value);
|
||||
|
||||
printf("file=\"%s\"\n", NS_ConvertUTF16toUTF8(ptrv).get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -71,9 +71,11 @@ endif
|
|||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
ifdef ENABLE_TESTS
|
||||
ifndef MOZ_ENABLE_LIBXUL
|
||||
TOOL_DIRS = tests
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
%{ C++
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringGlue.h"
|
||||
|
||||
|
||||
// XXX change to NS_CHARSETCONVERTERMANAGER_CID
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// {07D3D8E0-9614-11d2-B3AD-00805F8A6670}
|
||||
#define NS_ICASECONVERSION_IID \
|
||||
|
|
|
@ -43,7 +43,6 @@ VPATH = @srcdir@
|
|||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PROGRAM = UnicharSelfTest$(BIN_SUFFIX)
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
|
@ -55,6 +54,7 @@ REQUIRES = xpcom \
|
|||
CPPSRCS = UnicharSelfTest.cpp
|
||||
|
||||
LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsISupports.h"
|
||||
#include "nsXPCOM.h"
|
||||
|
@ -49,10 +50,8 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIUnicodeNormalizer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringAPI.h"
|
||||
|
||||
NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_CID);
|
||||
|
@ -402,7 +401,7 @@ static void TestEntityConversion(PRUint32 version)
|
|||
nsresult res;
|
||||
|
||||
|
||||
inString.Assign(NS_ConvertASCIItoUCS2("\xA0\xA1\xA2\xA3"));
|
||||
inString.Assign(NS_ConvertASCIItoUTF16("\xA0\xA1\xA2\xA3"));
|
||||
uChar = (PRUnichar) 8364; //euro
|
||||
inString.Append(&uChar, 1);
|
||||
uChar = (PRUnichar) 9830; //
|
||||
|
@ -411,12 +410,15 @@ static void TestEntityConversion(PRUint32 version)
|
|||
nsCOMPtr <nsIEntityConverter> entityConv = do_CreateInstance(kEntityConverterCID, &res);;
|
||||
if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n"); return;}
|
||||
|
||||
const PRUnichar *data;
|
||||
PRUint32 length = NS_StringGetData(inString, &data);
|
||||
|
||||
// convert char by char
|
||||
for (i = 0; i < inString.Length(); i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
char *entity = NULL;
|
||||
res = entityConv->ConvertToEntity(inString[i], version, &entity);
|
||||
res = entityConv->ConvertToEntity(data[i], version, &entity);
|
||||
if (NS_SUCCEEDED(res) && NULL != entity) {
|
||||
printf("%c %s\n", inString[i], entity);
|
||||
printf("%c %s\n", data[i], entity);
|
||||
nsMemory::Free(entity);
|
||||
}
|
||||
}
|
||||
|
@ -425,9 +427,9 @@ static void TestEntityConversion(PRUint32 version)
|
|||
PRUnichar *entities;
|
||||
res = entityConv->ConvertToEntities(inString.get(), version, &entities);
|
||||
if (NS_SUCCEEDED(res) && NULL != entities) {
|
||||
for (i = 0; i < nsCRT::strlen(entities); i++) {
|
||||
printf("%c", (char) entities[i]);
|
||||
if (';' == (char) entities[i])
|
||||
for (PRUnichar *centity = entities; *centity; ++centity) {
|
||||
printf("%c", (char) *centity);
|
||||
if (';' == (char) *centity)
|
||||
printf("\n");
|
||||
}
|
||||
nsMemory::Free(entities);
|
||||
|
@ -447,12 +449,15 @@ static void TestSaveAsCharset()
|
|||
nsresult res;
|
||||
|
||||
nsString inString;
|
||||
inString.Assign(NS_ConvertASCIItoUCS2("\x61\x62\x80\xA0\x63"));
|
||||
inString.Assign(NS_ConvertASCIItoUTF16("\x61\x62\x80\xA0\x63"));
|
||||
char *outString;
|
||||
|
||||
const PRUnichar *data;
|
||||
PRUint32 length = NS_StringGetData(inString, &data);
|
||||
|
||||
// first, dump input string
|
||||
for (PRUint32 i = 0; i < inString.Length(); i++) {
|
||||
printf("%c ", inString[i]);
|
||||
for (PRUint32 i = 0; i < length; i++) {
|
||||
printf("%c ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
@ -579,7 +584,7 @@ void TestNormalization()
|
|||
printf("Test 2 - NormalizeUnicode(PRUint32, const nsAString&, nsAString&):\n");
|
||||
nsAutoString resultStr;
|
||||
res = t->NormalizeUnicodeNFD(nsDependentString(normStr), resultStr);
|
||||
if (resultStr.Equals(nfdForm)) {
|
||||
if (resultStr.Equals(nsDependentString(nfdForm))) {
|
||||
printf(" Succeeded in NFD UnicodeNormalizer test. \n");
|
||||
} else {
|
||||
printf(" Failed in NFD UnicodeNormalizer test. \n");
|
||||
|
|
Загрузка…
Ссылка в новой задаче