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_LANG_CPLUSPLUS
AC_TRY_COMPILE([#include <iostream.h>],
[ cout << "Hello World" << endl; ],,
AC_TRY_COMPILE([#include <new.h>],
[ unsigned *test = new unsigned(42); ],,
AC_MSG_ERROR([\$(CXX) test failed. You must have MS VC++ in your path to build.]) )
AC_LANG_RESTORE

View File

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

View File

@@ -44,13 +44,16 @@ endif
CPPSRCS = Double.cpp \
List.cpp \
SimpleErrorObserver.cpp \
txAtoms.cpp \
txExpandedNameMap.cpp \
txNamespaceMap.cpp \
txURIUtils.cpp \
txStringUtils.cpp
ifdef TX_EXE
CPPSRCS += SimpleErrorObserver.cpp
endif
include $(topsrcdir)/config/rules.mk
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.
*
* ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsICharsetDetector.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -36,7 +36,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include <iostream.h>
#include <assert.h>
#include "nsCOMPtr.h"
#include "nsISupports.h"
@@ -101,13 +100,13 @@ class test_message
public:
test_message()
{
cout << "BEGIN unit tests for |nsCOMPtr|, compiled " __DATE__ << endl;
printf("BEGIN unit tests for |nsCOMPtr|, compiled " __DATE__ "\n");
}
~test_message()
{
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
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()
: refcount_(0)
{
++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()
{
++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
IFoo::AddRef()
{
++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_;
}
@@ -150,19 +153,20 @@ IFoo::Release()
{
int wrap_message = (refcount_ == 1);
if ( wrap_message )
cout << ">>";
printf(">>");
--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_ )
{
cout << " delete IFoo@" << STATIC_CAST(void*, this) << endl;
printf(" delete IFoo@%p\n", STATIC_CAST(void*, this));
delete this;
}
if ( wrap_message )
cout << "<<IFoo@" << STATIC_CAST(void*, this) << "::Release()" << endl;
printf("<<IFoo@%p::Release()\n", STATIC_CAST(void*, this));
return refcount_;
}
@@ -170,7 +174,7 @@ IFoo::Release()
nsresult
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;
nsresult status = NS_OK;
@@ -195,34 +199,34 @@ nsresult
CreateIFoo( void** result )
// a typical factory function (that calls AddRef)
{
cout << ">>CreateIFoo() --> ";
printf(">>CreateIFoo() --> ");
IFoo* foop = new IFoo;
cout << "IFoo@" << STATIC_CAST(void*, foop) << endl;
printf("IFoo@%p\n", STATIC_CAST(void*, foop));
foop->AddRef();
*result = foop;
cout << "<<CreateIFoo()" << endl;
printf("<<CreateIFoo()\n");
return 0;
}
void
set_a_IFoo( nsCOMPtr<IFoo>* result )
{
cout << ">>set_a_IFoo()" << endl;
printf(">>set_a_IFoo()\n");
assert(result);
nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) );
*result = foop;
cout << "<<set_a_IFoo()" << endl;
printf("<<set_a_IFoo()\n");
}
nsCOMPtr<IFoo>
return_a_IFoo()
{
cout << ">>return_a_IFoo()" << endl;
printf(">>return_a_IFoo()\n");
nsCOMPtr<IFoo> foop( do_QueryInterface(new IFoo) );
cout << "<<return_a_IFoo()" << endl;
printf("<<return_a_IFoo()\n");
return foop;
}
@@ -247,18 +251,18 @@ class IBar : public IFoo
IBar::IBar()
{
cout << " new IBar@" << STATIC_CAST(void*, this) << endl;
printf(" new IBar@%p\n", STATIC_CAST(void*, this));
}
IBar::~IBar()
{
cout << "IBar@" << STATIC_CAST(void*, this) << "::~IBar()" << endl;
printf("IBar@%p::~IBar()\n", STATIC_CAST(void*, this));
}
nsresult
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;
nsresult status = NS_OK;
@@ -287,14 +291,14 @@ nsresult
CreateIBar( void** result )
// a typical factory function (that calls AddRef)
{
cout << ">>CreateIBar() --> ";
printf(">>CreateIBar() --> ");
IBar* barp = new IBar;
cout << "IBar@" << STATIC_CAST(void*, barp) << endl;
printf("IBar@%p\n", STATIC_CAST(void*, barp));
barp->AddRef();
*result = barp;
cout << "<<CreateIBar()" << endl;
printf("<<CreateIBar()\n");
return 0;
}
@@ -411,9 +415,9 @@ nsCOMPtr<IFoo> gFoop;
int
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
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) );
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);
// [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|?
//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();
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();
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) );
}
{
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) );
@@ -466,86 +470,86 @@ main()
nsCOMPtr<IFoo> foo2p( do_QueryInterface(new IFoo) );
if ( foo1p != foo2p )
cout << "foo1p != foo2p" << endl;
printf("foo1p != foo2p\n");
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 )
cout << "foo1p != 0" << endl;
printf("foo1p != 0\n");
if ( 0 != foo1p )
cout << "0 != foo1p" << endl;
printf("0 != foo1p\n");
if ( foo1p == 0 )
cout << "foo1p == 0" << endl;
printf("foo1p == 0\n");
if ( 0 == foo1p )
cout << "0 == foo1p" << endl;
printf("0 == foo1p\n");
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 )
cout << "foo1p != raw_foo2p" << endl;
printf("foo1p != raw_foo2p\n");
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;
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 )
cout << "foo1p == foo2p" << endl;
printf("foo1p == foo2p\n");
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() )
cout << "raw_foo2p == foo2p" << endl;
printf("raw_foo2p == foo2p\n");
else
cout << "raw_foo2p != foo2p" << endl;
printf("raw_foo2p != foo2p\n");
#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 )
cout << "raw_foo2p == foo2p" << endl;
printf("raw_foo2p == foo2p\n");
else
cout << "raw_foo2p != foo2p" << endl;
printf("raw_foo2p != foo2p\n");
#endif
cout << endl << "### Test 12: bare pointer test?" << endl;
printf("\n### Test 12: bare pointer test?\n");
if ( foo1p )
cout << "foo1p is not NULL" << endl;
printf("foo1p is not NULL\n");
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 )
cout << "foo1p is NULL" << endl;
printf("foo1p is NULL\n");
else
cout << "foo1p is not NULL" << endl;
printf("foo1p is not NULL\n");
#if 0
if ( foo1p == 1 )
cout << "foo1p allowed compare with in" << endl;
printf("foo1p allowed compare with in\n");
#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;
raw_foo1p->AddRef();
IFoo* raw_foo2p = new IFoo;
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);
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;
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;
cout << "### Test 17: basic parameter behavior?" << endl;
printf("### Test 17: basic parameter behavior?\n");
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;
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) );
}
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;
cout << "### Test 19: reference parameter behavior?" << endl;
printf("### Test 19: reference parameter behavior?\n");
set_a_IFoo(address_of(foop));
cout << "### Test 20: return value behavior?" << endl;
printf("### Test 20: return value behavior?\n");
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;
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);
}
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;
fooP = do_QueryInterface(new IFoo);
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;
}
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) );
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) );
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);
cout << "<<main()" << endl;
printf("<<main()\n");
return 0;
}

View File

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

View File

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

View File

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

View File

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