2003-04-24 05:54:57 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is C++ hashtable templates.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Benjamin Smedberg.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsBaseHashtable.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
class TestUniChar // for nsClassHashtable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestUniChar(PRUint32 aWord)
|
|
|
|
{
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" TestUniChar::TestUniChar() %u\n", aWord);
|
2003-04-24 05:54:57 +04:00
|
|
|
mWord = aWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestUniChar()
|
|
|
|
{
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" TestUniChar::~TestUniChar() %u\n", mWord);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 GetChar() const { return mWord; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRUint32 mWord;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EntityNode {
|
|
|
|
const char* mStr; // never owns buffer
|
|
|
|
PRUint32 mUnicode;
|
|
|
|
};
|
|
|
|
|
|
|
|
EntityNode gEntities[] = {
|
|
|
|
{"nbsp",160},
|
|
|
|
{"iexcl",161},
|
|
|
|
{"cent",162},
|
|
|
|
{"pound",163},
|
|
|
|
{"curren",164},
|
|
|
|
{"yen",165},
|
|
|
|
{"brvbar",166},
|
|
|
|
{"sect",167},
|
|
|
|
{"uml",168},
|
|
|
|
{"copy",169},
|
|
|
|
{"ordf",170},
|
|
|
|
{"laquo",171},
|
|
|
|
{"not",172},
|
|
|
|
{"shy",173},
|
|
|
|
{"reg",174},
|
|
|
|
{"macr",175}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ENTITY_COUNT (sizeof(gEntities)/sizeof(EntityNode))
|
|
|
|
|
|
|
|
class EntityToUnicodeEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const char* KeyType;
|
|
|
|
typedef const char* KeyTypePointer;
|
|
|
|
|
|
|
|
EntityToUnicodeEntry(const char* aKey) { mNode = nsnull; }
|
|
|
|
EntityToUnicodeEntry(const EntityToUnicodeEntry& aEntry) { mNode = aEntry.mNode; }
|
|
|
|
~EntityToUnicodeEntry() { };
|
|
|
|
|
|
|
|
PRBool KeyEquals(const char* aEntity) const { return !strcmp(mNode->mStr, aEntity); }
|
|
|
|
static const char* KeyToPointer(const char* aEntity) { return aEntity; }
|
2006-06-15 17:48:29 +04:00
|
|
|
static PLDHashNumber HashKey(const char* aEntity) { return HashString(aEntity); }
|
2003-04-24 05:54:57 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
const EntityNode* mNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsTEnumGo(EntityToUnicodeEntry* aEntry, void* userArg) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated \"%s\" = %u\n",
|
|
|
|
aEntry->mNode->mStr, aEntry->mNode->mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsTEnumStop(EntityToUnicodeEntry* aEntry, void* userArg) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated \"%s\" = %u\n",
|
|
|
|
aEntry->mNode->mStr, aEntry->mNode->mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
testTHashtable(nsTHashtable<EntityToUnicodeEntry>& hash, PRUint32 numEntries) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", numEntries);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < numEntries; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry \"%s\"...", gEntities[i].mStr);
|
2003-04-24 05:54:57 +04:00
|
|
|
EntityToUnicodeEntry* entry =
|
|
|
|
hash.PutEntry(gEntities[i].mStr);
|
|
|
|
|
|
|
|
if (!entry) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (2);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
if (entry->mNode) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("entry already exists!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (3);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
entry->mNode = &gEntities[i];
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
for (i = 0; i < numEntries; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry \"%s\"...", gEntities[i].mStr);
|
2003-04-24 05:54:57 +04:00
|
|
|
EntityToUnicodeEntry* entry =
|
|
|
|
hash.GetEntry(gEntities[i].mStr);
|
|
|
|
|
|
|
|
if (!entry) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (4);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %u\n", entry->mNode->mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
EntityToUnicodeEntry* entry =
|
|
|
|
hash.GetEntry("xxxy");
|
|
|
|
|
|
|
|
if (entry) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (5);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
PRUint32 count = hash.EnumerateEntries(nsTEnumGo, nsnull);
|
|
|
|
if (count != numEntries) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsDEnumRead(const PRUint32& aKey, const char* aData, void* userArg) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated %u = \"%s\"\n", aKey, aData);
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsDEnum(const PRUint32& aKey, const char*& aData, void* userArg) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated %u = \"%s\"\n", aKey, aData);
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsCEnumRead(const nsACString& aKey, TestUniChar* aData, void* userArg) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated \"%s\" = %c\n",
|
|
|
|
PromiseFlatCString(aKey).get(), aData->GetChar());
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsCEnum(const nsACString& aKey, nsAutoPtr<TestUniChar>& aData, void* userArg) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated \"%s\" = %c\n",
|
|
|
|
PromiseFlatCString(aKey).get(), aData->GetChar());
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// all this nsIFoo stuff was copied wholesale from TestCOMPTr.cpp
|
|
|
|
//
|
|
|
|
|
|
|
|
#define NS_IFOO_IID \
|
|
|
|
{ 0x6f7652e0, 0xee43, 0x11d1, \
|
|
|
|
{ 0x9c, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
|
|
|
|
|
|
|
|
class IFoo : public nsISupports
|
|
|
|
{
|
2004-12-27 06:23:01 +03:00
|
|
|
public:
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-12-27 06:23:01 +03:00
|
|
|
public:
|
2003-04-24 05:54:57 +04:00
|
|
|
IFoo();
|
|
|
|
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
NS_IMETHOD QueryInterface( const nsIID&, void** );
|
|
|
|
|
|
|
|
NS_IMETHOD SetString(const nsACString& /*in*/ aString);
|
|
|
|
NS_IMETHOD GetString(nsACString& /*out*/ aString);
|
|
|
|
|
|
|
|
static void print_totals();
|
|
|
|
|
|
|
|
private:
|
2004-01-15 09:14:18 +03:00
|
|
|
~IFoo();
|
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
unsigned int refcount_;
|
|
|
|
|
|
|
|
static unsigned int total_constructions_;
|
|
|
|
static unsigned int total_destructions_;
|
|
|
|
nsCString mString;
|
|
|
|
};
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(IFoo, NS_IFOO_IID)
|
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
unsigned int IFoo::total_constructions_;
|
|
|
|
unsigned int IFoo::total_destructions_;
|
|
|
|
|
|
|
|
void
|
|
|
|
IFoo::print_totals()
|
|
|
|
{
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("total constructions/destructions --> %d/%d\n",
|
|
|
|
total_constructions_, total_destructions_);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IFoo::IFoo()
|
|
|
|
: refcount_(0)
|
|
|
|
{
|
|
|
|
++total_constructions_;
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" new IFoo@%p [#%d]\n",
|
|
|
|
NS_STATIC_CAST(void*, this), total_constructions_);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IFoo::~IFoo()
|
|
|
|
{
|
|
|
|
++total_destructions_;
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("IFoo@%p::~IFoo() [#%d]\n",
|
|
|
|
NS_STATIC_CAST(void*, this), total_destructions_);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt
|
|
|
|
IFoo::AddRef()
|
|
|
|
{
|
|
|
|
++refcount_;
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("IFoo@%p::AddRef(), refcount --> %d\n",
|
|
|
|
NS_STATIC_CAST(void*, this), refcount_);
|
2003-04-24 05:54:57 +04:00
|
|
|
return refcount_;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt
|
|
|
|
IFoo::Release()
|
|
|
|
{
|
2007-01-26 05:50:18 +03:00
|
|
|
int newcount = --refcount_;
|
|
|
|
if ( newcount == 0 )
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(">>");
|
2007-01-26 05:50:18 +03:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("IFoo@%p::Release(), refcount --> %d\n",
|
|
|
|
NS_STATIC_CAST(void*, this), refcount_);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2007-01-26 05:50:18 +03:00
|
|
|
if ( newcount == 0 )
|
2003-04-24 05:54:57 +04:00
|
|
|
{
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" delete IFoo@%p\n", NS_STATIC_CAST(void*, this));
|
2007-01-26 05:50:18 +03:00
|
|
|
printf("<<IFoo@%p::Release()\n", NS_STATIC_CAST(void*, this));
|
2003-04-24 05:54:57 +04:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2007-01-26 05:50:18 +03:00
|
|
|
return newcount;
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
IFoo::QueryInterface( const nsIID& aIID, void** aResult )
|
2004-12-27 06:23:01 +03:00
|
|
|
{
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("IFoo@%p::QueryInterface()\n", NS_STATIC_CAST(void*, this));
|
2004-12-27 06:23:01 +03:00
|
|
|
nsISupports* rawPtr = 0;
|
|
|
|
nsresult status = NS_OK;
|
|
|
|
|
|
|
|
if ( aIID.Equals(GetIID()) )
|
|
|
|
rawPtr = this;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsID iid_of_ISupports = NS_ISUPPORTS_IID;
|
|
|
|
if ( aIID.Equals(iid_of_ISupports) )
|
|
|
|
rawPtr = NS_STATIC_CAST(nsISupports*, this);
|
|
|
|
else
|
|
|
|
status = NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(rawPtr);
|
|
|
|
*aResult = rawPtr;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
IFoo::SetString(const nsACString& aString)
|
|
|
|
{
|
|
|
|
mString = aString;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
IFoo::GetString(nsACString& aString)
|
|
|
|
{
|
|
|
|
aString = mString;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateIFoo( IFoo** result )
|
|
|
|
// a typical factory function (that calls AddRef)
|
|
|
|
{
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" >>CreateIFoo() --> ");
|
2003-04-24 05:54:57 +04:00
|
|
|
IFoo* foop = new IFoo();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("IFoo@%p\n", NS_STATIC_CAST(void*, foop));
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
foop->AddRef();
|
|
|
|
*result = foop;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("<<CreateIFoo()\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsIEnumRead(const PRUint32& aKey, IFoo* aFoo, void* userArg) {
|
|
|
|
nsCAutoString str;
|
|
|
|
aFoo->GetString(str);
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated %u = \"%s\"\n", aKey, str.get());
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsIEnum(const PRUint32& aKey, nsCOMPtr<IFoo>& aData, void* userArg) {
|
|
|
|
nsCAutoString str;
|
|
|
|
aData->GetString(str);
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated %u = \"%s\"\n", aKey, str.get());
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsIEnum2Read(nsISupports* aKey, PRUint32 aData, void* userArg) {
|
|
|
|
nsCAutoString str;
|
|
|
|
nsCOMPtr<IFoo> foo = do_QueryInterface(aKey);
|
|
|
|
foo->GetString(str);
|
|
|
|
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated \"%s\" = %u\n", str.get(), aData);
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
nsIEnum2(nsISupports* aKey, PRUint32& aData, void* userArg) {
|
|
|
|
nsCAutoString str;
|
|
|
|
nsCOMPtr<IFoo> foo = do_QueryInterface(aKey);
|
|
|
|
foo->GetString(str);
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" enumerated \"%s\" = %u\n", str.get(), aData);
|
2003-04-24 05:54:57 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
// check an nsTHashtable
|
|
|
|
nsTHashtable<EntityToUnicodeEntry> EntityToUnicode;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsTHashtable...");
|
2003-04-24 05:54:57 +04:00
|
|
|
if (!EntityToUnicode.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (1);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Partially filling nsTHashtable:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
testTHashtable(EntityToUnicode, 5);
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerate-removing...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
PRUint32 count = EntityToUnicode.EnumerateEntries(nsTEnumStop, nsnull);
|
|
|
|
if (count != 5) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("wrong count\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (7);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Check enumeration...");
|
2003-04-24 05:54:57 +04:00
|
|
|
count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("entries remain in table!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (8);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling nsTHashtable:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
testTHashtable(EntityToUnicode, ENTITY_COUNT);
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...");
|
2003-04-24 05:54:57 +04:00
|
|
|
EntityToUnicode.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Check enumeration...");
|
2003-04-24 05:54:57 +04:00
|
|
|
count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("entries remain in table!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (9);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// now check a data-hashtable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsDataHashtable<nsUint32HashKey,const char*> UniToEntity;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsDataHashtable...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!UniToEntity.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (10);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
if (!UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (11);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
const char* str;
|
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %u...", gEntities[i].mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
if (!UniToEntity.Get(gEntities[i].mUnicode, &str)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (12);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %s\n", str);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-04-24 05:54:57 +04:00
|
|
|
if (UniToEntity.Get(99446, &str)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (13);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
count = UniToEntity.EnumerateRead(nsDEnumRead, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (14);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...");
|
2003-04-24 05:54:57 +04:00
|
|
|
UniToEntity.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-04-24 05:54:57 +04:00
|
|
|
count = UniToEntity.Enumerate(nsDEnum, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (15);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
//
|
|
|
|
// now check a thread-safe data-hashtable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsDataHashtableMT<nsUint32HashKey,const char*> UniToEntityL;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsDataHashtableMT...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!UniToEntityL.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (10);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!UniToEntityL.Put(gEntities[i].mUnicode, gEntities[i].mStr)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (11);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %u...", gEntities[i].mUnicode);
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!UniToEntityL.Get(gEntities[i].mUnicode, &str)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (12);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %s\n", str);
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (UniToEntityL.Get(99446, &str)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (13);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
count = UniToEntityL.EnumerateRead(nsDEnumRead, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (14);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...");
|
2003-06-18 15:26:27 +04:00
|
|
|
UniToEntityL.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-06-18 15:26:27 +04:00
|
|
|
count = UniToEntityL.Enumerate(nsDEnum, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (15);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
//
|
|
|
|
// now check a class-hashtable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsClassHashtable...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!EntToUniClass.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (16);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode);
|
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!EntToUniClass.Put(nsDependentCString(gEntities[i].mStr), temp)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
delete temp;
|
|
|
|
exit (17);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
TestUniChar* myChar;
|
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %s...", gEntities[i].mStr);
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!EntToUniClass.Get(nsDependentCString(gEntities[i].mStr), &myChar)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (18);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %c\n", myChar->GetChar());
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-04-24 05:54:57 +04:00
|
|
|
if (EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (19);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
count = EntToUniClass.EnumerateRead(nsCEnumRead, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (20);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
EntToUniClass.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clearing OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-04-24 05:54:57 +04:00
|
|
|
count = EntToUniClass.Enumerate(nsCEnum, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (21);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
//
|
|
|
|
// now check a thread-safe class-hashtable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsClassHashtableMT<nsCStringHashKey,TestUniChar> EntToUniClassL;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsClassHashtableMT...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!EntToUniClassL.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (16);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-06-18 15:26:27 +04:00
|
|
|
TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode);
|
|
|
|
|
|
|
|
if (!EntToUniClassL.Put(nsDependentCString(gEntities[i].mStr), temp)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
delete temp;
|
|
|
|
exit (17);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %s...", gEntities[i].mStr);
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!EntToUniClassL.Get(nsDependentCString(gEntities[i].mStr), &myChar)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (18);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %c\n", myChar->GetChar());
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (EntToUniClassL.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (19);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
count = EntToUniClassL.EnumerateRead(nsCEnumRead, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (20);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
EntToUniClassL.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clearing OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-06-18 15:26:27 +04:00
|
|
|
count = EntToUniClassL.Enumerate(nsCEnum, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (21);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
//
|
|
|
|
// now check a data-hashtable with an interface key
|
|
|
|
//
|
|
|
|
|
|
|
|
nsDataHashtable<nsISupportsHashKey,PRUint32> EntToUniClass2;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsDataHashtable with interface key...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!EntToUniClass2.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (22);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
nsCOMArray<IFoo> fooArray;
|
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
nsCOMPtr<IFoo> foo;
|
|
|
|
CreateIFoo(getter_AddRefs(foo));
|
2003-06-18 15:26:27 +04:00
|
|
|
foo->SetString(nsDependentCString(gEntities[i].mStr));
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
|
|
|
|
fooArray.InsertObjectAt(foo, i);
|
|
|
|
|
|
|
|
if (!EntToUniClass2.Put(foo, gEntities[i].mUnicode)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (23);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
PRUint32 myChar2;
|
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %s...", gEntities[i].mStr);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
if (!EntToUniClass2.Get(fooArray[i], &myChar2)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (24);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %c\n", myChar2);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-04-24 05:54:57 +04:00
|
|
|
if (EntToUniClass2.Get((nsISupports*) 0x55443316, &myChar2)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (25);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
count = EntToUniClass2.EnumerateRead(nsIEnum2Read, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (26);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
EntToUniClass2.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clearing OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-04-24 05:54:57 +04:00
|
|
|
count = EntToUniClass2.Enumerate(nsIEnum2, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (27);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// now check an interface-hashtable with an PRUint32 key
|
|
|
|
//
|
|
|
|
|
|
|
|
nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsInterfaceHashtable...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!UniToEntClass2.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (28);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-04-24 05:54:57 +04:00
|
|
|
nsCOMPtr<IFoo> foo;
|
|
|
|
CreateIFoo(getter_AddRefs(foo));
|
2003-06-18 15:26:27 +04:00
|
|
|
foo->SetString(nsDependentCString(gEntities[i].mStr));
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
if (!UniToEntClass2.Put(gEntities[i].mUnicode, foo)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (29);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %s...", gEntities[i].mStr);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
nsCOMPtr<IFoo> myEnt;
|
|
|
|
if (!UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (30);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString str;
|
|
|
|
myEnt->GetString(str);
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %s\n", str.get());
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-04-24 05:54:57 +04:00
|
|
|
nsCOMPtr<IFoo> myEnt;
|
|
|
|
if (UniToEntClass2.Get(9462, getter_AddRefs(myEnt))) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (31);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
count = UniToEntClass2.EnumerateRead(nsIEnumRead, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (32);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
UniToEntClass2.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clearing OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-04-24 05:54:57 +04:00
|
|
|
count = UniToEntClass2.Enumerate(nsIEnum, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
exit (33);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
//
|
|
|
|
// now check a thread-safe interface hashtable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsInterfaceHashtableMT<nsUint32HashKey,IFoo> UniToEntClass2L;
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsInterfaceHashtableMT...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (!UniToEntClass2L.Init(ENTITY_COUNT)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (28);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Filling hash with %d entries.\n", ENTITY_COUNT);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Putting entry %u...", gEntities[i].mUnicode);
|
2003-06-18 15:26:27 +04:00
|
|
|
nsCOMPtr<IFoo> foo;
|
|
|
|
CreateIFoo(getter_AddRefs(foo));
|
|
|
|
foo->SetString(nsDependentCString(gEntities[i].mStr));
|
|
|
|
|
|
|
|
if (!UniToEntClass2L.Put(gEntities[i].mUnicode, foo)) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (29);
|
|
|
|
}
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK...\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing Get:\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ENTITY_COUNT; ++i) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Getting entry %s...", gEntities[i].mStr);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
nsCOMPtr<IFoo> myEnt;
|
|
|
|
if (!UniToEntClass2L.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FAILED\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (30);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString str;
|
|
|
|
myEnt->GetString(str);
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Found %s\n", str.get());
|
2003-06-18 15:26:27 +04:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Testing non-existent entries...");
|
2003-06-18 15:26:27 +04:00
|
|
|
if (UniToEntClass2L.Get(9462, getter_AddRefs(myEnt))) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("FOUND! BAD!\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (31);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("not found; good.\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Enumerating:\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
count = UniToEntClass2L.EnumerateRead(nsIEnumRead, nsnull);
|
|
|
|
if (count != ENTITY_COUNT) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Bad count!\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (32);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Clearing...\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
UniToEntClass2L.Clear();
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clearing OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Checking count...");
|
2003-06-18 15:26:27 +04:00
|
|
|
count = UniToEntClass2L.Enumerate(nsIEnum, nsnull);
|
|
|
|
if (count) {
|
2004-02-07 05:41:10 +03:00
|
|
|
printf(" Clear did not remove all entries.\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
exit (33);
|
|
|
|
}
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|