Bug 208314 - remove use of iostreams to allow building with compilers

that don't support classic C++ iostreams (ex: MSVC++ .net 2003).
r=timeless, sr=dbaron
This commit is contained in:
tor@cs.brown.edu
2004-02-07 02:41:10 +00:00
parent 9fab3d8f5a
commit d2cd2d16c7
18 changed files with 731 additions and 732 deletions

View File

@@ -325,8 +325,8 @@ case "$target" in
AC_MSG_ERROR([\$(CC) test failed. You must have MS VC++ in your path to build.]) ) AC_MSG_ERROR([\$(CC) test failed. You must have MS VC++ in your path to build.]) )
AC_LANG_CPLUSPLUS AC_LANG_CPLUSPLUS
AC_TRY_COMPILE([#include <iostream.h>], AC_TRY_COMPILE([#include <new.h>],
[ cout << "Hello World" << endl; ],, [ unsigned *test = new unsigned(42); ],,
AC_MSG_ERROR([\$(CXX) test failed. You must have MS VC++ in your path to build.]) ) AC_MSG_ERROR([\$(CXX) test failed. You must have MS VC++ in your path to build.]) )
AC_LANG_RESTORE AC_LANG_RESTORE

View File

@@ -62,7 +62,6 @@ MODULE_NAME = TransformiixModule
CPPSRCS = XSLTProcessorModule.cpp CPPSRCS = XSLTProcessorModule.cpp
LOBJS = ../source/base/Double.$(OBJ_SUFFIX) \ LOBJS = ../source/base/Double.$(OBJ_SUFFIX) \
../source/base/List.$(OBJ_SUFFIX) \ ../source/base/List.$(OBJ_SUFFIX) \
../source/base/SimpleErrorObserver.$(OBJ_SUFFIX) \
../source/base/txAtoms.$(OBJ_SUFFIX) \ ../source/base/txAtoms.$(OBJ_SUFFIX) \
../source/base/txExpandedNameMap.$(OBJ_SUFFIX) \ ../source/base/txExpandedNameMap.$(OBJ_SUFFIX) \
../source/base/txNamespaceMap.$(OBJ_SUFFIX) \ ../source/base/txNamespaceMap.$(OBJ_SUFFIX) \

View File

@@ -44,13 +44,16 @@ endif
CPPSRCS = Double.cpp \ CPPSRCS = Double.cpp \
List.cpp \ List.cpp \
SimpleErrorObserver.cpp \
txAtoms.cpp \ txAtoms.cpp \
txExpandedNameMap.cpp \ txExpandedNameMap.cpp \
txNamespaceMap.cpp \ txNamespaceMap.cpp \
txURIUtils.cpp \ txURIUtils.cpp \
txStringUtils.cpp txStringUtils.cpp
ifdef TX_EXE
CPPSRCS += SimpleErrorObserver.cpp
endif
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../xpath -I$(srcdir)/../xslt -I$(srcdir)/../xml \ INCLUDES += -I$(srcdir)/../xpath -I$(srcdir)/../xslt -I$(srcdir)/../xml \

View File

@@ -36,7 +36,6 @@
* the terms of any one of the NPL, the GPL or the LGPL. * the terms of any one of the NPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsICharsetDetector.h" #include "nsICharsetDetector.h"

View File

@@ -36,7 +36,6 @@
* the terms of any one of the NPL, the GPL or the LGPL. * the terms of any one of the NPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsICharsetDetector.h" #include "nsICharsetDetector.h"

View File

@@ -36,7 +36,7 @@
* the terms of any one of the NPL, the GPL or the LGPL. * the terms of any one of the NPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h> #include <stdio.h>
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsISupports.h" #include "nsISupports.h"
@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
nsMemory::Free(charsetUni); nsMemory::Free(charsetUni);
if (NULL != tempCstr) { if (NULL != tempCstr) {
cout << csid << " " << tempCstr << "\n"; printf("%us %s\n", csid, tempCstr);
delete [] tempCstr; delete [] tempCstr;
} }
} }

View File

@@ -37,7 +37,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
@@ -115,22 +115,22 @@ static nsresult CreateCollationKey(nsICollation *t, nsCollationStrength strength
// create a raw collation key // create a raw collation key
res = t->GetSortKeyLen(strength, stringIn, keyLength); res = t->GetSortKeyLen(strength, stringIn, keyLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
*aKey = (PRUint8 *) new PRUint8[*keyLength]; *aKey = (PRUint8 *) new PRUint8[*keyLength];
if (NULL == *aKey) { if (NULL == *aKey) {
cout << "\tFailed!! memory allocation failed.\n"; printf("\tFailed!! memory allocation failed.\n");
} }
res = t->CreateRawSortKey(strength, stringIn, *aKey, keyLength); res = t->CreateRawSortKey(strength, stringIn, *aKey, keyLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
// create a key in nsString // create a key in nsString
nsString aKeyString; nsString aKeyString;
res = t->CreateSortKey(strength, stringIn, aKeyString); res = t->CreateSortKey(strength, stringIn, aKeyString);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
// compare the generated key // compare the generated key
@@ -141,14 +141,14 @@ static nsresult CreateCollationKey(nsICollation *t, nsCollationStrength strength
return res; return res;
} }
static void DebugDump(nsString& aString, ostream& aStream) { static void DebugDump(nsString& aString) {
#ifdef WIN32 #ifdef WIN32
char s[512]; char s[512];
int len = WideCharToMultiByte(GetACP(), 0, int len = WideCharToMultiByte(GetACP(), 0,
(LPCWSTR ) aString.get(), aString.Length(), (LPCWSTR ) aString.get(), aString.Length(),
s, 512, NULL, NULL); s, 512, NULL, NULL);
s[len] = '\0'; s[len] = '\0';
aStream.flush(); fflush(stdout);
printf("%s\n", s); printf("%s\n", s);
#elif defined(XP_MAC) || defined(XP_MACOSX) #elif defined(XP_MAC) || defined(XP_MACOSX)
// Use TEC (Text Encoding Conversion Manager) // Use TEC (Text Encoding Conversion Manager)
@@ -165,13 +165,13 @@ static void DebugDump(nsString& aString, ostream& aStream) {
err = TECDisposeConverter(anEncodingConverter); err = TECDisposeConverter(anEncodingConverter);
oOutputStr[oOutputLen] = '\0'; oOutputStr[oOutputLen] = '\0';
aStream.flush(); fflush(NULL);
printf("%s\n", oOutputStr); printf("%s\n", oOutputStr);
#else #else
for (int i = 0; i < aString.Length(); i++) { for (int i = 0; i < aString.Length(); i++) {
aStream << (char) aString[i]; putchar((char) aString[i]);
} }
aStream << "\n"; printf("\n");
#endif #endif
} }
@@ -184,18 +184,18 @@ static void TestCollation(nsILocale *locale)
nsICollation *t = NULL; nsICollation *t = NULL;
nsresult res; nsresult res;
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsICollation Test \n"; printf("Start nsICollation Test \n");
cout << "==============================\n"; printf("==============================\n");
res = nsComponentManager::CreateInstance(kCollationFactoryCID, res = nsComponentManager::CreateInstance(kCollationFactoryCID,
NULL, NULL,
NS_GET_IID(nsICollationFactory), NS_GET_IID(nsICollationFactory),
(void**) &f); (void**) &f);
cout << "Test 1 - CreateInstance():\n"; printf("Test 1 - CreateInstance():\n");
if(NS_FAILED(res) || ( f == NULL ) ) { if(NS_FAILED(res) || ( f == NULL ) ) {
cout << "\t1st CreateInstance failed\n"; printf("\t1st CreateInstance failed\n");
} else { } else {
f->Release(); f->Release();
} }
@@ -205,13 +205,13 @@ static void TestCollation(nsILocale *locale)
NS_GET_IID(nsICollationFactory), NS_GET_IID(nsICollationFactory),
(void**) &f); (void**) &f);
if(NS_FAILED(res) || ( f == NULL ) ) { if(NS_FAILED(res) || ( f == NULL ) ) {
cout << "\t2nd CreateInstance failed\n"; printf("\t2nd CreateInstance failed\n");
} }
res = f->CreateCollation(locale, &t); res = f->CreateCollation(locale, &t);
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\tCreateCollation failed\n"; printf("\tCreateCollation failed\n");
} else { } else {
nsString string1("abcde"); nsString string1("abcde");
nsString string2("ABCDE"); nsString string2("ABCDE");
@@ -222,93 +222,93 @@ static void TestCollation(nsILocale *locale)
PRUint32 i; PRUint32 i;
PRInt32 result; PRInt32 result;
cout << "String data used:\n"; printf("String data used:\n");
cout << "string1: "; printf("string1: ");
DebugDump(string1, cout); DebugDump(string1);
cout << "string2: "; printf("string2: ");
DebugDump(string2, cout); DebugDump(string2);
cout << "string3: "; printf("string3: ");
DebugDump(string3, cout); DebugDump(string3);
cout << "string4: "; printf("string4: ");
DebugDump(string4, cout); DebugDump(string4);
cout << "Test 2 - CompareString():\n"; printf("Test 2 - CompareString():\n");
res = t->CompareString(kCollationCaseInSensitive, string1, string2, &result); res = t->CompareString(kCollationCaseInSensitive, string1, string2, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case insensitive comparison (string1 vs string2): " << result << "\n"; printf("case insensitive comparison (string1 vs string2): %d\n", result);
res = t->CompareString(kCollationCaseSensitive, string1, string2, &result); res = t->CompareString(kCollationCaseSensitive, string1, string2, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case sensitive comparison (string1 vs string2): " << result << "\n"; printf("case sensitive comparison (string1 vs string2): %d\n", result);
cout << "Test 3 - GetSortKeyLen():\n"; printf("Test 3 - GetSortKeyLen():\n");
res = t->GetSortKeyLen(kCollationCaseSensitive, string2, &keyLength1); res = t->GetSortKeyLen(kCollationCaseSensitive, string2, &keyLength1);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "keyLength: " << keyLength1 << "\n"; printf("keyLength: %d\n", keyLength1);
cout << "Test 4 - CreateRawSortKey():\n"; printf("Test 4 - CreateRawSortKey():\n");
aKey1 = (PRUint8 *) new PRUint8[keyLength1]; aKey1 = (PRUint8 *) new PRUint8[keyLength1];
if (NULL == aKey1) { if (NULL == aKey1) {
cout << "\tFailed!! memory allocation failed.\n"; printf("\tFailed!! memory allocation failed.\n");
} }
res = t->CreateRawSortKey(kCollationCaseSensitive, string2, aKey1, &keyLength1); res = t->CreateRawSortKey(kCollationCaseSensitive, string2, aKey1, &keyLength1);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case sensitive key creation:\n"; printf("case sensitive key creation:\n");
cout << "keyLength: " << keyLength1 << "\n"; printf("keyLength: %d\n", keyLength1);
DebugDump(string2, cout); DebugDump(string2);
cout.flush(); fflush(NULL);
for (i = 0; i < keyLength1; i++) { for (i = 0; i < keyLength1; i++) {
printf("%.2x ", aKey1[i]); printf("%.2x ", aKey1[i]);
//cout << "key[" << i << "]: " << aKey1[i] << " "; //printf("key[" << i << "]: " << aKey1[i] << " ");
} }
cout << "\n"; printf("\n");
res = CreateCollationKey(t, kCollationCaseInSensitive, string2, &aKey2, &keyLength2); res = CreateCollationKey(t, kCollationCaseInSensitive, string2, &aKey2, &keyLength2);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case insensitive key creation:\n"; printf("case insensitive key creation:\n");
cout << "keyLength: " << keyLength2 << "\n"; printf("keyLength: %d\n", keyLength2);
DebugDump(string2, cout); DebugDump(string2);
cout.flush(); fflush(NULL);
for (i = 0; i < keyLength2; i++) { for (i = 0; i < keyLength2; i++) {
printf("%.2x ", aKey2[i]); printf("%.2x ", aKey2[i]);
//cout << "key[" << i << "]: " << aKey2[i] << " "; //printf("key[" << i << "]: " << aKey2[i] << " ");
} }
cout << "\n"; printf("\n");
cout << "Test 5 - CompareRawSortKey():\n"; printf("Test 5 - CompareRawSortKey():\n");
res = CreateCollationKey(t, kCollationCaseSensitive, string1, &aKey3, &keyLength3); res = CreateCollationKey(t, kCollationCaseSensitive, string1, &aKey3, &keyLength3);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
res = t->CompareRawSortKey(aKey1, keyLength1, aKey3, keyLength3, &result); res = t->CompareRawSortKey(aKey1, keyLength1, aKey3, keyLength3, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case sensitive comparison (string1 vs string2): " << result << "\n"; printf("case sensitive comparison (string1 vs string2): %d\n", result);
res = t->CompareRawSortKey(aKey3, keyLength3, aKey1, keyLength1, &result); res = t->CompareRawSortKey(aKey3, keyLength3, aKey1, keyLength1, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case sensitive comparison (string2 vs string1): " << result << "\n"; printf("case sensitive comparison (string2 vs string1): %d\n", result);
res = t->CompareRawSortKey(aKey2, keyLength2, aKey3, keyLength3, &result); res = t->CompareRawSortKey(aKey2, keyLength2, aKey3, keyLength3, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case insensitive comparison (string1 vs string2): " << result << "\n"; printf("case insensitive comparison (string1 vs string2): %d\n", result);
if (NULL != aKey1) if (NULL != aKey1)
delete[] aKey1; delete[] aKey1;
@@ -319,26 +319,26 @@ static void TestCollation(nsILocale *locale)
res = CreateCollationKey(t, kCollationCaseSensitive, string1, &aKey1, &keyLength1); res = CreateCollationKey(t, kCollationCaseSensitive, string1, &aKey1, &keyLength1);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
res = CreateCollationKey(t, kCollationCaseSensitive, string3, &aKey2, &keyLength2); res = CreateCollationKey(t, kCollationCaseSensitive, string3, &aKey2, &keyLength2);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
res = CreateCollationKey(t, kCollationCaseSensitive, string4, &aKey3, &keyLength3); res = CreateCollationKey(t, kCollationCaseSensitive, string4, &aKey3, &keyLength3);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
res = t->CompareRawSortKey(aKey1, keyLength1, aKey2, keyLength2, &result); res = t->CompareRawSortKey(aKey1, keyLength1, aKey2, keyLength2, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case sensitive comparison (string1 vs string3): " << result << "\n"; printf("case sensitive comparison (string1 vs string3): %d\n", result);
res = t->CompareRawSortKey(aKey1, keyLength1, aKey3, keyLength3, &result); res = t->CompareRawSortKey(aKey1, keyLength1, aKey3, keyLength3, &result);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
cout << "case sensitive comparison (string1 vs string4): " << result << "\n"; printf("case sensitive comparison (string1 vs string4): %d\n", result);
if (NULL != aKey1) if (NULL != aKey1)
delete[] aKey1; delete[] aKey1;
@@ -351,9 +351,9 @@ static void TestCollation(nsILocale *locale)
res = f->Release(); res = f->Release();
} }
cout << "==============================\n"; printf("==============================\n");
cout << "Finish nsICollation Test \n"; printf("Finish nsICollation Test \n");
cout << "==============================\n"; printf("==============================\n");
} }
@@ -368,9 +368,9 @@ static void TestSortPrint1(nsString *string_array, int len)
{ {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
//string_array[i].DebugDump(cout); //string_array[i].DebugDump(cout);
DebugDump(string_array[i], cout); DebugDump(string_array[i]);
} }
cout << "\n"; printf("\n");
} }
static void TestSortPrintToFile(nsString *string_array, int len) static void TestSortPrintToFile(nsString *string_array, int len)
@@ -420,20 +420,20 @@ static void DebugPrintCompResult(const nsString& string1, const nsString& string
printf(" %s\n", s); printf(" %s\n", s);
#else #else
// Warning: casting to char* // Warning: casting to char*
cout << NS_LossyConvertUCS2toASCII(string1).get() << ' '; printf(NS_LossyConvertUCS2toASCII(string1).get() << ' ');
switch ((int)result) { switch ((int)result) {
case 0: case 0:
cout << "=="; printf("==");
break; break;
case 1: case 1:
cout << '>'; printf('>');
break; break;
case -1: case -1:
cout << '<'; printf('<');
break; break;
} }
cout << ' ' << NS_LossyConvertUCS2toASCII(string2).get() << '\n'; printf(' ' << NS_LossyConvertUCS2toASCII(string2).get() << '\n');
#endif #endif
} }
@@ -501,7 +501,7 @@ static void TestSortPrint2(collation_rec *key_array, int len)
PRUint32 aLength; PRUint32 aLength;
PRUint8 *aKey; PRUint8 *aKey;
cout.flush(); fflush(NULL);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
aLength = key_array[i].aLength; aLength = key_array[i].aLength;
aKey = key_array[i].aKey; aKey = key_array[i].aKey;
@@ -544,13 +544,13 @@ static void SortTestFile(nsICollation* collationInst, FILE* fp)
#endif #endif
i++; i++;
} }
cout << "print string before sort\n"; printf("print string before sort\n");
TestSortPrint1(string_array, i); TestSortPrint1(string_array, i);
g_collationInst = collationInst; g_collationInst = collationInst;
qsort( (void *)string_array, i, sizeof(nsString), compare1 ); qsort( (void *)string_array, i, sizeof(nsString), compare1 );
cout << "print string after sort\n"; printf("print string after sort\n");
(g_outfp == NULL) ? TestSortPrint1(string_array, i) : TestSortPrintToFile(string_array, i); (g_outfp == NULL) ? TestSortPrint1(string_array, i) : TestSortPrintToFile(string_array, i);
} }
@@ -573,21 +573,21 @@ static void TestSort(nsILocale *locale, nsCollationStrength collationStrength, F
nsString string5("AAC"); nsString string5("AAC");
nsString string_array[5]; nsString string_array[5];
cout << "==============================\n"; printf("==============================\n");
cout << "Start sort Test \n"; printf("Start sort Test \n");
cout << "==============================\n"; printf("==============================\n");
res = nsComponentManager::CreateInstance(kCollationFactoryCID, res = nsComponentManager::CreateInstance(kCollationFactoryCID,
NULL, NULL,
NS_GET_IID(nsICollationFactory), NS_GET_IID(nsICollationFactory),
(void**) &factoryInst); (void**) &factoryInst);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
res = factoryInst->CreateCollation(locale, &collationInst); res = factoryInst->CreateCollation(locale, &collationInst);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
// set collation strength // set collation strength
@@ -601,16 +601,16 @@ static void TestSort(nsILocale *locale, nsCollationStrength collationStrength, F
return; return;
} }
cout << "==============================\n"; printf("==============================\n");
cout << "Sort Test by comparestring.\n"; printf("Sort Test by comparestring.\n");
cout << "==============================\n"; printf("==============================\n");
string_array[0] = string1; string_array[0] = string1;
string_array[1] = string2; string_array[1] = string2;
string_array[2] = string3; string_array[2] = string3;
string_array[3] = string4; string_array[3] = string4;
string_array[4] = string5; string_array[4] = string5;
cout << "print string before sort\n"; printf("print string before sort\n");
TestSortPrint1(string_array, 5); TestSortPrint1(string_array, 5);
g_collationInst = collationInst; g_collationInst = collationInst;
@@ -618,50 +618,50 @@ static void TestSort(nsILocale *locale, nsCollationStrength collationStrength, F
qsort( (void *)string_array, 5, sizeof(nsString), compare1 ); qsort( (void *)string_array, 5, sizeof(nsString), compare1 );
res = collationInst->Release(); res = collationInst->Release();
cout << "print string after sort\n"; printf("print string after sort\n");
TestSortPrint1(string_array, 5); TestSortPrint1(string_array, 5);
cout << "==============================\n"; printf("==============================\n");
cout << "Sort Test by collation key.\n"; printf("Sort Test by collation key.\n");
cout << "==============================\n"; printf("==============================\n");
res = CreateCollationKey(collationInst, strength, string1, &aKey, &aLength); res = CreateCollationKey(collationInst, strength, string1, &aKey, &aLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
key_array[0].aKey = aKey; key_array[0].aKey = aKey;
key_array[0].aLength = aLength; key_array[0].aLength = aLength;
res = CreateCollationKey(collationInst, strength, string2, &aKey, &aLength); res = CreateCollationKey(collationInst, strength, string2, &aKey, &aLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
key_array[1].aKey = aKey; key_array[1].aKey = aKey;
key_array[1].aLength = aLength; key_array[1].aLength = aLength;
res = CreateCollationKey(collationInst, strength, string3, &aKey, &aLength); res = CreateCollationKey(collationInst, strength, string3, &aKey, &aLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
key_array[2].aKey = aKey; key_array[2].aKey = aKey;
key_array[2].aLength = aLength; key_array[2].aLength = aLength;
res = CreateCollationKey(collationInst, strength, string4, &aKey, &aLength); res = CreateCollationKey(collationInst, strength, string4, &aKey, &aLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
key_array[3].aKey = aKey; key_array[3].aKey = aKey;
key_array[3].aLength = aLength; key_array[3].aLength = aLength;
res = CreateCollationKey(collationInst, strength, string5, &aKey, &aLength); res = CreateCollationKey(collationInst, strength, string5, &aKey, &aLength);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} }
key_array[4].aKey = aKey; key_array[4].aKey = aKey;
key_array[4].aLength = aLength; key_array[4].aLength = aLength;
cout << "print key before sort\n"; printf("print key before sort\n");
TestSortPrint2(key_array, 5); TestSortPrint2(key_array, 5);
g_collationInst = collationInst; g_collationInst = collationInst;
@@ -669,7 +669,7 @@ static void TestSort(nsILocale *locale, nsCollationStrength collationStrength, F
qsort( (void *)key_array, 5, sizeof(collation_rec), compare2 ); qsort( (void *)key_array, 5, sizeof(collation_rec), compare2 );
res = collationInst->Release(); res = collationInst->Release();
cout << "print key after sort\n"; printf("print key after sort\n");
TestSortPrint2(key_array, 5); TestSortPrint2(key_array, 5);
@@ -681,9 +681,9 @@ static void TestSort(nsILocale *locale, nsCollationStrength collationStrength, F
delete [] key_array[i].aKey; delete [] key_array[i].aKey;
} }
cout << "==============================\n"; printf("==============================\n");
cout << "Finish sort Test \n"; printf("Finish sort Test \n");
cout << "==============================\n"; printf("==============================\n");
} }
// Test all functions in nsIDateTimeFormat. // Test all functions in nsIDateTimeFormat.
@@ -692,9 +692,9 @@ static void TestDateTimeFormat(nsILocale *locale)
{ {
nsresult res; nsresult res;
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsIScriptableDateFormat Test \n"; printf("Start nsIScriptableDateFormat Test \n");
cout << "==============================\n"; printf("==============================\n");
nsIScriptableDateFormat *aScriptableDateFormat; nsIScriptableDateFormat *aScriptableDateFormat;
res = nsComponentManager::CreateInstance(kDateTimeFormatCID, res = nsComponentManager::CreateInstance(kDateTimeFormatCID,
@@ -702,7 +702,7 @@ static void TestDateTimeFormat(nsILocale *locale)
NS_GET_IID(nsIScriptableDateFormat), NS_GET_IID(nsIScriptableDateFormat),
(void**) &aScriptableDateFormat); (void**) &aScriptableDateFormat);
if(NS_FAILED(res) || ( aScriptableDateFormat == NULL ) ) { if(NS_FAILED(res) || ( aScriptableDateFormat == NULL ) ) {
cout << "\tnsIScriptableDateFormat CreateInstance failed\n"; printf("\tnsIScriptableDateFormat CreateInstance failed\n");
} }
PRUnichar *aUnichar; PRUnichar *aUnichar;
@@ -718,7 +718,7 @@ static void TestDateTimeFormat(nsILocale *locale)
58, 58,
&aUnichar); &aUnichar);
aString.SetString(aUnichar); aString.SetString(aUnichar);
DebugDump(aString, cout); DebugDump(aString);
res = aScriptableDateFormat->FormatDate(aLocaleUnichar, kDateFormatLong, res = aScriptableDateFormat->FormatDate(aLocaleUnichar, kDateFormatLong,
1970, 1970,
@@ -726,7 +726,7 @@ static void TestDateTimeFormat(nsILocale *locale)
20, 20,
&aUnichar); &aUnichar);
aString.SetString(aUnichar); aString.SetString(aUnichar);
DebugDump(aString, cout); DebugDump(aString);
res = aScriptableDateFormat->FormatTime(aLocaleUnichar, kTimeFormatSecondsForce24Hour, res = aScriptableDateFormat->FormatTime(aLocaleUnichar, kTimeFormatSecondsForce24Hour,
13, 13,
@@ -734,13 +734,13 @@ static void TestDateTimeFormat(nsILocale *locale)
31, 31,
&aUnichar); &aUnichar);
aString.SetString(aUnichar); aString.SetString(aUnichar);
DebugDump(aString, cout); DebugDump(aString);
aScriptableDateFormat->Release(); aScriptableDateFormat->Release();
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsIDateTimeFormat Test \n"; printf("Start nsIDateTimeFormat Test \n");
cout << "==============================\n"; printf("==============================\n");
nsIDateTimeFormat *t = NULL; nsIDateTimeFormat *t = NULL;
res = nsComponentManager::CreateInstance(kDateTimeFormatCID, res = nsComponentManager::CreateInstance(kDateTimeFormatCID,
@@ -748,9 +748,9 @@ static void TestDateTimeFormat(nsILocale *locale)
NS_GET_IID(nsIDateTimeFormat), NS_GET_IID(nsIDateTimeFormat),
(void**) &t); (void**) &t);
cout << "Test 1 - CreateInstance():\n"; printf("Test 1 - CreateInstance():\n");
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t1st CreateInstance failed\n"; printf("\t1st CreateInstance failed\n");
} else { } else {
t->Release(); t->Release();
} }
@@ -761,7 +761,7 @@ static void TestDateTimeFormat(nsILocale *locale)
(void**) &t); (void**) &t);
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t2nd CreateInstance failed\n"; printf("\t2nd CreateInstance failed\n");
} else { } else {
} }
@@ -771,73 +771,73 @@ static void TestDateTimeFormat(nsILocale *locale)
time_t timetTime; time_t timetTime;
cout << "Test 2 - FormatTime():\n"; printf("Test 2 - FormatTime():\n");
time( &timetTime ); time( &timetTime );
res = t->FormatTime(locale, kDateFormatShort, kTimeFormatSeconds, timetTime, dateString); res = t->FormatTime(locale, kDateFormatShort, kTimeFormatSeconds, timetTime, dateString);
DebugDump(dateString, cout); DebugDump(dateString);
cout << "Test 3 - FormatTMTime():\n"; printf("Test 3 - FormatTMTime():\n");
time_t ltime; time_t ltime;
time( &ltime ); time( &ltime );
// try (almost) all format combination // try (almost) all format combination
res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatNone, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatNone, localtime( &ltime ), dateString);
cout << "kDateFormatNone, kTimeFormatNone:\n"; printf("kDateFormatNone, kTimeFormatNone:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatNone, kTimeFormatSeconds:\n"; printf("kDateFormatNone, kTimeFormatSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatNoSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatNone, kTimeFormatNoSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatNone, kTimeFormatNoSeconds:\n"; printf("kDateFormatNone, kTimeFormatNoSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatNone, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatNone, localtime( &ltime ), dateString);
cout << "kDateFormatLong, kTimeFormatNone:\n"; printf("kDateFormatLong, kTimeFormatNone:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatLong, kTimeFormatSeconds:\n"; printf("kDateFormatLong, kTimeFormatSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatNoSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatLong, kTimeFormatNoSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatLong, kTimeFormatNoSeconds:\n"; printf("kDateFormatLong, kTimeFormatNoSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatNone, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatNone, localtime( &ltime ), dateString);
cout << "kDateFormatShort, kTimeFormatNone:\n"; printf("kDateFormatShort, kTimeFormatNone:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatShort, kTimeFormatSeconds:\n"; printf("kDateFormatShort, kTimeFormatSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatNoSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatShort, kTimeFormatNoSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatShort, kTimeFormatNoSeconds:\n"; printf("kDateFormatShort, kTimeFormatNoSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatNone, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatNone, localtime( &ltime ), dateString);
cout << "kDateFormatYearMonth, kTimeFormatNone:\n"; printf("kDateFormatYearMonth, kTimeFormatNone:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatYearMonth, kTimeFormatSeconds:\n"; printf("kDateFormatYearMonth, kTimeFormatSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatNoSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatYearMonth, kTimeFormatNoSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatYearMonth, kTimeFormatNoSeconds:\n"; printf("kDateFormatYearMonth, kTimeFormatNoSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNone, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNone, localtime( &ltime ), dateString);
cout << "kDateFormatWeekday, kTimeFormatNone:\n"; printf("kDateFormatWeekday, kTimeFormatNone:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatWeekday, kTimeFormatSeconds:\n"; printf("kDateFormatWeekday, kTimeFormatSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNoSeconds, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNoSeconds, localtime( &ltime ), dateString);
cout << "kDateFormatWeekday, kTimeFormatNoSeconds:\n"; printf("kDateFormatWeekday, kTimeFormatNoSeconds:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatSecondsForce24Hour, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatSecondsForce24Hour, localtime( &ltime ), dateString);
cout << "kDateFormatWeekday, kTimeFormatSecondsForce24Hour:\n"; printf("kDateFormatWeekday, kTimeFormatSecondsForce24Hour:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNoSecondsForce24Hour, localtime( &ltime ), dateString); res = t->FormatTMTime(locale, kDateFormatWeekday, kTimeFormatNoSecondsForce24Hour, localtime( &ltime ), dateString);
cout << "kDateFormatWeekday, kTimeFormatNoSecondsForce24Hour:\n"; printf("kDateFormatWeekday, kTimeFormatNoSecondsForce24Hour:\n");
DebugDump(dateString, cout); DebugDump(dateString);
res = t->Release(); res = t->Release();
cout << "==============================\n"; printf("==============================\n");
cout << "Finish nsIDateTimeFormat Test \n"; printf("Finish nsIDateTimeFormat Test \n");
cout << "==============================\n"; printf("==============================\n");
} }
static nsresult NewLocale(const nsString* localeName, nsILocale** locale) static nsresult NewLocale(const nsString* localeName, nsILocale** locale)
@@ -846,10 +846,10 @@ static nsresult NewLocale(const nsString* localeName, nsILocale** locale)
nsresult res; nsresult res;
res = nsComponentManager::FindFactory(kLocaleFactoryCID, getter_AddRefs(localeFactory)); res = nsComponentManager::FindFactory(kLocaleFactoryCID, getter_AddRefs(localeFactory));
if (NS_FAILED(res) || localeFactory == nsnull) cout << "FindFactory nsILocaleFactory failed\n"; if (NS_FAILED(res) || localeFactory == nsnull) printf("FindFactory nsILocaleFactory failed\n");
res = localeFactory->NewLocale(localeName, locale); res = localeFactory->NewLocale(localeName, locale);
if (NS_FAILED(res) || locale == nsnull) cout << "NewLocale failed\n"; if (NS_FAILED(res) || locale == nsnull) printf("NewLocale failed\n");
return res; return res;
} }
@@ -1023,10 +1023,10 @@ int main(int argc, char** argv) {
nsCOMPtr<nsILocaleFactory> localeFactory; nsCOMPtr<nsILocaleFactory> localeFactory;
res = nsComponentManager::FindFactory(kLocaleFactoryCID, getter_AddRefs(localeFactory)); res = nsComponentManager::FindFactory(kLocaleFactoryCID, getter_AddRefs(localeFactory));
if (NS_FAILED(res) || localeFactory == nsnull) cout << "FindFactory nsILocaleFactory failed\n"; if (NS_FAILED(res) || localeFactory == nsnull) printf("FindFactory nsILocaleFactory failed\n");
res = localeFactory->GetApplicationLocale(getter_AddRefs(locale)); res = localeFactory->GetApplicationLocale(getter_AddRefs(locale));
if (NS_FAILED(res) || locale == nsnull) cout << "GetApplicationLocale failed\n"; if (NS_FAILED(res) || locale == nsnull) printf("GetApplicationLocale failed\n");
// -------------------------------------------- // --------------------------------------------
nsCollationStrength strength = kCollationCaseInSensitive; nsCollationStrength strength = kCollationCaseInSensitive;
@@ -1041,7 +1041,7 @@ int main(int argc, char** argv) {
char *s; char *s;
s = find_option(argc, argv, "-h"); s = find_option(argc, argv, "-h");
if (s) { if (s) {
cout << argv[0] << g_usage; printf(argv[0] << g_usage);
return 0; return 0;
} }
s = find_option(argc, argv, "-v"); s = find_option(argc, argv, "-v");
@@ -1071,11 +1071,11 @@ int main(int argc, char** argv) {
// print locale string // print locale string
nsAutoString localeStr; nsAutoString localeStr;
locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeStr); locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeStr);
cout << "locale setting for collation is "; printf("locale setting for collation is ");
DebugDump(localeStr, cout); DebugDump(localeStr);
locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr); locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr);
cout << "locale setting for time is "; printf("locale setting for time is ");
DebugDump(localeStr, cout); DebugDump(localeStr);
while (argc--) { while (argc--) {
if (!strcmp(argv[argc], "-col")) if (!strcmp(argv[argc], "-col"))
@@ -1095,13 +1095,13 @@ int main(int argc, char** argv) {
// -------------------------------------------- // --------------------------------------------
cout << "Finish All The Test Cases\n"; printf("Finish All The Test Cases\n");
res = nsComponentManager::FreeLibraries(); res = nsComponentManager::FreeLibraries();
if(NS_FAILED(res)) if(NS_FAILED(res))
cout << "nsComponentManager failed\n"; printf("nsComponentManager failed\n");
else else
cout << "nsComponentManager FreeLibraries Done\n"; printf("nsComponentManager FreeLibraries Done\n");
return 0; return 0;
} }

View File

@@ -35,7 +35,7 @@
* the terms of any one of the NPL, the GPL or the LGPL. * the terms of any one of the NPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h> #include <stdio.h>
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsISupports.h" #include "nsISupports.h"
@@ -122,23 +122,23 @@ PRBool TestASCIILB(nsILineBreaker *lb,
if (i != outlen) if (i != outlen)
{ {
ok = PR_FALSE; ok = PR_FALSE;
cout << "WARNING!!! return size wrong, expect " << outlen << printf("WARNING!!! return size wrong, expect %d bet got %d \n",
" bet got " << i << "\n"; outlen, i);
} }
cout << "string = \n" << in << "\n"; printf("string = \n%s\n", in);
cout << ruler1 << "\n"; printf("%s\n", ruler1);
cout << ruler2 << "\n"; printf("%s\n", ruler2);
cout << "Expect = \n"; printf("Expect = \n");
for(j=0;j<outlen;j++) for(j=0;j<outlen;j++)
{ {
cout << out[j] << ","; printf("%d,", out[j]);
} }
cout << "\nResult = \n"; printf("\nResult = \n");
for(j=0;j<i;j++) for(j=0;j<i;j++)
{ {
cout << res[j] << ","; printf("%d,", res[j]);
} }
cout << "\n"; printf("\n");
for(j=0;j<i;j++) for(j=0;j<i;j++)
{ {
if(j < outlen) if(j < outlen)
@@ -146,14 +146,11 @@ PRBool TestASCIILB(nsILineBreaker *lb,
if (res[j] != out[j]) if (res[j] != out[j])
{ {
ok = PR_FALSE; ok = PR_FALSE;
cout << "[" << j << "] expect " << out[j] << " but got " << printf("[%d] expect %d but got %d\n", j, out[j], res[j]);
res[j] << "\n";
} }
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "[" << j << "] additional " << printf("[%d] additional %d\n", j, res[j]);
res[j] << "\n";
} }
} }
return ok; return ok;
@@ -181,23 +178,23 @@ PRBool TestASCIIWB(nsIWordBreaker *lb,
if (i != outlen) if (i != outlen)
{ {
ok = PR_FALSE; ok = PR_FALSE;
cout << "WARNING!!! return size wrong, expect " << outlen << printf("WARNING!!! return size wrong, expect %d bet got %d\n",
" bet got " << i << "\n"; outlen, i);
} }
cout << "string = \n" << in << "\n"; printf("string = \n%s\n", in);
cout << ruler1 << "\n"; printf("%s\n", ruler1);
cout << ruler2 << "\n"; printf("%s\n", ruler2);
cout << "Expect = \n"; printf("Expect = \n");
for(j=0;j<outlen;j++) for(j=0;j<outlen;j++)
{ {
cout << out[j] << ","; printf("%d,", out[j]);
} }
cout << "\nResult = \n"; printf("\nResult = \n");
for(j=0;j<i;j++) for(j=0;j<i;j++)
{ {
cout << res[j] << ","; printf("%d,", res[j]);
} }
cout << "\n"; printf("\n");
for(j=0;j<i;j++) for(j=0;j<i;j++)
{ {
if(j < outlen) if(j < outlen)
@@ -205,14 +202,11 @@ PRBool TestASCIIWB(nsIWordBreaker *lb,
if (res[j] != out[j]) if (res[j] != out[j])
{ {
ok = PR_FALSE; ok = PR_FALSE;
cout << "[" << j << "] expect " << out[j] << " but got " << printf("[%d] expect %d but got %d\n", j, out[j], res[j]);
res[j] << "\n";
} }
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "[" << j << "] additional " << printf("[%d] additional %d\n", j, res[j]);
res[j] << "\n";
} }
} }
return ok; return ok;
@@ -221,9 +215,9 @@ PRBool TestASCIIWB(nsIWordBreaker *lb,
PRBool TestLineBreaker() PRBool TestLineBreaker()
{ {
cout << "==================================\n"; printf("==================================\n");
cout << "Finish nsILineBreakerFactory Test \n"; printf("Finish nsILineBreakerFactory Test \n");
cout << "==================================\n"; printf("==================================\n");
nsILineBreakerFactory *t = NULL; nsILineBreakerFactory *t = NULL;
nsresult res; nsresult res;
PRBool ok = PR_TRUE; PRBool ok = PR_TRUE;
@@ -231,9 +225,9 @@ PRBool TestLineBreaker()
kILineBreakerFactory, kILineBreakerFactory,
(nsISupports**) &t); (nsISupports**) &t);
cout << "Test 1 - GetService():\n"; printf("Test 1 - GetService():\n");
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t1st GetService failed\n"; printf("\t1st GetService failed\n");
ok = PR_FALSE; ok = PR_FALSE;
} else { } else {
#ifdef WORD_AROUND_SERVICE_MANAGER_ASSERT #ifdef WORD_AROUND_SERVICE_MANAGER_ASSERT
@@ -246,48 +240,48 @@ PRBool TestLineBreaker()
(nsISupports**) &t); (nsISupports**) &t);
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t2nd GetService failed\n"; printf("\t2nd GetService failed\n");
ok = PR_FALSE; ok = PR_FALSE;
} else { } else {
cout << "Test 3 - GetLineBreaker():\n"; printf("Test 3 - GetLineBreaker():\n");
nsILineBreaker *lb; nsILineBreaker *lb;
nsAutoString lb_arg; nsAutoString lb_arg;
res = t->GetBreaker(lb_arg, &lb); res = t->GetBreaker(lb_arg, &lb);
if(NS_FAILED(res) || (lb == NULL)) { if(NS_FAILED(res) || (lb == NULL)) {
cout << "GetBreaker(nsILineBreaker*) failed\n"; printf("GetBreaker(nsILineBreaker*) failed\n");
ok = PR_FALSE; ok = PR_FALSE;
} else { } else {
cout << "Test 4 - {First,Next}ForwardBreak():\n"; printf("Test 4 - {First,Next}ForwardBreak():\n");
if( TestASCIILB(lb, teng1, sizeof(teng1)/sizeof(char), if( TestASCIILB(lb, teng1, sizeof(teng1)/sizeof(char),
exp1, sizeof(exp1)/sizeof(PRUint32)) ) exp1, sizeof(exp1)/sizeof(PRUint32)) )
{ {
cout << "Test 4 Passed\n\n"; printf("Test 4 Passed\n\n");
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "Test 4 Failed\n\n"; printf("Test 4 Failed\n\n");
} }
cout << "Test 5 - {First,Next}ForwardBreak():\n"; printf("Test 5 - {First,Next}ForwardBreak():\n");
if(TestASCIILB(lb, teng2, sizeof(teng2)/sizeof(char), if(TestASCIILB(lb, teng2, sizeof(teng2)/sizeof(char),
lexp2, sizeof(lexp2)/sizeof(PRUint32)) ) lexp2, sizeof(lexp2)/sizeof(PRUint32)) )
{ {
cout << "Test 5 Passed\n\n"; printf("Test 5 Passed\n\n");
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "Test 5 Failed\n\n"; printf("Test 5 Failed\n\n");
} }
cout << "Test 6 - {First,Next}ForwardBreak():\n"; printf("Test 6 - {First,Next}ForwardBreak():\n");
if(TestASCIILB(lb, teng3, sizeof(teng3)/sizeof(char), if(TestASCIILB(lb, teng3, sizeof(teng3)/sizeof(char),
exp3, sizeof(exp3)/sizeof(PRUint32)) ) exp3, sizeof(exp3)/sizeof(PRUint32)) )
{ {
cout << "Test 6 Passed\n\n"; printf("Test 6 Passed\n\n");
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "Test 6 Failed\n\n"; printf("Test 6 Failed\n\n");
} }
@@ -298,18 +292,18 @@ PRBool TestLineBreaker()
res = nsServiceManager::ReleaseService(kLWBrkCID, t); res = nsServiceManager::ReleaseService(kLWBrkCID, t);
#endif #endif
} }
cout << "==================================\n"; printf("==================================\n");
cout << "Finish nsILineBreakerFactory Test \n"; printf("Finish nsILineBreakerFactory Test \n");
cout << "==================================\n"; printf("==================================\n");
return ok; return ok;
} }
PRBool TestWordBreaker() PRBool TestWordBreaker()
{ {
cout << "==================================\n"; printf("==================================\n");
cout << "Finish nsIWordBreakerFactory Test \n"; printf("Finish nsIWordBreakerFactory Test \n");
cout << "==================================\n"; printf("==================================\n");
nsIWordBreakerFactory *t = NULL; nsIWordBreakerFactory *t = NULL;
nsresult res; nsresult res;
PRBool ok = PR_TRUE; PRBool ok = PR_TRUE;
@@ -317,9 +311,9 @@ PRBool TestWordBreaker()
kIWordBreakerFactory, kIWordBreakerFactory,
(nsISupports**) &t); (nsISupports**) &t);
cout << "Test 1 - GetService():\n"; printf("Test 1 - GetService():\n");
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t1st GetService failed\n"; printf("\t1st GetService failed\n");
ok = PR_FALSE; ok = PR_FALSE;
} else { } else {
res = nsServiceManager::ReleaseService(kLWBrkCID, t); res = nsServiceManager::ReleaseService(kLWBrkCID, t);
@@ -330,48 +324,48 @@ PRBool TestWordBreaker()
(nsISupports**) &t); (nsISupports**) &t);
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t2nd GetService failed\n"; printf("\t2nd GetService failed\n");
ok = PR_FALSE; ok = PR_FALSE;
} else { } else {
cout << "Test 3 - GetWordBreaker():\n"; printf("Test 3 - GetWordBreaker():\n");
nsIWordBreaker *lb; nsIWordBreaker *lb;
nsAutoString lb_arg; nsAutoString lb_arg;
res = t->GetBreaker(lb_arg, &lb); res = t->GetBreaker(lb_arg, &lb);
if(NS_FAILED(res) || (lb == NULL)) { if(NS_FAILED(res) || (lb == NULL)) {
cout << "GetBreaker(nsIWordBreaker*) failed\n"; printf("GetBreaker(nsIWordBreaker*) failed\n");
ok = PR_FALSE; ok = PR_FALSE;
} else { } else {
cout << "Test 4 - {First,Next}ForwardBreak():\n"; printf("Test 4 - {First,Next}ForwardBreak():\n");
if( TestASCIIWB(lb, teng1, sizeof(teng1)/sizeof(char), if( TestASCIIWB(lb, teng1, sizeof(teng1)/sizeof(char),
wexp1, sizeof(wexp1)/sizeof(PRUint32)) ) wexp1, sizeof(wexp1)/sizeof(PRUint32)) )
{ {
cout << "Test 4 Passed\n\n"; printf("Test 4 Passed\n\n");
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "Test 4 Failed\n\n"; printf("Test 4 Failed\n\n");
} }
cout << "Test 5 - {First,Next}ForwardBreak():\n"; printf("Test 5 - {First,Next}ForwardBreak():\n");
if(TestASCIIWB(lb, teng2, sizeof(teng2)/sizeof(char), if(TestASCIIWB(lb, teng2, sizeof(teng2)/sizeof(char),
wexp2, sizeof(wexp2)/sizeof(PRUint32)) ) wexp2, sizeof(wexp2)/sizeof(PRUint32)) )
{ {
cout << "Test 5 Passed\n\n"; printf("Test 5 Passed\n\n");
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "Test 5 Failed\n\n"; printf("Test 5 Failed\n\n");
} }
cout << "Test 6 - {First,Next}ForwardBreak():\n"; printf("Test 6 - {First,Next}ForwardBreak():\n");
if(TestASCIIWB(lb, teng3, sizeof(teng3)/sizeof(char), if(TestASCIIWB(lb, teng3, sizeof(teng3)/sizeof(char),
wexp3, sizeof(wexp3)/sizeof(PRUint32)) ) wexp3, sizeof(wexp3)/sizeof(PRUint32)) )
{ {
cout << "Test 6 Passed\n\n"; printf("Test 6 Passed\n\n");
} else { } else {
ok = PR_FALSE; ok = PR_FALSE;
cout << "Test 6 Failed\n\n"; printf("Test 6 Failed\n\n");
} }
@@ -380,9 +374,9 @@ PRBool TestWordBreaker()
res = nsServiceManager::ReleaseService(kLWBrkCID, t); res = nsServiceManager::ReleaseService(kLWBrkCID, t);
} }
cout << "==================================\n"; printf("==================================\n");
cout << "Finish nsIWordBreakerFactory Test \n"; printf("Finish nsIWordBreakerFactory Test \n");
cout << "==================================\n"; printf("==================================\n");
return ok; return ok;
} }
@@ -472,8 +466,8 @@ void SamplePrintWordWithBreak()
fragText = nextFragText; fragText = nextFragText;
} }
} }
cout << "Output From SamplePrintWordWithBreak() \n\n"; printf("Output From SamplePrintWordWithBreak() \n\n");
cout << "[" << NS_LossyConvertUCS2toASCII(result).get() << "]\n"; printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get());
} }
void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset) void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset)
@@ -560,8 +554,8 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset)
} }
} }
cout << "Output From SamplePrintWordWithBreak() \n\n"; printf("Output From SamplePrintWordWithBreak() \n\n");
cout << "[" << NS_LossyConvertUCS2toASCII(result).get() << "]\n"; printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get());
} }
// Main // Main
@@ -571,37 +565,37 @@ int main(int argc, char** argv) {
NS_InitXPCOM2(nsnull, nsnull, nsnull); NS_InitXPCOM2(nsnull, nsnull, nsnull);
// -------------------------------------------- // --------------------------------------------
cout << "Test Line Break\n"; printf("Test Line Break\n");
PRBool lbok ; PRBool lbok ;
PRBool wbok ; PRBool wbok ;
lbok =TestWordBreaker(); lbok =TestWordBreaker();
if(lbok) if(lbok)
cout << "Line Break Test\nOK\n"; printf("Line Break Test\nOK\n");
else else
cout << "Line Break Test\nFailed\n"; printf("Line Break Test\nFailed\n");
wbok = TestLineBreaker(); wbok = TestLineBreaker();
if(wbok) if(wbok)
cout << "Word Break Test\nOK\n"; printf("Word Break Test\nOK\n");
else else
cout << "Word Break Test\nFailed\n"; printf("Word Break Test\nFailed\n");
SampleWordBreakUsage(); SampleWordBreakUsage();
// -------------------------------------------- // --------------------------------------------
cout << "Finish All The Test Cases\n"; printf("Finish All The Test Cases\n");
nsresult res = NS_OK; nsresult res = NS_OK;
res = nsComponentManager::FreeLibraries(); res = nsComponentManager::FreeLibraries();
if(NS_FAILED(res)) if(NS_FAILED(res))
cout << "nsComponentManager failed\n"; printf("nsComponentManager failed\n");
else else
cout << "nsComponentManager FreeLibraries Done\n"; printf("nsComponentManager FreeLibraries Done\n");
if(lbok && wbok) if(lbok && wbok)
cout << "Line/Word Break Test\nOK\n"; printf("Line/Word Break Test\nOK\n");
else else
cout << "Line/Word Break Test\nFailed\n"; printf("Line/Word Break Test\nFailed\n");
return 0; return 0;
} }

View File

@@ -40,7 +40,7 @@
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
#include <iostream.h> #include <stdio.h>
#include "nsIURL.h" #include "nsIURL.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@@ -118,9 +118,9 @@ main(int argc, char *argv[])
nsAutoString country; nsAutoString country;
ret = getUILangCountry(uiLang, country); ret = getUILangCountry(uiLang, country);
#if DEBUG_tao #if DEBUG_tao
cout << "\n uiLang=" << NS_LossyConvertUTF16toASCII(uiLang).get() printf("\n uiLang=%s, country=%s\n\n",
<< ", country=" << NS_LossyConvertUTF16toASCII(country).get() NS_LossyConvertUTF16toASCII(uiLang).get(),
<< "\n" << endl; NS_LossyConvertUTF16toASCII(country).get());
#endif #endif
nsIStringBundle* bundle = nsnull; nsIStringBundle* bundle = nsnull;
@@ -144,7 +144,7 @@ main(int argc, char *argv[])
} }
v = ptrv; v = ptrv;
value = ToNewCString(v); value = ToNewCString(v);
cout << "123=\"" << value << "\"" << endl; printf("123=\"%s\"\n", value);
// file // file
nsString strfile; nsString strfile;
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
} }
v = ptrv; v = ptrv;
value = ToNewCString(v); value = ToNewCString(v);
cout << "file=\"" << value << "\"" << endl; printf("file=\"%s\"\n", value);
return 0; return 0;
} }

View File

@@ -36,7 +36,7 @@
* the terms of any one of the NPL, the GPL or the LGPL. * the terms of any one of the NPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h> #include <stdio.h>
#include "nsISupports.h" #include "nsISupports.h"
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@@ -267,18 +267,18 @@ static PRUnichar t4result[T4LEN+1] = {
void TestCaseConversion() void TestCaseConversion()
{ {
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsICaseConversion Test \n"; printf("Start nsICaseConversion Test \n");
cout << "==============================\n"; printf("==============================\n");
nsICaseConversion *t = NULL; nsICaseConversion *t = NULL;
nsresult res; nsresult res;
res = nsServiceManager::GetService(kUnicharUtilCID, res = nsServiceManager::GetService(kUnicharUtilCID,
kCaseConversionIID, kCaseConversionIID,
(nsISupports**) &t); (nsISupports**) &t);
cout << "Test 1 - GetService():\n"; printf("Test 1 - GetService():\n");
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t1st GetService failed\n"; printf("\t1st GetService failed\n");
} else { } else {
res = nsServiceManager::ReleaseService(kUnicharUtilCID, t); res = nsServiceManager::ReleaseService(kUnicharUtilCID, t);
} }
@@ -288,97 +288,97 @@ void TestCaseConversion()
(nsISupports**) &t); (nsISupports**) &t);
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t2nd GetService failed\n"; printf("\t2nd GetService failed\n");
} else { } else {
int i; int i;
PRUnichar ch; PRUnichar ch;
PRUnichar buf[256]; PRUnichar buf[256];
cout << "Test 2 - ToUpper(PRUnichar, PRUnichar*):\n"; printf("Test 2 - ToUpper(PRUnichar, PRUnichar*):\n");
for(i=0;i < T2LEN ; i++) for(i=0;i < T2LEN ; i++)
{ {
res = t->ToUpper(t2data[i], &ch); res = t->ToUpper(t2data[i], &ch);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
break; break;
} }
if(ch != t2result[i]) if(ch != t2result[i])
cout << "\tFailed!! result unexpected " << i << "\n"; printf("\tFailed!! result unexpected %d\n", i);
} }
cout << "Test 3 - ToLower(PRUnichar, PRUnichar*):\n"; printf("Test 3 - ToLower(PRUnichar, PRUnichar*):\n");
for(i=0;i < T3LEN; i++) for(i=0;i < T3LEN; i++)
{ {
res = t->ToLower(t3data[i], &ch); res = t->ToLower(t3data[i], &ch);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
break; break;
} }
if(ch != t3result[i]) if(ch != t3result[i])
cout << "\tFailed!! result unexpected " << i << "\n"; printf("\tFailed!! result unexpected %d\n", i);
} }
cout << "Test 4 - ToTitle(PRUnichar, PRUnichar*):\n"; printf("Test 4 - ToTitle(PRUnichar, PRUnichar*):\n");
for(i=0;i < T4LEN; i++) for(i=0;i < T4LEN; i++)
{ {
res = t->ToTitle(t4data[i], &ch); res = t->ToTitle(t4data[i], &ch);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
break; break;
} }
if(ch != t4result[i]) if(ch != t4result[i])
cout << "\tFailed!! result unexpected " << i << "\n"; printf("\tFailed!! result unexpected %d\n", i);
} }
cout << "Test 5 - ToUpper(PRUnichar*, PRUnichar*, PRUint32):\n"; printf("Test 5 - ToUpper(PRUnichar*, PRUnichar*, PRUint32):\n");
res = t->ToUpper(t2data, buf, T2LEN); res = t->ToUpper(t2data, buf, T2LEN);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} else { } else {
for(i = 0; i < T2LEN; i++) for(i = 0; i < T2LEN; i++)
{ {
if(buf[i] != t2result[i]) if(buf[i] != t2result[i])
{ {
cout << "\tFailed!! result unexpected " << i << "\n"; printf("\tFailed!! result unexpected %d\n", i);
break; break;
} }
} }
} }
cout << "Test 6 - ToLower(PRUnichar*, PRUnichar*, PRUint32):\n"; printf("Test 6 - ToLower(PRUnichar*, PRUnichar*, PRUint32):\n");
res = t->ToLower(t3data, buf, T3LEN); res = t->ToLower(t3data, buf, T3LEN);
if(NS_FAILED(res)) { if(NS_FAILED(res)) {
cout << "\tFailed!! return value != NS_OK\n"; printf("\tFailed!! return value != NS_OK\n");
} else { } else {
for(i = 0; i < T3LEN; i++) for(i = 0; i < T3LEN; i++)
{ {
if(buf[i] != t3result[i]) if(buf[i] != t3result[i])
{ {
cout << "\tFailed!! result unexpected " << i << "\n"; printf("\tFailed!! result unexpected %d\n", i);
break; break;
} }
} }
} }
cout << "Test 7 - ToTitle(PRUnichar*, PRUnichar*, PRUint32):\n"; printf("Test 7 - ToTitle(PRUnichar*, PRUnichar*, PRUint32):\n");
cout << "!!! To Be Implemented !!!\n"; printf("!!! To Be Implemented !!!\n");
res = nsServiceManager::ReleaseService(kUnicharUtilCID, t); res = nsServiceManager::ReleaseService(kUnicharUtilCID, t);
} }
cout << "==============================\n"; printf("==============================\n");
cout << "Finish nsICaseConversion Test \n"; printf("Finish nsICaseConversion Test \n");
cout << "==============================\n"; printf("==============================\n");
} }
static void TestEntityConversion(PRUint32 version) static void TestEntityConversion(PRUint32 version)
{ {
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsIEntityConverter Test \n"; printf("Start nsIEntityConverter Test \n");
cout << "==============================\n"; printf("==============================\n");
PRUint32 i; PRUint32 i;
nsString inString; nsString inString;
@@ -394,7 +394,7 @@ static void TestEntityConversion(PRUint32 version)
nsCOMPtr <nsIEntityConverter> entityConv; nsCOMPtr <nsIEntityConverter> entityConv;
res = nsComponentManager::CreateInstance(kEntityConverterCID, NULL, NS_GET_IID(nsIEntityConverter), getter_AddRefs(entityConv)); res = nsComponentManager::CreateInstance(kEntityConverterCID, NULL, NS_GET_IID(nsIEntityConverter), getter_AddRefs(entityConv));
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n"; return;} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n"); return;}
// convert char by char // convert char by char
@@ -402,7 +402,7 @@ static void TestEntityConversion(PRUint32 version)
char *entity = NULL; char *entity = NULL;
res = entityConv->ConvertToEntity(inString[i], version, &entity); res = entityConv->ConvertToEntity(inString[i], version, &entity);
if (NS_SUCCEEDED(res) && NULL != entity) { if (NS_SUCCEEDED(res) && NULL != entity) {
cout << inString[i] << " " << entity << "\n"; printf("%c %s\n", inString[i], entity);
nsMemory::Free(entity); nsMemory::Free(entity);
} }
} }
@@ -412,23 +412,23 @@ static void TestEntityConversion(PRUint32 version)
res = entityConv->ConvertToEntities(inString.get(), version, &entities); res = entityConv->ConvertToEntities(inString.get(), version, &entities);
if (NS_SUCCEEDED(res) && NULL != entities) { if (NS_SUCCEEDED(res) && NULL != entities) {
for (i = 0; i < nsCRT::strlen(entities); i++) { for (i = 0; i < nsCRT::strlen(entities); i++) {
cout << (char) entities[i]; printf("%c", (char) entities[i]);
if (';' == (char) entities[i]) if (';' == (char) entities[i])
cout << "\n"; printf("\n");
} }
nsMemory::Free(entities); nsMemory::Free(entities);
} }
cout << "==============================\n"; printf("==============================\n");
cout << "Finish nsIEntityConverter Test \n"; printf("Finish nsIEntityConverter Test \n");
cout << "==============================\n\n"; printf("==============================\n\n");
} }
static void TestSaveAsCharset() static void TestSaveAsCharset()
{ {
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsISaveAsCharset Test \n"; printf("Start nsISaveAsCharset Test \n");
cout << "==============================\n"; printf("==============================\n");
nsresult res; nsresult res;
@@ -438,84 +438,84 @@ static void TestSaveAsCharset()
// first, dump input string // first, dump input string
for (PRUint32 i = 0; i < inString.Length(); i++) { for (PRUint32 i = 0; i < inString.Length(); i++) {
cout << inString[i] << " "; printf("%c ", inString[i]);
} }
cout << "\n"; printf("\n");
nsCOMPtr <nsISaveAsCharset> saveAsCharset; nsCOMPtr <nsISaveAsCharset> saveAsCharset;
res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL, NS_GET_IID(nsISaveAsCharset), getter_AddRefs(saveAsCharset)); res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL, NS_GET_IID(nsISaveAsCharset), getter_AddRefs(saveAsCharset));
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
cout << "ISO-8859-1 " << "attr_plainTextDefault " << "entityNone " << "\n"; printf("ISO-8859-1 attr_plainTextDefault entityNone\n");
res = saveAsCharset->Init("ISO-8859-1", res = saveAsCharset->Init("ISO-8859-1",
nsISaveAsCharset::attr_plainTextDefault, nsISaveAsCharset::attr_plainTextDefault,
nsIEntityConverter::entityNone); nsIEntityConverter::entityNone);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
res = saveAsCharset->Convert(inString.get(), &outString); res = saveAsCharset->Convert(inString.get(), &outString);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << outString << "\n"; nsMemory::Free(outString);} else {printf("%s\n", outString); nsMemory::Free(outString);}
cout << "ISO-2022-JP " << "attr_plainTextDefault " << "entityNone " << "\n"; printf("ISO-2022-JP attr_plainTextDefault entityNone\n");
res = saveAsCharset->Init("ISO-2022-JP", res = saveAsCharset->Init("ISO-2022-JP",
nsISaveAsCharset::attr_plainTextDefault, nsISaveAsCharset::attr_plainTextDefault,
nsIEntityConverter::entityNone); nsIEntityConverter::entityNone);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
res = saveAsCharset->Convert(inString.get(), &outString); res = saveAsCharset->Convert(inString.get(), &outString);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << outString << "\n"; nsMemory::Free(outString);} else {printf("%s\n", outString); nsMemory::Free(outString);}
if (NS_ERROR_UENC_NOMAPPING == res) { if (NS_ERROR_UENC_NOMAPPING == res) {
outString = ToNewUTF8String(inString); outString = ToNewUTF8String(inString);
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << "Fall back to UTF-8: " << outString << "\n"; nsMemory::Free(outString);} else {printf("Fall back to UTF-8: %s\n", outString); nsMemory::Free(outString);}
} }
cout << "ISO-2022-JP " << "attr_FallbackQuestionMark " << "entityNone " << "\n"; printf("ISO-2022-JP attr_FallbackQuestionMark entityNone\n");
res = saveAsCharset->Init("ISO-2022-JP", res = saveAsCharset->Init("ISO-2022-JP",
nsISaveAsCharset::attr_FallbackQuestionMark, nsISaveAsCharset::attr_FallbackQuestionMark,
nsIEntityConverter::entityNone); nsIEntityConverter::entityNone);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
res = saveAsCharset->Convert(inString.get(), &outString); res = saveAsCharset->Convert(inString.get(), &outString);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << outString << "\n"; nsMemory::Free(outString);} else {printf("%s\n", outString); nsMemory::Free(outString);}
cout << "ISO-2022-JP " << "attr_FallbackEscapeU " << "entityNone " << "\n"; printf("ISO-2022-JP attr_FallbackEscapeU entityNone\n");
res = saveAsCharset->Init("ISO-2022-JP", res = saveAsCharset->Init("ISO-2022-JP",
nsISaveAsCharset::attr_FallbackEscapeU, nsISaveAsCharset::attr_FallbackEscapeU,
nsIEntityConverter::entityNone); nsIEntityConverter::entityNone);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
res = saveAsCharset->Convert(inString.get(), &outString); res = saveAsCharset->Convert(inString.get(), &outString);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << outString << "\n"; nsMemory::Free(outString);} else {printf("%s\n", outString); nsMemory::Free(outString);}
cout << "ISO-8859-1 " << "attr_htmlTextDefault " << "html40Latin1 " << "\n"; printf("ISO-8859-1 attr_htmlTextDefault html40Latin1\n");
res = saveAsCharset->Init("ISO-8859-1", res = saveAsCharset->Init("ISO-8859-1",
nsISaveAsCharset::attr_htmlTextDefault, nsISaveAsCharset::attr_htmlTextDefault,
nsIEntityConverter::html40Latin1); nsIEntityConverter::html40Latin1);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
res = saveAsCharset->Convert(inString.get(), &outString); res = saveAsCharset->Convert(inString.get(), &outString);
if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << outString << "\n"; nsMemory::Free(outString);} else {printf("%s\n", outString); nsMemory::Free(outString);}
cout << "ISO-8859-1 " << "attr_FallbackHexNCR+attr_EntityAfterCharsetConv " << "html40Latin1 " << "\n"; printf("ISO-8859-1 attr_FallbackHexNCR+attr_EntityAfterCharsetConv html40Latin1 \n");
res = saveAsCharset->Init("ISO-8859-1", res = saveAsCharset->Init("ISO-8859-1",
nsISaveAsCharset::attr_FallbackHexNCR + nsISaveAsCharset::attr_FallbackHexNCR +
nsISaveAsCharset::attr_EntityAfterCharsetConv, nsISaveAsCharset::attr_EntityAfterCharsetConv,
nsIEntityConverter::html40Latin1); nsIEntityConverter::html40Latin1);
if (NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
res = saveAsCharset->Convert(inString.get(), &outString); res = saveAsCharset->Convert(inString.get(), &outString);
if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {cout << "\tFailed!! return value != NS_OK\n";} if (NS_ERROR_UENC_NOMAPPING != res && NS_FAILED(res)) {printf("\tFailed!! return value != NS_OK\n");}
if (NULL == outString) {cout << "\tFailed!! output null\n";} if (NULL == outString) {printf("\tFailed!! output null\n");}
else {cout << outString << "\n"; nsMemory::Free(outString);} else {printf("%s\n", outString); nsMemory::Free(outString);}
cout << "==============================\n"; printf("==============================\n");
cout << "Finish nsISaveAsCharset Test \n"; printf("Finish nsISaveAsCharset Test \n");
cout << "==============================\n\n"; printf("==============================\n\n");
} }
static PRUnichar normStr[] = static PRUnichar normStr[] =
@@ -544,18 +544,18 @@ static PRUnichar nfdForm[] =
void TestNormalization() void TestNormalization()
{ {
cout << "==============================\n"; printf("==============================\n");
cout << "Start nsIUnicodeNormalizer Test \n"; printf("Start nsIUnicodeNormalizer Test \n");
cout << "==============================\n"; printf("==============================\n");
nsIUnicodeNormalizer *t = NULL; nsIUnicodeNormalizer *t = NULL;
nsresult res; nsresult res;
res = nsServiceManager::GetService(kUnicodeNormalizerCID, res = nsServiceManager::GetService(kUnicodeNormalizerCID,
NS_GET_IID(nsIUnicodeNormalizer), NS_GET_IID(nsIUnicodeNormalizer),
(nsISupports**) &t); (nsISupports**) &t);
cout << "Test 1 - GetService():\n"; printf("Test 1 - GetService():\n");
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t1st Norm GetService failed\n"; printf("\t1st Norm GetService failed\n");
} else { } else {
res = nsServiceManager::ReleaseService(kUnicodeNormalizerCID, t); res = nsServiceManager::ReleaseService(kUnicodeNormalizerCID, t);
} }
@@ -565,23 +565,23 @@ void TestNormalization()
(nsISupports**) &t); (nsISupports**) &t);
if(NS_FAILED(res) || ( t == NULL ) ) { if(NS_FAILED(res) || ( t == NULL ) ) {
cout << "\t2nd GetService failed\n"; printf("\t2nd GetService failed\n");
} else { } else {
cout << "Test 2 - NormalizeUnicode(PRUint32, const nsAString&, nsAString&):\n"; printf("Test 2 - NormalizeUnicode(PRUint32, const nsAString&, nsAString&):\n");
nsAutoString resultStr; nsAutoString resultStr;
res = t->NormalizeUnicodeNFD(nsDependentString(normStr), resultStr); res = t->NormalizeUnicodeNFD(nsDependentString(normStr), resultStr);
if (resultStr.Equals(nfdForm)) { if (resultStr.Equals(nfdForm)) {
cout << " Succeeded in NFD UnicodeNormalizer test. \n"; printf(" Succeeded in NFD UnicodeNormalizer test. \n");
} else { } else {
cout << " Failed in NFD UnicodeNormalizer test. \n"; printf(" Failed in NFD UnicodeNormalizer test. \n");
} }
res = nsServiceManager::ReleaseService(kUnicodeNormalizerCID, t); res = nsServiceManager::ReleaseService(kUnicodeNormalizerCID, t);
} }
cout << "==============================\n"; printf("==============================\n");
cout << "Finish nsIUnicodeNormalizer Test \n"; printf("Finish nsIUnicodeNormalizer Test \n");
cout << "==============================\n"; printf("==============================\n");
} }
@@ -611,14 +611,14 @@ int main(int argc, char** argv) {
TestNormalization(); TestNormalization();
// -------------------------------------------- // --------------------------------------------
cout << "Finish All The Test Cases\n"; printf("Finish All The Test Cases\n");
nsresult res = NS_OK; nsresult res = NS_OK;
res = nsComponentManager::FreeLibraries(); res = nsComponentManager::FreeLibraries();
if(NS_FAILED(res)) if(NS_FAILED(res))
cout << "nsComponentManager failed\n"; printf("nsComponentManager failed\n");
else else
cout << "nsComponentManager FreeLibraries Done\n"; printf("nsComponentManager FreeLibraries Done\n");
return 0; return 0;
} }

View File

@@ -48,7 +48,7 @@
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsIEnumerator.h" #include "nsIEnumerator.h"
#include <iostream.h> //BAD DOG -- no biscuit! #include <stdio.h>
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
@@ -116,7 +116,7 @@ main(int argc, char* argv[])
} }
char* value = ToNewCString(v); char* value = ToNewCString(v);
if (value) { if (value) {
cout << "\"" << i << "\"=\"" << value << "\"" << endl; printf("\"%d\"=\"%s\"\n", i, value);
delete[] value; delete[] value;
} }
else { else {
@@ -134,8 +134,8 @@ main(int argc, char* argv[])
} }
cout << endl << "Key" << "\t" << "Value" << endl; printf("\nKey\tValue\n");
cout << "---" << "\t" << "-----" << endl; printf( "---\t-----\n");
PRBool hasMore; PRBool hasMore;
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) &&
@@ -163,7 +163,7 @@ main(int argc, char* argv[])
return 1; return 1;
} }
cout << key.get() << "\t" << value.get() << endl; printf("%s\t%s\n", key.get(), value.get());
} }
return 0; return 0;
} }

View File

@@ -49,7 +49,6 @@
#include "prlong.h" #include "prlong.h"
#include "plstr.h" #include "plstr.h"
#include "nsSupportsArray.h" #include "nsSupportsArray.h"
#include <fstream.h>
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsIComponentRegistrar.h" #include "nsIComponentRegistrar.h"
int getStrLine(const char *src, char *str, int ind, int max); int getStrLine(const char *src, char *str, int ind, int max);

View File

@@ -42,15 +42,12 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <fstream.h>
//using namespace std;
#include "plstr.h" #include "plstr.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "iostream.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsString.h" #include "nsString.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
@@ -84,7 +81,7 @@ nsresult writeoutto(const char* i_pURL, char** o_Result, PRInt32 urlFactory = UR
NS_GET_IID(nsIURI), (void**)&url); NS_GET_IID(nsIURI), (void**)&url);
if (NS_FAILED(result)) if (NS_FAILED(result))
{ {
cout << "CreateInstance failed" << endl; printf("CreateInstance failed\n");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
pURL = url; pURL = url;
@@ -96,7 +93,7 @@ nsresult writeoutto(const char* i_pURL, char** o_Result, PRInt32 urlFactory = UR
do_GetService(kIOServiceCID, &result); do_GetService(kIOServiceCID, &result);
if (NS_FAILED(result)) if (NS_FAILED(result))
{ {
cout << "Service failed!" << endl; printf("Service failed!\n");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
result = pService->NewURI(nsDependentCString(i_pURL), nsnull, nsnull, getter_AddRefs(pURL)); result = pService->NewURI(nsDependentCString(i_pURL), nsnull, nsnull, getter_AddRefs(pURL));
@@ -161,7 +158,7 @@ nsresult writeout(const char* i_pURL, PRInt32 urlFactory = URL_FACTORY_DEFAULT)
char* temp = 0; char* temp = 0;
if (!i_pURL) return NS_ERROR_FAILURE; if (!i_pURL) return NS_ERROR_FAILURE;
int rv = writeoutto(i_pURL, &temp, urlFactory); int rv = writeoutto(i_pURL, &temp, urlFactory);
cout << i_pURL << endl << temp << endl; printf("%s\n%s\n", i_pURL, temp);
delete[] temp; delete[] temp;
return rv; return rv;
} }
@@ -177,10 +174,10 @@ nsresult testURL(const char* i_pURL, PRInt32 urlFactory = URL_FACTORY_DEFAULT)
if (!gFileIO) if (!gFileIO)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
ifstream testfile(gFileIO); FILE *testfile = fopen(gFileIO, "rt");
if (!testfile) if (!testfile)
{ {
cerr << "Cannot open testfile: " << gFileIO << endl; fprintf(stderr, "Cannot open testfile: %s\n", gFileIO);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@@ -190,7 +187,7 @@ nsresult testURL(const char* i_pURL, PRInt32 urlFactory = URL_FACTORY_DEFAULT)
char* prevResult = nsnull; char* prevResult = nsnull;
char* tempurl = nsnull; char* tempurl = nsnull;
while (testfile.getline(temp,512)) while (fgets(temp,512,testfile))
{ {
if (*temp == '#' || !*temp) if (*temp == '#' || !*temp)
continue; continue;
@@ -198,7 +195,7 @@ nsresult testURL(const char* i_pURL, PRInt32 urlFactory = URL_FACTORY_DEFAULT)
if (0 == count%3) if (0 == count%3)
{ {
if (prevResult) delete[] prevResult; if (prevResult) delete[] prevResult;
cout << "Testing: " << temp << endl; printf("Testing: %s\n", temp);
writeoutto(temp, &prevResult, urlFactory); writeoutto(temp, &prevResult, urlFactory);
} }
else if (1 == count%3) { else if (1 == count%3) {
@@ -206,24 +203,24 @@ nsresult testURL(const char* i_pURL, PRInt32 urlFactory = URL_FACTORY_DEFAULT)
tempurl = nsCRT::strdup(temp); tempurl = nsCRT::strdup(temp);
} else { } else {
if (!prevResult) if (!prevResult)
cout << "no results to compare to!" << endl; printf("no results to compare to!\n");
else else
{ {
PRInt32 res; PRInt32 res;
cout << "Result: " << prevResult << endl; printf("Result: %s\n", prevResult);
if (urlFactory != URL_FACTORY_DEFAULT) { if (urlFactory != URL_FACTORY_DEFAULT) {
cout << "Expected: " << tempurl << endl; printf("Expected: %s\n", tempurl);
res = PL_strcmp(tempurl, prevResult); res = PL_strcmp(tempurl, prevResult);
} else { } else {
cout << "Expected: " << temp << endl; printf("Expected: %s\n", temp);
res = PL_strcmp(temp, prevResult); res = PL_strcmp(temp, prevResult);
} }
if (res == 0) if (res == 0)
cout << "\tPASSED" << endl << endl; printf("\tPASSED\n\n");
else else
{ {
cout << "\tFAILED" << endl << endl; printf("\tFAILED\n\n");
failed++; failed++;
} }
} }
@@ -231,10 +228,10 @@ nsresult testURL(const char* i_pURL, PRInt32 urlFactory = URL_FACTORY_DEFAULT)
count++; count++;
} }
if (failed>0) { if (failed>0) {
cout << failed << " tests FAILED out of " << count/3 << endl; printf("%d tests FAILED out of %d\n", failed, count/3);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} else { } else {
cout << "All " << count/3 << " tests PASSED." << endl; printf("All %d tests PASSED.\n", count/3);
return NS_OK; return NS_OK;
} }
} }
@@ -251,7 +248,7 @@ nsresult makeAbsTest(const char* i_BaseURI, const char* relativePortion,
NS_GET_IID(nsIURI), getter_AddRefs(baseURL)); NS_GET_IID(nsIURI), getter_AddRefs(baseURL));
if (NS_FAILED(status)) if (NS_FAILED(status))
{ {
cout << "CreateInstance failed" << endl; printf("CreateInstance failed\n");
return status; return status;
} }
status = baseURL->SetSpec(nsDependentCString(i_BaseURI)); status = baseURL->SetSpec(nsDependentCString(i_BaseURI));
@@ -266,18 +263,18 @@ nsresult makeAbsTest(const char* i_BaseURI, const char* relativePortion,
nsCAutoString temp; nsCAutoString temp;
baseURL->GetSpec(temp); baseURL->GetSpec(temp);
cout << "Analyzing " << temp.get() << endl; printf("Analyzing %s\n", temp.get());
cout << "With " << relativePortion << endl; printf("With %s\n", relativePortion);
cout << "Got " << newURL.get() << endl; printf("Got %s\n", newURL.get());
if (expectedResult) { if (expectedResult) {
cout << "Expect " << expectedResult << endl; printf("Expect %s\n", expectedResult);
int res = PL_strcmp(newURL.get(), expectedResult); int res = PL_strcmp(newURL.get(), expectedResult);
if (res == 0) { if (res == 0) {
cout << "\tPASSED" << endl << endl; printf("\tPASSED\n\n");
return NS_OK; return NS_OK;
} else { } else {
cout << "\tFAILED" << endl << endl; printf("\tFAILED\n\n");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }
@@ -390,25 +387,25 @@ int doMakeAbsTest(const char* i_URL = 0, const char* i_relativePortion=0)
failed++; failed++;
} }
if (failed>0) { if (failed>0) {
cout << failed << " tests FAILED out of " << numTests << endl; printf("%d tests FAILED out of %d\n", failed, numTests);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} else { } else {
cout << "All " << numTests << " tests PASSED." << endl; printf("All %d tests PASSED.\n", numTests);
return NS_OK; return NS_OK;
} }
} }
void printusage(void) void printusage(void)
{ {
cout << "urltest [-std] [-file <filename>] <URL> " << printf("urltest [-std] [-file <filename>] <URL> "
" [-abs <relative>]" << endl << endl " [-abs <relative>]\n\n"
<< "\t-std : Generate results using nsStdURL. " << endl "\t-std : Generate results using nsStdURL.\n"
<< "\t-file : Read URLs from file. " << endl "\t-file : Read URLs from file.\n"
<< "\t-abs : Make an absolute URL from the base (<URL>) and the" << endl "\t-abs : Make an absolute URL from the base (<URL>) and the\n"
<< "\t\trelative path specified. If -abs is given without " << endl "\t\trelative path specified. If -abs is given without\n"
<< "\t\ta base URI standard RFC 2396 relative URL tests" << endl "\t\ta base URI standard RFC 2396 relative URL tests\n"
<< "\t\tare performed. Implies -std." << endl "\t\tare performed. Implies -std.\n"
<< "\t<URL> : The string representing the URL." << endl; "\t<URL> : The string representing the URL.\n");
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@@ -428,7 +425,7 @@ int main(int argc, char **argv)
registrar->AutoRegister(nsnull); registrar->AutoRegister(nsnull);
// end of all messages from register components... // end of all messages from register components...
cout << "------------------" << endl << endl; printf("------------------\n\n");
PRInt32 urlFactory = URL_FACTORY_DEFAULT; PRInt32 urlFactory = URL_FACTORY_DEFAULT;
PRBool bMakeAbs= PR_FALSE; PRBool bMakeAbs= PR_FALSE;

View File

@@ -36,7 +36,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include <assert.h> #include <assert.h>
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsISupports.h" #include "nsISupports.h"
@@ -101,13 +100,13 @@ class test_message
public: public:
test_message() test_message()
{ {
cout << "BEGIN unit tests for |nsCOMPtr|, compiled " __DATE__ << endl; printf("BEGIN unit tests for |nsCOMPtr|, compiled " __DATE__ "\n");
} }
~test_message() ~test_message()
{ {
IFoo::print_totals(); IFoo::print_totals();
cout << "END unit tests for |nsCOMPtr|." << endl; printf("END unit tests for |nsCOMPtr|.\n");
} }
}; };
@@ -121,27 +120,31 @@ test_message gTestMessage;
void void
IFoo::print_totals() IFoo::print_totals()
{ {
cout << "total constructions/destructions --> " << total_constructions_ << "/" << total_destructions_ << endl; printf("total constructions/destructions --> %d/%d\n",
total_constructions_, total_destructions_);
} }
IFoo::IFoo() IFoo::IFoo()
: refcount_(0) : refcount_(0)
{ {
++total_constructions_; ++total_constructions_;
cout << " new IFoo@" << STATIC_CAST(void*, this) << " [#" << total_constructions_ << "]" << endl; printf(" new IFoo@%p [#%d]\n",
STATIC_CAST(void*, this), total_constructions_);
} }
IFoo::~IFoo() IFoo::~IFoo()
{ {
++total_destructions_; ++total_destructions_;
cout << "IFoo@" << STATIC_CAST(void*, this) << "::~IFoo()" << " [#" << total_destructions_ << "]" << endl; printf("IFoo@%p::~IFoo() [#%d]\n",
STATIC_CAST(void*, this), total_destructions_);
} }
nsrefcnt nsrefcnt
IFoo::AddRef() IFoo::AddRef()
{ {
++refcount_; ++refcount_;
cout << "IFoo@" << STATIC_CAST(void*, this) << "::AddRef(), refcount --> " << refcount_ << endl; printf("IFoo@%p::AddRef(), refcount --> %d\n",
STATIC_CAST(void*, this), refcount_);
return refcount_; return refcount_;
} }
@@ -150,19 +153,20 @@ IFoo::Release()
{ {
int wrap_message = (refcount_ == 1); int wrap_message = (refcount_ == 1);
if ( wrap_message ) if ( wrap_message )
cout << ">>"; printf(">>");
--refcount_; --refcount_;
cout << "IFoo@" << STATIC_CAST(void*, this) << "::Release(), refcount --> " << refcount_ << endl; printf("IFoo@%p::Release(), refcount --> %d\n",
STATIC_CAST(void*, this), refcount_);
if ( !refcount_ ) if ( !refcount_ )
{ {
cout << " delete IFoo@" << STATIC_CAST(void*, this) << endl; printf(" delete IFoo@%p\n", STATIC_CAST(void*, this));
delete this; delete this;
} }
if ( wrap_message ) if ( wrap_message )
cout << "<<IFoo@" << STATIC_CAST(void*, this) << "::Release()" << endl; printf("<<IFoo@%p::Release()\n", STATIC_CAST(void*, this));
return refcount_; return refcount_;
} }
@@ -170,7 +174,7 @@ IFoo::Release()
nsresult nsresult
IFoo::QueryInterface( const nsIID& aIID, void** aResult ) IFoo::QueryInterface( const nsIID& aIID, void** aResult )
{ {
cout << "IFoo@" << STATIC_CAST(void*, this) << "::QueryInterface()" << endl; printf("IFoo@%p::QueryInterface()\n", STATIC_CAST(void*, this));
nsISupports* rawPtr = 0; nsISupports* rawPtr = 0;
nsresult status = NS_OK; nsresult status = NS_OK;
@@ -195,34 +199,34 @@ nsresult
CreateIFoo( void** result ) CreateIFoo( void** result )
// a typical factory function (that calls AddRef) // a typical factory function (that calls AddRef)
{ {
cout << ">>CreateIFoo() --> "; printf(">>CreateIFoo() --> ");
IFoo* foop = new IFoo; IFoo* foop = new IFoo;
cout << "IFoo@" << STATIC_CAST(void*, foop) << endl; printf("IFoo@%p\n", STATIC_CAST(void*, foop));
foop->AddRef(); foop->AddRef();
*result = foop; *result = foop;
cout << "<<CreateIFoo()" << endl; printf("<<CreateIFoo()\n");
return 0; return 0;
} }
void void
set_a_IFoo( nsCOMPtr<IFoo>* result ) set_a_IFoo( nsCOMPtr<IFoo>* result )
{ {
cout << ">>set_a_IFoo()" << endl; printf(">>set_a_IFoo()\n");
assert(result); assert(result);
nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) ); nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) );
*result = foop; *result = foop;
cout << "<<set_a_IFoo()" << endl; printf("<<set_a_IFoo()\n");
} }
nsCOMPtr<IFoo> nsCOMPtr<IFoo>
return_a_IFoo() return_a_IFoo()
{ {
cout << ">>return_a_IFoo()" << endl; printf(">>return_a_IFoo()\n");
nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) ); nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) );
cout << "<<return_a_IFoo()" << endl; printf("<<return_a_IFoo()\n");
return foop; return foop;
} }
@@ -247,18 +251,18 @@ class IBar : public IFoo
IBar::IBar() IBar::IBar()
{ {
cout << " new IBar@" << STATIC_CAST(void*, this) << endl; printf(" new IBar@%p\n", STATIC_CAST(void*, this));
} }
IBar::~IBar() IBar::~IBar()
{ {
cout << "IBar@" << STATIC_CAST(void*, this) << "::~IBar()" << endl; printf("IBar@%p::~IBar()\n", STATIC_CAST(void*, this));
} }
nsresult nsresult
IBar::QueryInterface( const nsID& aIID, void** aResult ) IBar::QueryInterface( const nsID& aIID, void** aResult )
{ {
cout << "IBar@" << STATIC_CAST(void*, this) << "::QueryInterface()" << endl; printf("IBar@%p::QueryInterface()\n", STATIC_CAST(void*, this));
nsISupports* rawPtr = 0; nsISupports* rawPtr = 0;
nsresult status = NS_OK; nsresult status = NS_OK;
@@ -287,14 +291,14 @@ nsresult
CreateIBar( void** result ) CreateIBar( void** result )
// a typical factory function (that calls AddRef) // a typical factory function (that calls AddRef)
{ {
cout << ">>CreateIBar() --> "; printf(">>CreateIBar() --> ");
IBar* barp = new IBar; IBar* barp = new IBar;
cout << "IBar@" << STATIC_CAST(void*, barp) << endl; printf("IBar@%p\n", STATIC_CAST(void*, barp));
barp->AddRef(); barp->AddRef();
*result = barp; *result = barp;
cout << "<<CreateIBar()" << endl; printf("<<CreateIBar()\n");
return 0; return 0;
} }
@@ -411,9 +415,9 @@ nsCOMPtr<IFoo> gFoop;
int int
main() main()
{ {
cout << ">>main()" << endl; printf(">>main()\n");
cout << "sizeof(nsCOMPtr<IFoo>) --> " << sizeof(nsCOMPtr<IFoo>) << endl; printf("sizeof(nsCOMPtr<IFoo>) --> %d\n", sizeof(nsCOMPtr<IFoo>));
#ifdef TEST_EXCEPTIONS #ifdef TEST_EXCEPTIONS
TestBloat_Raw(); TestBloat_Raw();
@@ -423,10 +427,10 @@ main()
{ {
cout << endl << "### Test 1: will a |nsCOMPtr| call |AddRef| on a pointer assigned into it?" << endl; printf("\n### Test 1: will a |nsCOMPtr| call |AddRef| on a pointer assigned into it?\n");
nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) ); nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) );
cout << endl << "### Test 2: will a |nsCOMPtr| |Release| its old pointer when a new one is assigned in?" << endl; printf("\n### Test 2: will a |nsCOMPtr| |Release| its old pointer when a new one is assigned in?\n");
foop = do_QueryInterface(new IFoo); foop = do_QueryInterface(new IFoo);
// [Shouldn't compile] Is it a compile time error to try to |AddRef| by hand? // [Shouldn't compile] Is it a compile time error to try to |AddRef| by hand?
@@ -438,22 +442,22 @@ main()
// [Shouldn't compile] Is it a compile time error to try to |delete| an |nsCOMPtr|? // [Shouldn't compile] Is it a compile time error to try to |delete| an |nsCOMPtr|?
//delete foop; //delete foop;
cout << endl << "### Test 3: can you |AddRef| if you must?" << endl; printf("\n### Test 3: can you |AddRef| if you must?\n");
STATIC_CAST(IFoo*, foop)->AddRef(); STATIC_CAST(IFoo*, foop)->AddRef();
cout << endl << "### Test 4: can you |Release| if you must?" << endl; printf("\n### Test 4: can you |Release| if you must?\n");
STATIC_CAST(IFoo*, foop)->Release(); STATIC_CAST(IFoo*, foop)->Release();
cout << endl << "### Test 5: will a |nsCOMPtr| |Release| when it goes out of scope?" << endl; printf("\n### Test 5: will a |nsCOMPtr| |Release| when it goes out of scope?\n");
} }
{ {
cout << endl << "### Test 6: will a |nsCOMPtr| call the correct destructor?" << endl; printf("\n### Test 6: will a |nsCOMPtr| call the correct destructor?\n");
nsCOMPtr<IFoo> foop( do_QueryInterface(new IBar) ); nsCOMPtr<IFoo> foop( do_QueryInterface(new IBar) );
} }
{ {
cout << endl << "### Test 7: can you compare one |nsCOMPtr| with another [!=]?" << endl; printf("\n### Test 7: can you compare one |nsCOMPtr| with another [!=]?\n");
nsCOMPtr<IFoo> foo1p( do_QueryInterface(new IFoo) ); nsCOMPtr<IFoo> foo1p( do_QueryInterface(new IFoo) );
@@ -466,86 +470,86 @@ main()
nsCOMPtr<IFoo> foo2p( do_QueryInterface(new IFoo) ); nsCOMPtr<IFoo> foo2p( do_QueryInterface(new IFoo) );
if ( foo1p != foo2p ) if ( foo1p != foo2p )
cout << "foo1p != foo2p" << endl; printf("foo1p != foo2p\n");
else else
cout << "foo1p == foo2p" << endl; printf("foo1p == foo2p\n");
cout << endl << "### Test 7.5: can you compare a |nsCOMPtr| with NULL, 0, nsnull [!=]?" << endl; printf("\n### Test 7.5: can you compare a |nsCOMPtr| with NULL, 0, nsnull [!=]?\n");
if ( foo1p != 0 ) if ( foo1p != 0 )
cout << "foo1p != 0" << endl; printf("foo1p != 0\n");
if ( 0 != foo1p ) if ( 0 != foo1p )
cout << "0 != foo1p" << endl; printf("0 != foo1p\n");
if ( foo1p == 0 ) if ( foo1p == 0 )
cout << "foo1p == 0" << endl; printf("foo1p == 0\n");
if ( 0 == foo1p ) if ( 0 == foo1p )
cout << "0 == foo1p" << endl; printf("0 == foo1p\n");
IFoo* raw_foo2p = foo2p.get(); IFoo* raw_foo2p = foo2p.get();
cout << endl << "### Test 8: can you compare a |nsCOMPtr| with a raw interface pointer [!=]?" << endl; printf("\n### Test 8: can you compare a |nsCOMPtr| with a raw interface pointer [!=]?\n");
if ( foo1p.get() != raw_foo2p ) if ( foo1p.get() != raw_foo2p )
cout << "foo1p != raw_foo2p" << endl; printf("foo1p != raw_foo2p\n");
else else
cout << "foo1p == raw_foo2p" << endl; printf("foo1p == raw_foo2p\n");
cout << endl << "### Test 9: can you assign one |nsCOMPtr| into another?" << endl; printf("\n### Test 9: can you assign one |nsCOMPtr| into another?\n");
foo1p = foo2p; foo1p = foo2p;
cout << endl << "### Test 10: can you compare one |nsCOMPtr| with another [==]?" << endl; printf("\n### Test 10: can you compare one |nsCOMPtr| with another [==]?\n");
if ( foo1p == foo2p ) if ( foo1p == foo2p )
cout << "foo1p == foo2p" << endl; printf("foo1p == foo2p\n");
else else
cout << "foo1p != foo2p" << endl; printf("foo1p != foo2p\n");
cout << endl << "### Test 11: can you compare a |nsCOMPtr| with a raw interface pointer [==]?" << endl; printf("\n### Test 11: can you compare a |nsCOMPtr| with a raw interface pointer [==]?\n");
if ( raw_foo2p == foo2p.get() ) if ( raw_foo2p == foo2p.get() )
cout << "raw_foo2p == foo2p" << endl; printf("raw_foo2p == foo2p\n");
else else
cout << "raw_foo2p != foo2p" << endl; printf("raw_foo2p != foo2p\n");
#if 1 #if 1
cout << endl << "### Test 11.5: can you compare a |nsCOMPtr| with a raw interface pointer [==]?" << endl; printf("\n### Test 11.5: can you compare a |nsCOMPtr| with a raw interface pointer [==]?\n");
if ( nsCOMPtr<IFoo>( raw_foo2p ) == foo2p ) if ( nsCOMPtr<IFoo>( raw_foo2p ) == foo2p )
cout << "raw_foo2p == foo2p" << endl; printf("raw_foo2p == foo2p\n");
else else
cout << "raw_foo2p != foo2p" << endl; printf("raw_foo2p != foo2p\n");
#endif #endif
cout << endl << "### Test 12: bare pointer test?" << endl; printf("\n### Test 12: bare pointer test?\n");
if ( foo1p ) if ( foo1p )
cout << "foo1p is not NULL" << endl; printf("foo1p is not NULL\n");
else else
cout << "foo1p is NULL" << endl; printf("foo1p is NULL\n");
cout << endl << "### Test 13: numeric pointer test?" << endl; printf("\n### Test 13: numeric pointer test?\n");
if ( foo1p == 0 ) if ( foo1p == 0 )
cout << "foo1p is NULL" << endl; printf("foo1p is NULL\n");
else else
cout << "foo1p is not NULL" << endl; printf("foo1p is not NULL\n");
#if 0 #if 0
if ( foo1p == 1 ) if ( foo1p == 1 )
cout << "foo1p allowed compare with in" << endl; printf("foo1p allowed compare with in\n");
#endif #endif
cout << endl << "### Test 14: how about when two |nsCOMPtr|s referring to the same object go out of scope?" << endl; printf("\n### Test 14: how about when two |nsCOMPtr|s referring to the same object go out of scope?\n");
} }
{ {
cout << endl << "### Test 15,16 ...setup..." << endl; printf("\n### Test 15,16 ...setup...\n");
IFoo* raw_foo1p = new IFoo; IFoo* raw_foo1p = new IFoo;
raw_foo1p->AddRef(); raw_foo1p->AddRef();
IFoo* raw_foo2p = new IFoo; IFoo* raw_foo2p = new IFoo;
raw_foo2p->AddRef(); raw_foo2p->AddRef();
cout << endl << "### Test 15: what if I don't want to |AddRef| when I construct?" << endl; printf("\n### Test 15: what if I don't want to |AddRef| when I construct?\n");
nsCOMPtr<IFoo> foo1p( dont_AddRef(raw_foo1p) ); nsCOMPtr<IFoo> foo1p( dont_AddRef(raw_foo1p) );
//nsCOMPtr<IFoo> foo1p = dont_AddRef(raw_foo1p); //nsCOMPtr<IFoo> foo1p = dont_AddRef(raw_foo1p);
cout << endl << "### Test 16: what if I don't want to |AddRef| when I assign in?" << endl; printf("\n### Test 16: what if I don't want to |AddRef| when I assign in?\n");
nsCOMPtr<IFoo> foo2p; nsCOMPtr<IFoo> foo2p;
foo2p = dont_AddRef(raw_foo2p); foo2p = dont_AddRef(raw_foo2p);
} }
@@ -557,66 +561,66 @@ main()
{ {
cout << endl << "### setup for Test 17" << endl; printf("\n### setup for Test 17\n");
nsCOMPtr<IFoo> foop; nsCOMPtr<IFoo> foop;
cout << "### Test 17: basic parameter behavior?" << endl; printf("### Test 17: basic parameter behavior?\n");
CreateIFoo( nsGetterAddRefs<IFoo>(foop) ); CreateIFoo( nsGetterAddRefs<IFoo>(foop) );
} }
cout << "### End Test 17" << endl; printf("### End Test 17\n");
{ {
cout << endl << "### setup for Test 18" << endl; printf("\n### setup for Test 18\n");
nsCOMPtr<IFoo> foop; nsCOMPtr<IFoo> foop;
cout << "### Test 18: basic parameter behavior, using the short form?" << endl; printf("### Test 18: basic parameter behavior, using the short form?\n");
CreateIFoo( getter_AddRefs(foop) ); CreateIFoo( getter_AddRefs(foop) );
} }
cout << "### End Test 18" << endl; printf("### End Test 18\n");
{ {
cout << endl << "### setup for Test 19, 20" << endl; printf("\n### setup for Test 19, 20\n");
nsCOMPtr<IFoo> foop; nsCOMPtr<IFoo> foop;
cout << "### Test 19: reference parameter behavior?" << endl; printf("### Test 19: reference parameter behavior?\n");
set_a_IFoo(address_of(foop)); set_a_IFoo(address_of(foop));
cout << "### Test 20: return value behavior?" << endl; printf("### Test 20: return value behavior?\n");
foop = return_a_IFoo(); foop = return_a_IFoo();
} }
cout << "### End Test 19, 20" << endl; printf("### End Test 19, 20\n");
{ {
cout << endl << "### setup for Test 21" << endl; printf("\n### setup for Test 21\n");
nsCOMPtr<IFoo> fooP; nsCOMPtr<IFoo> fooP;
cout << "### Test 21: is |QueryInterface| called on assigning in a raw pointer?" << endl; printf("### Test 21: is |QueryInterface| called on assigning in a raw pointer?\n");
fooP = do_QueryInterface(new IFoo); fooP = do_QueryInterface(new IFoo);
} }
cout << "### End Test 21" << endl; printf("### End Test 21\n");
{ {
cout << endl << "### setup for Test 22" << endl; printf("\n### setup for Test 22\n");
nsCOMPtr<IFoo> fooP; nsCOMPtr<IFoo> fooP;
fooP = do_QueryInterface(new IFoo); fooP = do_QueryInterface(new IFoo);
nsCOMPtr<IFoo> foo2P; nsCOMPtr<IFoo> foo2P;
cout << "### Test 22: is |QueryInterface| _not_ called when assigning in a smart-pointer of the same type?" << endl; printf("### Test 22: is |QueryInterface| _not_ called when assigning in a smart-pointer of the same type?\n");
foo2P = fooP; foo2P = fooP;
} }
cout << "### End Test 22" << endl; printf("### End Test 22\n");
{ {
cout << endl << "### setup for Test 23" << endl; printf("\n### setup for Test 23\n");
nsCOMPtr<IBar> barP( do_QueryInterface(new IBar) ); nsCOMPtr<IBar> barP( do_QueryInterface(new IBar) );
cout << "### Test 23: is |QueryInterface| called when assigning in a smart-pointer of a different type?" << endl; printf("### Test 23: is |QueryInterface| called when assigning in a smart-pointer of a different type?\n");
nsCOMPtr<IFoo> fooP( do_QueryInterface(barP) ); nsCOMPtr<IFoo> fooP( do_QueryInterface(barP) );
if ( fooP ) if ( fooP )
cout << "an IBar* is an IFoo*" << endl; printf("an IBar* is an IFoo*\n");
} }
cout << "### End Test 23" << endl; printf("### End Test 23\n");
{ {
@@ -636,10 +640,10 @@ main()
} }
cout << endl << "### Test 24: will a static |nsCOMPtr| |Release| before program termination?" << endl; printf("\n### Test 24: will a static |nsCOMPtr| |Release| before program termination?\n");
gFoop = do_QueryInterface(new IFoo); gFoop = do_QueryInterface(new IFoo);
cout << "<<main()" << endl; printf("<<main()\n");
return 0; return 0;
} }

View File

@@ -36,7 +36,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include "TestFactory.h" #include "TestFactory.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
@@ -63,7 +62,7 @@ public:
NS_IMPL_ISUPPORTS1(TestClassImpl, ITestClass) NS_IMPL_ISUPPORTS1(TestClassImpl, ITestClass)
void TestClassImpl::Test() { void TestClassImpl::Test() {
cout << "hello, world!\n"; printf("hello, world!\n");
} }
/** /**
@@ -135,7 +134,7 @@ int main(int argc, char **argv) {
t->Test(); t->Test();
t->Release(); t->Release();
} else { } else {
cout << "CreateInstance failed\n"; printf("CreateInstance failed\n");
} }
t = NULL; t = NULL;
@@ -149,7 +148,7 @@ int main(int argc, char **argv) {
t->Test(); t->Test();
t->Release(); t->Release();
} else { } else {
cout << "Dynamic CreateInstance failed\n"; printf("Dynamic CreateInstance failed\n");
} }
} // this scopes the nsCOMPtrs } // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM

View File

@@ -35,7 +35,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsBaseHashtable.h" #include "nsBaseHashtable.h"
#include "nsDataHashtable.h" #include "nsDataHashtable.h"
@@ -52,13 +51,13 @@ class TestUniChar // for nsClassHashtable
public: public:
TestUniChar(PRUint32 aWord) TestUniChar(PRUint32 aWord)
{ {
cout << " TestUniChar::TestUniChar() " << aWord << endl; printf(" TestUniChar::TestUniChar() %u\n", aWord);
mWord = aWord; mWord = aWord;
} }
~TestUniChar() ~TestUniChar()
{ {
cout << " TestUniChar::~TestUniChar() " << mWord << endl; printf(" TestUniChar::~TestUniChar() %u\n", mWord);
} }
PRUint32 GetChar() const { return mWord; } PRUint32 GetChar() const { return mWord; }
@@ -114,103 +113,103 @@ public:
PLDHashOperator PLDHashOperator
nsTEnumGo(EntityToUnicodeEntry* aEntry, void* userArg) { nsTEnumGo(EntityToUnicodeEntry* aEntry, void* userArg) {
cout << " enumerated \"" << aEntry->mNode->mStr << "\" = " << printf(" enumerated \"%s\" = %u\n",
aEntry->mNode->mUnicode << endl; aEntry->mNode->mStr, aEntry->mNode->mUnicode);
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
PLDHashOperator PLDHashOperator
nsTEnumStop(EntityToUnicodeEntry* aEntry, void* userArg) { nsTEnumStop(EntityToUnicodeEntry* aEntry, void* userArg) {
cout << " enumerated \"" << aEntry->mNode->mStr << "\" = " << printf(" enumerated \"%s\" = %u\n",
aEntry->mNode->mUnicode << endl; aEntry->mNode->mStr, aEntry->mNode->mUnicode);
return PL_DHASH_REMOVE; return PL_DHASH_REMOVE;
} }
void void
testTHashtable(nsTHashtable<EntityToUnicodeEntry>& hash, PRUint32 numEntries) { testTHashtable(nsTHashtable<EntityToUnicodeEntry>& hash, PRUint32 numEntries) {
cout << "Filling hash with " << numEntries << " entries." << endl; printf("Filling hash with %d entries.\n", numEntries);
PRUint32 i; PRUint32 i;
for (i = 0; i < numEntries; ++i) { for (i = 0; i < numEntries; ++i) {
cout << " Putting entry \"" << gEntities[i].mStr << "\"..."; printf(" Putting entry \"%s\"...", gEntities[i].mStr);
EntityToUnicodeEntry* entry = EntityToUnicodeEntry* entry =
hash.PutEntry(gEntities[i].mStr); hash.PutEntry(gEntities[i].mStr);
if (!entry) { if (!entry) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (2); exit (2);
} }
cout << "OK..."; printf("OK...");
if (entry->mNode) { if (entry->mNode) {
cout << "entry already exists!" << endl; printf("entry already exists!\n");
exit (3); exit (3);
} }
cout << endl; printf("\n");
entry->mNode = &gEntities[i]; entry->mNode = &gEntities[i];
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
for (i = 0; i < numEntries; ++i) { for (i = 0; i < numEntries; ++i) {
cout << " Getting entry \"" << gEntities[i].mStr << "\"..."; printf(" Getting entry \"%s\"...", gEntities[i].mStr);
EntityToUnicodeEntry* entry = EntityToUnicodeEntry* entry =
hash.GetEntry(gEntities[i].mStr); hash.GetEntry(gEntities[i].mStr);
if (!entry) { if (!entry) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (4); exit (4);
} }
cout << "Found " << entry->mNode->mUnicode << endl; printf("Found %u\n", entry->mNode->mUnicode);
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
EntityToUnicodeEntry* entry = EntityToUnicodeEntry* entry =
hash.GetEntry("xxxy"); hash.GetEntry("xxxy");
if (entry) { if (entry) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (5); exit (5);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
PRUint32 count = hash.EnumerateEntries(nsTEnumGo, nsnull); PRUint32 count = hash.EnumerateEntries(nsTEnumGo, nsnull);
if (count != numEntries) { if (count != numEntries) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (6); exit (6);
} }
} }
PLDHashOperator PLDHashOperator
nsDEnumRead(const PRUint32& aKey, const char* aData, void* userArg) { nsDEnumRead(const PRUint32& aKey, const char* aData, void* userArg) {
cout << " enumerated " << aKey << " = \"" << aData << "\"" << endl; printf(" enumerated %u = \"%s\"\n", aKey, aData);
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
PLDHashOperator PLDHashOperator
nsDEnum(const PRUint32& aKey, const char*& aData, void* userArg) { nsDEnum(const PRUint32& aKey, const char*& aData, void* userArg) {
cout << " enumerated " << aKey << " = \"" << aData << "\"" << endl; printf(" enumerated %u = \"%s\"\n", aKey, aData);
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
PLDHashOperator PLDHashOperator
nsCEnumRead(const nsACString& aKey, TestUniChar* aData, void* userArg) { nsCEnumRead(const nsACString& aKey, TestUniChar* aData, void* userArg) {
cout << " enumerated \"" << PromiseFlatCString(aKey).get() << "\" = " << printf(" enumerated \"%s\" = %c\n",
aData->GetChar() << endl; PromiseFlatCString(aKey).get(), aData->GetChar());
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
PLDHashOperator PLDHashOperator
nsCEnum(const nsACString& aKey, nsAutoPtr<TestUniChar>& aData, void* userArg) { nsCEnum(const nsACString& aKey, nsAutoPtr<TestUniChar>& aData, void* userArg) {
cout << " enumerated \"" << PromiseFlatCString(aKey).get() << "\" = " << printf(" enumerated \"%s\" = %c\n",
aData->GetChar() << endl; PromiseFlatCString(aKey).get(), aData->GetChar());
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
@@ -255,27 +254,31 @@ unsigned int IFoo::total_destructions_;
void void
IFoo::print_totals() IFoo::print_totals()
{ {
cout << "total constructions/destructions --> " << total_constructions_ << "/" << total_destructions_ << endl; printf("total constructions/destructions --> %d/%d\n",
total_constructions_, total_destructions_);
} }
IFoo::IFoo() IFoo::IFoo()
: refcount_(0) : refcount_(0)
{ {
++total_constructions_; ++total_constructions_;
cout << " new IFoo@" << NS_STATIC_CAST(void*, this) << " [#" << total_constructions_ << "]" << endl; printf(" new IFoo@%p [#%d]\n",
NS_STATIC_CAST(void*, this), total_constructions_);
} }
IFoo::~IFoo() IFoo::~IFoo()
{ {
++total_destructions_; ++total_destructions_;
cout << "IFoo@" << NS_STATIC_CAST(void*, this) << "::~IFoo()" << " [#" << total_destructions_ << "]" << endl; printf("IFoo@%p::~IFoo() [#%d]\n",
NS_STATIC_CAST(void*, this), total_destructions_);
} }
nsrefcnt nsrefcnt
IFoo::AddRef() IFoo::AddRef()
{ {
++refcount_; ++refcount_;
cout << "IFoo@" << NS_STATIC_CAST(void*, this) << "::AddRef(), refcount --> " << refcount_ << endl; printf("IFoo@%p::AddRef(), refcount --> %d\n",
NS_STATIC_CAST(void*, this), refcount_);
return refcount_; return refcount_;
} }
@@ -284,19 +287,20 @@ IFoo::Release()
{ {
int wrap_message = (refcount_ == 1); int wrap_message = (refcount_ == 1);
if ( wrap_message ) if ( wrap_message )
cout << ">>"; printf(">>");
--refcount_; --refcount_;
cout << "IFoo@" << NS_STATIC_CAST(void*, this) << "::Release(), refcount --> " << refcount_ << endl; printf("IFoo@%p::Release(), refcount --> %d\n",
NS_STATIC_CAST(void*, this), refcount_);
if ( !refcount_ ) if ( !refcount_ )
{ {
cout << " delete IFoo@" << NS_STATIC_CAST(void*, this) << endl; printf(" delete IFoo@%p\n", NS_STATIC_CAST(void*, this));
delete this; delete this;
} }
if ( wrap_message ) if ( wrap_message )
cout << "<<IFoo@" << NS_STATIC_CAST(void*, this) << "::Release()" << endl; printf(" delete IFoo@%p\n", NS_STATIC_CAST(void*, this));
return refcount_; return refcount_;
} }
@@ -304,7 +308,7 @@ IFoo::Release()
nsresult nsresult
IFoo::QueryInterface( const nsIID& aIID, void** aResult ) IFoo::QueryInterface( const nsIID& aIID, void** aResult )
{ {
cout << "IFoo@" << NS_STATIC_CAST(void*, this) << "::QueryInterface()" << endl; printf("IFoo@%p::QueryInterface()\n", NS_STATIC_CAST(void*, this));
nsISupports* rawPtr = 0; nsISupports* rawPtr = 0;
nsresult status = NS_OK; nsresult status = NS_OK;
@@ -343,14 +347,14 @@ nsresult
CreateIFoo( IFoo** result ) CreateIFoo( IFoo** result )
// a typical factory function (that calls AddRef) // a typical factory function (that calls AddRef)
{ {
cout << " >>CreateIFoo() --> "; printf(" >>CreateIFoo() --> ");
IFoo* foop = new IFoo(); IFoo* foop = new IFoo();
cout << "IFoo@" << NS_STATIC_CAST(void*, foop) << endl; printf("IFoo@%p\n", NS_STATIC_CAST(void*, foop));
foop->AddRef(); foop->AddRef();
*result = foop; *result = foop;
cout << "<<CreateIFoo()" << endl; printf("<<CreateIFoo()\n");
return 0; return 0;
} }
@@ -359,7 +363,7 @@ nsIEnumRead(const PRUint32& aKey, IFoo* aFoo, void* userArg) {
nsCAutoString str; nsCAutoString str;
aFoo->GetString(str); aFoo->GetString(str);
cout << " enumerated " << aKey << " = \"" << str.get() << "\"" << endl; printf(" enumerated %u = \"%s\"\n", aKey, str.get());
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
@@ -368,7 +372,7 @@ nsIEnum(const PRUint32& aKey, nsCOMPtr<IFoo>& aData, void* userArg) {
nsCAutoString str; nsCAutoString str;
aData->GetString(str); aData->GetString(str);
cout << " enumerated " << aKey << " = \"" << str.get() << "\"" << endl; printf(" enumerated %u = \"%s\"\n", aKey, str.get());
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
@@ -379,7 +383,7 @@ nsIEnum2Read(nsISupports* aKey, PRUint32 aData, void* userArg) {
foo->GetString(str); foo->GetString(str);
cout << " enumerated \"" << str.get() << "\" = " << aData << endl; printf(" enumerated \"%s\" = %u\n", str.get(), aData);
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
@@ -389,7 +393,7 @@ nsIEnum2(nsISupports* aKey, PRUint32& aData, void* userArg) {
nsCOMPtr<IFoo> foo = do_QueryInterface(aKey); nsCOMPtr<IFoo> foo = do_QueryInterface(aKey);
foo->GetString(str); foo->GetString(str);
cout << " enumerated \"" << str.get() << "\" = " << aData << endl; printf(" enumerated \"%s\" = %u\n", str.get(), aData);
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
@@ -398,46 +402,46 @@ main(void) {
// check an nsTHashtable // check an nsTHashtable
nsTHashtable<EntityToUnicodeEntry> EntityToUnicode; nsTHashtable<EntityToUnicodeEntry> EntityToUnicode;
cout << "Initializing nsTHashtable..."; printf("Initializing nsTHashtable...");
if (!EntityToUnicode.Init(ENTITY_COUNT)) { if (!EntityToUnicode.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (1); exit (1);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Partially filling nsTHashtable:" << endl; printf("Partially filling nsTHashtable:\n");
testTHashtable(EntityToUnicode, 5); testTHashtable(EntityToUnicode, 5);
cout << "Enumerate-removing..." << endl; printf("Enumerate-removing...\n");
PRUint32 count = EntityToUnicode.EnumerateEntries(nsTEnumStop, nsnull); PRUint32 count = EntityToUnicode.EnumerateEntries(nsTEnumStop, nsnull);
if (count != 5) { if (count != 5) {
cout << "wrong count" << endl; printf("wrong count\n");
exit (7); exit (7);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Check enumeration..."; printf("Check enumeration...");
count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nsnull); count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nsnull);
if (count) { if (count) {
cout << "entries remain in table!" << endl; printf("entries remain in table!\n");
exit (8); exit (8);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling nsTHashtable:" << endl; printf("Filling nsTHashtable:\n");
testTHashtable(EntityToUnicode, ENTITY_COUNT); testTHashtable(EntityToUnicode, ENTITY_COUNT);
cout << "Clearing..."; printf("Clearing...");
EntityToUnicode.Clear(); EntityToUnicode.Clear();
cout << "OK" << endl; printf("OK\n");
cout << "Check enumeration..."; printf("Check enumeration...");
count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nsnull); count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nsnull);
if (count) { if (count) {
cout << "entries remain in table!" << endl; printf("entries remain in table!\n");
exit (9); exit (9);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check a data-hashtable // now check a data-hashtable
@@ -445,66 +449,66 @@ main(void) {
nsDataHashtable<nsUint32HashKey,const char*> UniToEntity; nsDataHashtable<nsUint32HashKey,const char*> UniToEntity;
cout << "Initializing nsDataHashtable..."; printf("Initializing nsDataHashtable...");
if (!UniToEntity.Init(ENTITY_COUNT)) { if (!UniToEntity.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (10); exit (10);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
PRUint32 i; PRUint32 i;
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
if (!UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr)) { if (!UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (11); exit (11);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
const char* str; const char* str;
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mUnicode << "..."; printf(" Getting entry %u...", gEntities[i].mUnicode);
if (!UniToEntity.Get(gEntities[i].mUnicode, &str)) { if (!UniToEntity.Get(gEntities[i].mUnicode, &str)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (12); exit (12);
} }
cout << "Found " << str << endl; printf("Found %s\n", str);
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
if (UniToEntity.Get(99446, &str)) { if (UniToEntity.Get(99446, &str)) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (13); exit (13);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = UniToEntity.EnumerateRead(nsDEnumRead, nsnull); count = UniToEntity.EnumerateRead(nsDEnumRead, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (14); exit (14);
} }
cout << "Clearing..."; printf("Clearing...");
UniToEntity.Clear(); UniToEntity.Clear();
cout << "OK" << endl; printf("OK\n");
cout << "Checking count..."; printf("Checking count...");
count = UniToEntity.Enumerate(nsDEnum, nsnull); count = UniToEntity.Enumerate(nsDEnum, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (15); exit (15);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check a thread-safe data-hashtable // now check a thread-safe data-hashtable
@@ -512,64 +516,64 @@ main(void) {
nsDataHashtableMT<nsUint32HashKey,const char*> UniToEntityL; nsDataHashtableMT<nsUint32HashKey,const char*> UniToEntityL;
cout << "Initializing nsDataHashtableMT..."; printf("Initializing nsDataHashtableMT...");
if (!UniToEntityL.Init(ENTITY_COUNT)) { if (!UniToEntityL.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (10); exit (10);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
if (!UniToEntityL.Put(gEntities[i].mUnicode, gEntities[i].mStr)) { if (!UniToEntityL.Put(gEntities[i].mUnicode, gEntities[i].mStr)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (11); exit (11);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mUnicode << "..."; printf(" Getting entry %u...", gEntities[i].mUnicode);
if (!UniToEntityL.Get(gEntities[i].mUnicode, &str)) { if (!UniToEntityL.Get(gEntities[i].mUnicode, &str)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (12); exit (12);
} }
cout << "Found " << str << endl; printf("Found %s\n", str);
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
if (UniToEntityL.Get(99446, &str)) { if (UniToEntityL.Get(99446, &str)) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (13); exit (13);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = UniToEntityL.EnumerateRead(nsDEnumRead, nsnull); count = UniToEntityL.EnumerateRead(nsDEnumRead, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (14); exit (14);
} }
cout << "Clearing..."; printf("Clearing...");
UniToEntityL.Clear(); UniToEntityL.Clear();
cout << "OK" << endl; printf("OK\n");
cout << "Checking count..."; printf("Checking count...");
count = UniToEntityL.Enumerate(nsDEnum, nsnull); count = UniToEntityL.Enumerate(nsDEnum, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (15); exit (15);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check a class-hashtable // now check a class-hashtable
@@ -577,68 +581,68 @@ main(void) {
nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass; nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass;
cout << "Initializing nsClassHashtable..."; printf("Initializing nsClassHashtable...");
if (!EntToUniClass.Init(ENTITY_COUNT)) { if (!EntToUniClass.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (16); exit (16);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode); TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode);
if (!EntToUniClass.Put(nsDependentCString(gEntities[i].mStr), temp)) { if (!EntToUniClass.Put(nsDependentCString(gEntities[i].mStr), temp)) {
cout << "FAILED" << endl; printf("FAILED\n");
delete temp; delete temp;
exit (17); exit (17);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
TestUniChar* myChar; TestUniChar* myChar;
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mStr << "..."; printf(" Getting entry %s...", gEntities[i].mStr);
if (!EntToUniClass.Get(nsDependentCString(gEntities[i].mStr), &myChar)) { if (!EntToUniClass.Get(nsDependentCString(gEntities[i].mStr), &myChar)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (18); exit (18);
} }
cout << "Found " << myChar->GetChar() << endl; printf("Found %c\n", myChar->GetChar());
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
if (EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) { if (EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (19); exit (19);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = EntToUniClass.EnumerateRead(nsCEnumRead, nsnull); count = EntToUniClass.EnumerateRead(nsCEnumRead, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (20); exit (20);
} }
cout << "Clearing..." << endl; printf("Clearing...\n");
EntToUniClass.Clear(); EntToUniClass.Clear();
cout << " Clearing OK" << endl; printf(" Clearing OK\n");
cout << "Checking count..."; printf("Checking count...");
count = EntToUniClass.Enumerate(nsCEnum, nsnull); count = EntToUniClass.Enumerate(nsCEnum, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (21); exit (21);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check a thread-safe class-hashtable // now check a thread-safe class-hashtable
@@ -646,67 +650,67 @@ main(void) {
nsClassHashtableMT<nsCStringHashKey,TestUniChar> EntToUniClassL; nsClassHashtableMT<nsCStringHashKey,TestUniChar> EntToUniClassL;
cout << "Initializing nsClassHashtableMT..."; printf("Initializing nsClassHashtableMT...");
if (!EntToUniClassL.Init(ENTITY_COUNT)) { if (!EntToUniClassL.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (16); exit (16);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode); TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode);
if (!EntToUniClassL.Put(nsDependentCString(gEntities[i].mStr), temp)) { if (!EntToUniClassL.Put(nsDependentCString(gEntities[i].mStr), temp)) {
cout << "FAILED" << endl; printf("FAILED\n");
delete temp; delete temp;
exit (17); exit (17);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mStr << "..."; printf(" Getting entry %s...", gEntities[i].mStr);
if (!EntToUniClassL.Get(nsDependentCString(gEntities[i].mStr), &myChar)) { if (!EntToUniClassL.Get(nsDependentCString(gEntities[i].mStr), &myChar)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (18); exit (18);
} }
cout << "Found " << myChar->GetChar() << endl; printf("Found %c\n", myChar->GetChar());
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
if (EntToUniClassL.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) { if (EntToUniClassL.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (19); exit (19);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = EntToUniClassL.EnumerateRead(nsCEnumRead, nsnull); count = EntToUniClassL.EnumerateRead(nsCEnumRead, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (20); exit (20);
} }
cout << "Clearing..." << endl; printf("Clearing...\n");
EntToUniClassL.Clear(); EntToUniClassL.Clear();
cout << " Clearing OK" << endl; printf(" Clearing OK\n");
cout << "Checking count..."; printf("Checking count...");
count = EntToUniClassL.Enumerate(nsCEnum, nsnull); count = EntToUniClassL.Enumerate(nsCEnum, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (21); exit (21);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check a data-hashtable with an interface key // now check a data-hashtable with an interface key
@@ -714,19 +718,19 @@ main(void) {
nsDataHashtable<nsISupportsHashKey,PRUint32> EntToUniClass2; nsDataHashtable<nsISupportsHashKey,PRUint32> EntToUniClass2;
cout << "Initializing nsDataHashtable with interface key..."; printf("Initializing nsDataHashtable with interface key...");
if (!EntToUniClass2.Init(ENTITY_COUNT)) { if (!EntToUniClass2.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (22); exit (22);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
nsCOMArray<IFoo> fooArray; nsCOMArray<IFoo> fooArray;
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
nsCOMPtr<IFoo> foo; nsCOMPtr<IFoo> foo;
CreateIFoo(getter_AddRefs(foo)); CreateIFoo(getter_AddRefs(foo));
foo->SetString(nsDependentCString(gEntities[i].mStr)); foo->SetString(nsDependentCString(gEntities[i].mStr));
@@ -735,54 +739,54 @@ main(void) {
fooArray.InsertObjectAt(foo, i); fooArray.InsertObjectAt(foo, i);
if (!EntToUniClass2.Put(foo, gEntities[i].mUnicode)) { if (!EntToUniClass2.Put(foo, gEntities[i].mUnicode)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (23); exit (23);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
PRUint32 myChar2; PRUint32 myChar2;
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mStr << "..."; printf(" Getting entry %s...", gEntities[i].mStr);
if (!EntToUniClass2.Get(fooArray[i], &myChar2)) { if (!EntToUniClass2.Get(fooArray[i], &myChar2)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (24); exit (24);
} }
cout << "Found " << myChar2 << endl; printf("Found %c\n", myChar2);
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
if (EntToUniClass2.Get((nsISupports*) 0x55443316, &myChar2)) { if (EntToUniClass2.Get((nsISupports*) 0x55443316, &myChar2)) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (25); exit (25);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = EntToUniClass2.EnumerateRead(nsIEnum2Read, nsnull); count = EntToUniClass2.EnumerateRead(nsIEnum2Read, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (26); exit (26);
} }
cout << "Clearing..." << endl; printf("Clearing...\n");
EntToUniClass2.Clear(); EntToUniClass2.Clear();
cout << " Clearing OK" << endl; printf(" Clearing OK\n");
cout << "Checking count..."; printf("Checking count...");
count = EntToUniClass2.Enumerate(nsIEnum2, nsnull); count = EntToUniClass2.Enumerate(nsIEnum2, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (27); exit (27);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check an interface-hashtable with an PRUint32 key // now check an interface-hashtable with an PRUint32 key
@@ -790,73 +794,73 @@ main(void) {
nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2; nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2;
cout << "Initializing nsInterfaceHashtable..."; printf("Initializing nsInterfaceHashtable...");
if (!UniToEntClass2.Init(ENTITY_COUNT)) { if (!UniToEntClass2.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (28); exit (28);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
nsCOMPtr<IFoo> foo; nsCOMPtr<IFoo> foo;
CreateIFoo(getter_AddRefs(foo)); CreateIFoo(getter_AddRefs(foo));
foo->SetString(nsDependentCString(gEntities[i].mStr)); foo->SetString(nsDependentCString(gEntities[i].mStr));
if (!UniToEntClass2.Put(gEntities[i].mUnicode, foo)) { if (!UniToEntClass2.Put(gEntities[i].mUnicode, foo)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (29); exit (29);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mStr << "..."; printf(" Getting entry %s...", gEntities[i].mStr);
nsCOMPtr<IFoo> myEnt; nsCOMPtr<IFoo> myEnt;
if (!UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) { if (!UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (30); exit (30);
} }
nsCAutoString str; nsCAutoString str;
myEnt->GetString(str); myEnt->GetString(str);
cout << "Found " << str.get() << endl; printf("Found %s\n", str.get());
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
nsCOMPtr<IFoo> myEnt; nsCOMPtr<IFoo> myEnt;
if (UniToEntClass2.Get(9462, getter_AddRefs(myEnt))) { if (UniToEntClass2.Get(9462, getter_AddRefs(myEnt))) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (31); exit (31);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = UniToEntClass2.EnumerateRead(nsIEnumRead, nsnull); count = UniToEntClass2.EnumerateRead(nsIEnumRead, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (32); exit (32);
} }
cout << "Clearing..." << endl; printf("Clearing...\n");
UniToEntClass2.Clear(); UniToEntClass2.Clear();
cout << " Clearing OK" << endl; printf(" Clearing OK\n");
cout << "Checking count..."; printf("Checking count...");
count = UniToEntClass2.Enumerate(nsIEnum, nsnull); count = UniToEntClass2.Enumerate(nsIEnum, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (33); exit (33);
} }
cout << "OK" << endl; printf("OK\n");
// //
// now check a thread-safe interface hashtable // now check a thread-safe interface hashtable
@@ -864,72 +868,72 @@ main(void) {
nsInterfaceHashtableMT<nsUint32HashKey,IFoo> UniToEntClass2L; nsInterfaceHashtableMT<nsUint32HashKey,IFoo> UniToEntClass2L;
cout << "Initializing nsInterfaceHashtableMT..."; printf("Initializing nsInterfaceHashtableMT...");
if (!UniToEntClass2L.Init(ENTITY_COUNT)) { if (!UniToEntClass2L.Init(ENTITY_COUNT)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (28); exit (28);
} }
cout << "OK" << endl; printf("OK\n");
cout << "Filling hash with " << ENTITY_COUNT << " entries." << endl; printf("Filling hash with %d entries.\n", ENTITY_COUNT);
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Putting entry " << gEntities[i].mUnicode << "..."; printf(" Putting entry %u...", gEntities[i].mUnicode);
nsCOMPtr<IFoo> foo; nsCOMPtr<IFoo> foo;
CreateIFoo(getter_AddRefs(foo)); CreateIFoo(getter_AddRefs(foo));
foo->SetString(nsDependentCString(gEntities[i].mStr)); foo->SetString(nsDependentCString(gEntities[i].mStr));
if (!UniToEntClass2L.Put(gEntities[i].mUnicode, foo)) { if (!UniToEntClass2L.Put(gEntities[i].mUnicode, foo)) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (29); exit (29);
} }
cout << "OK..." << endl; printf("OK...\n");
} }
cout << "Testing Get:" << endl; printf("Testing Get:\n");
for (i = 0; i < ENTITY_COUNT; ++i) { for (i = 0; i < ENTITY_COUNT; ++i) {
cout << " Getting entry " << gEntities[i].mStr << "..."; printf(" Getting entry %s...", gEntities[i].mStr);
nsCOMPtr<IFoo> myEnt; nsCOMPtr<IFoo> myEnt;
if (!UniToEntClass2L.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) { if (!UniToEntClass2L.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) {
cout << "FAILED" << endl; printf("FAILED\n");
exit (30); exit (30);
} }
nsCAutoString str; nsCAutoString str;
myEnt->GetString(str); myEnt->GetString(str);
cout << "Found " << str.get() << endl; printf("Found %s\n", str.get());
} }
cout << "Testing non-existent entries..."; printf("Testing non-existent entries...");
if (UniToEntClass2L.Get(9462, getter_AddRefs(myEnt))) { if (UniToEntClass2L.Get(9462, getter_AddRefs(myEnt))) {
cout << "FOUND! BAD!" << endl; printf("FOUND! BAD!\n");
exit (31); exit (31);
} }
cout << "not found; good." << endl; printf("not found; good.\n");
cout << "Enumerating:" << endl; printf("Enumerating:\n");
count = UniToEntClass2L.EnumerateRead(nsIEnumRead, nsnull); count = UniToEntClass2L.EnumerateRead(nsIEnumRead, nsnull);
if (count != ENTITY_COUNT) { if (count != ENTITY_COUNT) {
cout << " Bad count!" << endl; printf(" Bad count!\n");
exit (32); exit (32);
} }
cout << "Clearing..." << endl; printf("Clearing...\n");
UniToEntClass2L.Clear(); UniToEntClass2L.Clear();
cout << " Clearing OK" << endl; printf(" Clearing OK\n");
cout << "Checking count..."; printf("Checking count...");
count = UniToEntClass2L.Enumerate(nsIEnum, nsnull); count = UniToEntClass2L.Enumerate(nsIEnum, nsnull);
if (count) { if (count) {
cout << " Clear did not remove all entries." << endl; printf(" Clear did not remove all entries.\n");
exit (33); exit (33);
} }
cout << "OK" << endl; printf("OK\n");
return 0; return 0;
} }

View File

@@ -44,26 +44,23 @@
#include "nsString.h" #include "nsString.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "prprf.h" #include "prprf.h"
#include <iostream.h>
#include <iomanip.h> // needed for libstdc++-v3
#include "nsWeakReference.h" #include "nsWeakReference.h"
static nsIObserverService *anObserverService = NULL; static nsIObserverService *anObserverService = NULL;
static void testResult( nsresult rv ) { static void testResult( nsresult rv ) {
if ( NS_SUCCEEDED( rv ) ) { if ( NS_SUCCEEDED( rv ) ) {
cout << "...ok" << endl; printf("...ok\n");
} else { } else {
cout << "...failed, rv=0x" << hex << (int)rv << endl; printf("...failed, rv=0x%x\n", (int)rv);
} }
return; return;
} }
extern ostream &operator<<( ostream &s, nsString &str ) { void printString(nsString &str) {
const char *cstr = ToNewCString(str); const char *cstr = ToNewCString(str);
s << cstr; printf("%s", cstr);
delete [] (char*)cstr; delete [] (char*)cstr;
return s;
} }
class TestObserver : public nsIObserver, public nsSupportsWeakReference { class TestObserver : public nsIObserver, public nsSupportsWeakReference {
@@ -92,10 +89,14 @@ TestObserver::Observe( nsISupports *aSubject,
The annoying double-cast below is to work around an annoying bug in The annoying double-cast below is to work around an annoying bug in
the compiler currently used on wensleydale. This is a test. the compiler currently used on wensleydale. This is a test.
*/ */
cout << mName << " has observed something: subject@" << (void*)aSubject printString(mName);
<< " name=" << NS_REINTERPRET_CAST(TestObserver*, NS_REINTERPRET_CAST(void*, aSubject))->mName printf(" has observed something: subject@%p", (void*)aSubject);
<< " aTopic=" << topic.get() printf(" name=");
<< " someData=" << data << endl; printString(NS_REINTERPRET_CAST(TestObserver*, NS_REINTERPRET_CAST(void*, aSubject))->mName);
printf(" aTopic=%s", topic.get());
printf(" someData=");
printString(data);
printf("\n");
return NS_OK; return NS_OK;
} }
@@ -117,62 +118,64 @@ int main(int argc, char *argv[])
nsIObserver *bObserver = new TestObserver(NS_LITERAL_STRING("Observer-B")); nsIObserver *bObserver = new TestObserver(NS_LITERAL_STRING("Observer-B"));
bObserver->AddRef(); bObserver->AddRef();
cout << "Adding Observer-A as observer of topic-A..." << endl; printf("Adding Observer-A as observer of topic-A...\n");
rv = anObserverService->AddObserver(aObserver, topicA.get(), PR_FALSE); rv = anObserverService->AddObserver(aObserver, topicA.get(), PR_FALSE);
testResult(rv); testResult(rv);
cout << "Adding Observer-B as observer of topic-A..." << endl; printf("Adding Observer-B as observer of topic-A...\n");
rv = anObserverService->AddObserver(bObserver, topicA.get(), PR_FALSE); rv = anObserverService->AddObserver(bObserver, topicA.get(), PR_FALSE);
testResult(rv); testResult(rv);
cout << "Adding Observer-B as observer of topic-B..." << endl; printf("Adding Observer-B as observer of topic-B...\n");
rv = anObserverService->AddObserver(bObserver, topicB.get(), PR_FALSE); rv = anObserverService->AddObserver(bObserver, topicB.get(), PR_FALSE);
testResult(rv); testResult(rv);
cout << "Testing Notify(observer-A, topic-A)..." << endl; printf("Testing Notify(observer-A, topic-A)...\n");
rv = anObserverService->NotifyObservers( aObserver, rv = anObserverService->NotifyObservers( aObserver,
topicA.get(), topicA.get(),
NS_LITERAL_STRING("Testing Notify(observer-A, topic-A)").get() ); NS_LITERAL_STRING("Testing Notify(observer-A, topic-A)").get() );
testResult(rv); testResult(rv);
cout << "Testing Notify(observer-B, topic-B)..." << endl; printf("Testing Notify(observer-B, topic-B)...\n");
rv = anObserverService->NotifyObservers( bObserver, rv = anObserverService->NotifyObservers( bObserver,
topicB.get(), topicB.get(),
NS_LITERAL_STRING("Testing Notify(observer-B, topic-B)").get() ); NS_LITERAL_STRING("Testing Notify(observer-B, topic-B)").get() );
testResult(rv); testResult(rv);
cout << "Testing EnumerateObserverList (for topic-A)..." << endl; printf("Testing EnumerateObserverList (for topic-A)...\n");
nsCOMPtr<nsISimpleEnumerator> e; nsCOMPtr<nsISimpleEnumerator> e;
rv = anObserverService->EnumerateObservers(topicA.get(), getter_AddRefs(e)); rv = anObserverService->EnumerateObservers(topicA.get(), getter_AddRefs(e));
testResult(rv); testResult(rv);
cout << "Enumerating observers of topic-A..." << endl; printf("Enumerating observers of topic-A...\n");
if ( e ) { if ( e ) {
nsCOMPtr<nsIObserver> observer; nsCOMPtr<nsIObserver> observer;
PRBool loop = PR_TRUE; PRBool loop = PR_TRUE;
while( NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop) while( NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop)
{ {
e->GetNext(getter_AddRefs(observer)); e->GetNext(getter_AddRefs(observer));
cout << "Calling observe on enumerated observer " printf("Calling observe on enumerated observer ");
<< NS_REINTERPRET_CAST(TestObserver*, NS_REINTERPRET_CAST(void*, observer.get()))->mName << "..." << endl; printString(NS_REINTERPRET_CAST(TestObserver*,
NS_REINTERPRET_CAST(void*, observer.get()))->mName);
printf("...\n");
rv = observer->Observe( observer, rv = observer->Observe( observer,
topicA.get(), topicA.get(),
NS_LITERAL_STRING("during enumeration").get() ); NS_LITERAL_STRING("during enumeration").get() );
testResult(rv); testResult(rv);
} }
} }
cout << "...done enumerating observers of topic-A" << endl; printf("...done enumerating observers of topic-A\n");
cout << "Removing Observer-A..." << endl; printf("Removing Observer-A...\n");
rv = anObserverService->RemoveObserver(aObserver, topicA.get()); rv = anObserverService->RemoveObserver(aObserver, topicA.get());
testResult(rv); testResult(rv);
cout << "Removing Observer-B (topic-A)..." << endl; printf("Removing Observer-B (topic-A)...\n");
rv = anObserverService->RemoveObserver(bObserver, topicB.get()); rv = anObserverService->RemoveObserver(bObserver, topicB.get());
testResult(rv); testResult(rv);
cout << "Removing Observer-B (topic-B)..." << endl; printf("Removing Observer-B (topic-B)...\n");
rv = anObserverService->RemoveObserver(bObserver, topicA.get()); rv = anObserverService->RemoveObserver(bObserver, topicA.get());
testResult(rv); testResult(rv);

View File

@@ -38,7 +38,6 @@
#include <windows.h> #include <windows.h>
#include <unknwn.h> #include <unknwn.h>
#include <iostream.h>
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIFactory.h" #include "nsIFactory.h"
@@ -69,13 +68,13 @@ public:
} }
NS_IMETHOD Test() { NS_IMETHOD Test() {
cout << "Accessed nsITestCom::Test() from COM\n"; printf("Accessed nsITestCom::Test() from COM\n");
return NS_OK; return NS_OK;
} }
private: private:
~nsTestCom() { ~nsTestCom() {
cout << "nsTestCom instance successfully deleted\n"; printf("nsTestCom instance successfully deleted\n");
} }
}; };
@@ -85,7 +84,7 @@ nsrefcnt nsTestCom::AddRef()
{ {
nsrefcnt res = ++mRefCnt; nsrefcnt res = ++mRefCnt;
NS_LOG_ADDREF(this, mRefCnt, "nsTestCom", sizeof(*this)); NS_LOG_ADDREF(this, mRefCnt, "nsTestCom", sizeof(*this));
cout << "nsTestCom: Adding ref = " << res << "\n"; printf("nsTestCom: Adding ref = %d\n", res);
return res; return res;
} }
@@ -93,7 +92,7 @@ nsrefcnt nsTestCom::Release()
{ {
nsrefcnt res = --mRefCnt; nsrefcnt res = --mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsTestCom"); NS_LOG_RELEASE(this, mRefCnt, "nsTestCom");
cout << "nsTestCom: Releasing = " << res << "\n"; printf("nsTestCom: Releasing = %d\n", res);
if (res == 0) { if (res == 0) {
delete this; delete this;
} }
@@ -111,9 +110,9 @@ public:
void **aResult); void **aResult);
NS_IMETHOD LockFactory(PRBool aLock) { NS_IMETHOD LockFactory(PRBool aLock) {
cout << "nsTestComFactory: "; printf("nsTestComFactory: ");
cout << (aLock == PR_TRUE ? "Locking server" : "Unlocking server"); printf("%s", (aLock == PR_TRUE ? "Locking server" : "Unlocking server"));
cout << "\n"; printf("\n");
return S_OK; return S_OK;
} }
}; };
@@ -139,7 +138,7 @@ nsresult nsTestComFactory::CreateInstance(nsISupports *aOuter,
NS_RELEASE(t); NS_RELEASE(t);
if (NS_SUCCEEDED(res)) { if (NS_SUCCEEDED(res)) {
cout << "nsTestComFactory: successfully created nsTestCom instance\n"; printf("nsTestComFactory: successfully created nsTestCom instance\n");
} }
return res; return res;