2003-04-24 05:54:57 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsBaseHashtable.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsCOMArray.h"
|
2012-06-20 07:41:56 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2005-11-08 21:17:49 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-08-18 20:45:38 +04:00
|
|
|
namespace TestHashtables {
|
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
class TestUniChar // for nsClassHashtable
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 19:56:38 +04:00
|
|
|
TestUniChar(uint32_t aWord)
|
2003-04-24 05:54:57 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetChar() const { return mWord; }
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mWord;
|
2003-04-24 05:54:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EntityNode {
|
|
|
|
const char* mStr; // never owns buffer
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mUnicode;
|
2003-04-24 05:54:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
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}
|
|
|
|
};
|
|
|
|
|
2010-05-18 03:36:31 +04:00
|
|
|
#define ENTITY_COUNT (unsigned(sizeof(gEntities)/sizeof(EntityNode)))
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
class EntityToUnicodeEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const char* KeyType;
|
|
|
|
typedef const char* KeyTypePointer;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
EntityToUnicodeEntry(const char* aKey) { mNode = nullptr; }
|
2003-04-24 05:54:57 +04:00
|
|
|
EntityToUnicodeEntry(const EntityToUnicodeEntry& aEntry) { mNode = aEntry.mNode; }
|
2012-12-09 21:23:19 +04:00
|
|
|
~EntityToUnicodeEntry() { }
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool KeyEquals(const char* aEntity) const { return !strcmp(mNode->mStr, aEntity); }
|
2003-04-24 05:54:57 +04:00
|
|
|
static const char* KeyToPointer(const char* aEntity) { return aEntity; }
|
2012-03-13 02:53:18 +04:00
|
|
|
static PLDHashNumber HashKey(const char* aEntity) { return mozilla::HashString(aEntity); }
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
testTHashtable(nsTHashtable<EntityToUnicodeEntry>& hash, uint32_t 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
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-23 23:26:15 +04:00
|
|
|
printf("Testing nonexistent 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");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = hash.EnumerateEntries(nsTEnumGo, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDEnumRead(const uint32_t& 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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDEnum(const uint32_t& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-08-18 21:38:50 +04:00
|
|
|
// all this nsIFoo stuff was copied wholesale from TestCOMPtr.cpp
|
2003-04-24 05:54:57 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
#define NS_IFOO_IID \
|
|
|
|
{ 0x6f7652e0, 0xee43, 0x11d1, \
|
|
|
|
{ 0x9c, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
|
|
|
|
|
2012-06-20 07:41:56 +04:00
|
|
|
class IFoo MOZ_FINAL : public nsISupports
|
2003-04-24 05:54:57 +04:00
|
|
|
{
|
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
|
|
|
|
|
|
|
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",
|
2007-07-08 11:08:04 +04:00
|
|
|
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",
|
2007-07-08 11:08:04 +04:00
|
|
|
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",
|
2007-07-08 11:08:04 +04:00
|
|
|
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",
|
2007-07-08 11:08:04 +04:00
|
|
|
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
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
printf(" delete IFoo@%p\n", static_cast<void*>(this));
|
|
|
|
printf("<<IFoo@%p::Release()\n", 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
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
printf("IFoo@%p::QueryInterface()\n", static_cast<void*>(this));
|
2004-12-27 06:23:01 +03:00
|
|
|
nsISupports* rawPtr = 0;
|
|
|
|
nsresult status = NS_OK;
|
|
|
|
|
2014-03-18 02:19:53 +04:00
|
|
|
if ( aIID.Equals(GetIID()) )
|
2004-12-27 06:23:01 +03:00
|
|
|
rawPtr = this;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsID iid_of_ISupports = NS_ISUPPORTS_IID;
|
|
|
|
if ( aIID.Equals(iid_of_ISupports) )
|
2007-07-08 11:08:04 +04:00
|
|
|
rawPtr = static_cast<nsISupports*>(this);
|
2004-12-27 06:23:01 +03:00
|
|
|
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();
|
2007-07-08 11:08:04 +04:00
|
|
|
printf("IFoo@%p\n", 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");
|
2012-07-27 17:59:29 +04:00
|
|
|
return NS_OK;
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIEnumRead(const uint32_t& aKey, IFoo* aFoo, void* userArg) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIEnum(const uint32_t& aKey, nsCOMPtr<IFoo>& aData, void* userArg) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIEnum2Read(nsISupports* aKey, uint32_t aData, void* userArg) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIEnum2(nsISupports* aKey, uint32_t& aData, void* userArg) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2003-04-24 05:54:57 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-08-18 20:45:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
using namespace TestHashtables;
|
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
// check an nsTHashtable
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsTHashtable...");
|
2013-09-02 12:41:57 +04:00
|
|
|
nsTHashtable<EntityToUnicodeEntry> EntityToUnicode(ENTITY_COUNT);
|
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");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = EntityToUnicode.EnumerateEntries(nsTEnumStop, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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...");
|
2012-07-30 18:20:58 +04:00
|
|
|
count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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...");
|
2012-07-30 18:20:58 +04:00
|
|
|
count = EntityToUnicode.EnumerateEntries(nsTEnumGo, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
|
//
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsDataHashtable...");
|
2013-09-02 12:41:57 +04:00
|
|
|
nsDataHashtable<nsUint32HashKey,const char*> UniToEntity(ENTITY_COUNT);
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2010-05-18 03:36:31 +04:00
|
|
|
printf("Filling hash with %u entries.\n", ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
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);
|
2012-05-18 21:30:49 +04:00
|
|
|
UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr);
|
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
|
|
|
}
|
|
|
|
|
2010-05-23 23:26:15 +04:00
|
|
|
printf("Testing nonexistent 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
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
count = UniToEntity.EnumerateRead(nsDEnumRead, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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...");
|
2012-07-30 18:20:58 +04:00
|
|
|
count = UniToEntity.Enumerate(nsDEnum, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
|
|
|
|
//
|
|
|
|
// now check a class-hashtable
|
|
|
|
//
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsClassHashtable...");
|
2013-09-02 12:41:57 +04:00
|
|
|
nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass(ENTITY_COUNT);
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2010-05-18 03:36:31 +04:00
|
|
|
printf("Filling hash with %u 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);
|
|
|
|
|
2012-05-18 21:30:49 +04:00
|
|
|
EntToUniClass.Put(nsDependentCString(gEntities[i].mStr), temp);
|
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
|
|
|
}
|
|
|
|
|
2010-05-23 23:26:15 +04:00
|
|
|
printf("Testing nonexistent 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
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
count = EntToUniClass.EnumerateRead(nsCEnumRead, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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...");
|
2012-07-30 18:20:58 +04:00
|
|
|
count = EntToUniClass.Enumerate(nsCEnum, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
|
|
|
|
//
|
|
|
|
// now check a data-hashtable with an interface key
|
|
|
|
//
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsDataHashtable with interface key...");
|
2013-09-02 12:41:57 +04:00
|
|
|
nsDataHashtable<nsISupportsHashKey,uint32_t> EntToUniClass2(ENTITY_COUNT);
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2010-05-18 03:36:31 +04:00
|
|
|
printf("Filling hash with %u 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);
|
|
|
|
|
2012-05-18 21:30:49 +04:00
|
|
|
EntToUniClass2.Put(foo, gEntities[i].mUnicode);
|
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");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t myChar2;
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-23 23:26:15 +04:00
|
|
|
printf("Testing nonexistent 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
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
count = EntToUniClass2.EnumerateRead(nsIEnum2Read, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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...");
|
2012-07-30 18:20:58 +04:00
|
|
|
count = EntToUniClass2.Enumerate(nsIEnum2, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
|
|
|
|
//
|
2012-08-22 19:56:38 +04:00
|
|
|
// now check an interface-hashtable with an uint32_t key
|
2003-04-24 05:54:57 +04:00
|
|
|
//
|
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("Initializing nsInterfaceHashtable...");
|
2013-09-02 12:41:57 +04:00
|
|
|
nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2(ENTITY_COUNT);
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("OK\n");
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2010-05-18 03:36:31 +04:00
|
|
|
printf("Filling hash with %u 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
|
|
|
|
2012-05-18 21:30:49 +04:00
|
|
|
UniToEntClass2.Put(gEntities[i].mUnicode, foo);
|
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);
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-23 23:26:15 +04:00
|
|
|
printf("Testing nonexistent 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
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
count = UniToEntClass2.EnumerateRead(nsIEnumRead, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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...");
|
2012-07-30 18:20:58 +04:00
|
|
|
count = UniToEntClass2.Enumerate(nsIEnum, nullptr);
|
2003-04-24 05:54:57 +04:00
|
|
|
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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|