2015-07-23 12:36:13 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
#include "gtest/gtest.h"
|
2005-11-08 21:17:49 +03:00
|
|
|
|
2008-08-18 20:45:38 +04:00
|
|
|
namespace TestHashtables {
|
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
class TestUniChar // for nsClassHashtable
|
|
|
|
{
|
|
|
|
public:
|
2014-08-05 17:36:59 +04:00
|
|
|
explicit TestUniChar(uint32_t aWord)
|
2003-04-24 05:54:57 +04:00
|
|
|
{
|
|
|
|
mWord = aWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestUniChar()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2014-08-05 17:36:59 +04:00
|
|
|
explicit 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;
|
|
|
|
};
|
|
|
|
|
2015-07-23 12:36:13 +03:00
|
|
|
static uint32_t
|
|
|
|
nsTIterPrint(nsTHashtable<EntityToUnicodeEntry>& hash)
|
|
|
|
{
|
|
|
|
uint32_t n = 0;
|
|
|
|
for (auto iter = hash.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return n;
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 12:36:13 +03:00
|
|
|
static uint32_t
|
|
|
|
nsTIterPrintRemove(nsTHashtable<EntityToUnicodeEntry>& hash)
|
|
|
|
{
|
|
|
|
uint32_t n = 0;
|
|
|
|
for (auto iter = hash.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Remove();
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return n;
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
testTHashtable(nsTHashtable<EntityToUnicodeEntry>& hash, uint32_t numEntries) {
|
|
|
|
uint32_t i;
|
2003-04-24 05:54:57 +04:00
|
|
|
for (i = 0; i < numEntries; ++i) {
|
|
|
|
EntityToUnicodeEntry* entry =
|
|
|
|
hash.PutEntry(gEntities[i].mStr);
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
EXPECT_TRUE(entry);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
EXPECT_FALSE(entry->mNode);
|
2003-04-24 05:54:57 +04:00
|
|
|
entry->mNode = &gEntities[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numEntries; ++i) {
|
|
|
|
EntityToUnicodeEntry* entry =
|
|
|
|
hash.GetEntry(gEntities[i].mStr);
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
EXPECT_TRUE(entry);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
EntityToUnicodeEntry* entry =
|
|
|
|
hash.GetEntry("xxxy");
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
EXPECT_FALSE(entry);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2015-07-23 12:36:13 +03:00
|
|
|
uint32_t count = nsTIterPrint(hash);
|
2016-11-01 02:58:42 +03:00
|
|
|
EXPECT_EQ(count, numEntries);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
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 } }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IFoo 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();
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef();
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release();
|
2003-04-24 05:54:57 +04:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IFoo::IFoo()
|
|
|
|
: refcount_(0)
|
|
|
|
{
|
|
|
|
++total_constructions_;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFoo::~IFoo()
|
|
|
|
{
|
|
|
|
++total_destructions_;
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
MozExternalRefCountType
|
2003-04-24 05:54:57 +04:00
|
|
|
IFoo::AddRef()
|
|
|
|
{
|
|
|
|
++refcount_;
|
|
|
|
return refcount_;
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
MozExternalRefCountType
|
2003-04-24 05:54:57 +04:00
|
|
|
IFoo::Release()
|
|
|
|
{
|
2007-01-26 05:50:18 +03:00
|
|
|
int newcount = --refcount_;
|
|
|
|
if ( newcount == 0 )
|
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
|
|
|
{
|
|
|
|
nsISupports* rawPtr = 0;
|
|
|
|
nsresult status = NS_OK;
|
|
|
|
|
2014-03-18 04:23:11 +04:00
|
|
|
if ( aIID.Equals(NS_GET_IID(IFoo)) )
|
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)
|
|
|
|
{
|
|
|
|
IFoo* foop = new IFoo();
|
|
|
|
|
|
|
|
foop->AddRef();
|
|
|
|
*result = foop;
|
|
|
|
|
2012-07-27 17:59:29 +04:00
|
|
|
return NS_OK;
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace TestHashtables
|
2008-08-18 20:45:38 +04:00
|
|
|
|
|
|
|
using namespace TestHashtables;
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
TEST(Hashtable, THashtable)
|
2016-11-01 02:34:24 +03:00
|
|
|
{
|
2003-04-24 05:54:57 +04:00
|
|
|
// check an nsTHashtable
|
2013-09-02 12:41:57 +04:00
|
|
|
nsTHashtable<EntityToUnicodeEntry> EntityToUnicode(ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
testTHashtable(EntityToUnicode, 5);
|
|
|
|
|
2015-07-23 12:36:13 +03:00
|
|
|
uint32_t count = nsTIterPrintRemove(EntityToUnicode);
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(5));
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2015-07-23 12:36:13 +03:00
|
|
|
count = nsTIterPrint(EntityToUnicode);
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(0));
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
testTHashtable(EntityToUnicode, ENTITY_COUNT);
|
|
|
|
|
|
|
|
EntityToUnicode.Clear();
|
|
|
|
|
2015-07-23 12:36:13 +03:00
|
|
|
count = nsTIterPrint(EntityToUnicode);
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(0));
|
2016-11-01 02:34:24 +03:00
|
|
|
}
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
TEST(Hashtables, DataHashtable)
|
2016-11-01 02:34:24 +03:00
|
|
|
{
|
2016-11-01 02:58:42 +03:00
|
|
|
// check a data-hashtable
|
2013-09-02 12:41:57 +04:00
|
|
|
nsDataHashtable<nsUint32HashKey,const char*> UniToEntity(ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
2012-05-18 21:30:49 +04:00
|
|
|
UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* str;
|
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_TRUE(UniToEntity.Get(gEntities[i].mUnicode, &str));
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_FALSE(UniToEntity.Get(99446, &str));
|
2016-11-04 09:00:47 +03:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
uint32_t count = 0;
|
2015-11-23 01:39:01 +03:00
|
|
|
for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, ENTITY_COUNT);
|
2015-11-23 01:39:01 +03:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
UniToEntity.Clear();
|
|
|
|
|
2015-11-25 06:42:28 +03:00
|
|
|
count = 0;
|
|
|
|
for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
printf(" enumerated %u = \"%s\"\n", iter.Key(), iter.Data());
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(0));
|
2016-11-01 02:34:24 +03:00
|
|
|
}
|
2016-11-04 09:00:47 +03:00
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
TEST(Hashtables, ClassHashtable)
|
2016-11-01 02:34:24 +03:00
|
|
|
{
|
2016-11-01 02:58:42 +03:00
|
|
|
// check a class-hashtable
|
2013-09-02 12:41:57 +04:00
|
|
|
nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass(ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
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);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TestUniChar* myChar;
|
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_TRUE(EntToUniClass.Get(nsDependentCString(gEntities[i].mStr), &myChar));
|
2016-11-04 09:00:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_FALSE(EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar));
|
2015-11-23 01:39:01 +03:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
uint32_t count = 0;
|
2015-11-23 01:39:01 +03:00
|
|
|
for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, ENTITY_COUNT);
|
2015-11-23 01:39:01 +03:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
EntToUniClass.Clear();
|
|
|
|
|
2015-11-25 06:42:28 +03:00
|
|
|
count = 0;
|
|
|
|
for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(0));
|
2016-11-01 02:34:24 +03:00
|
|
|
}
|
2016-11-04 09:00:47 +03:00
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
TEST(Hashtables, DataHashtableWithInterfaceKey)
|
2016-11-01 02:34:24 +03:00
|
|
|
{
|
2016-11-01 02:58:42 +03:00
|
|
|
// check a data-hashtable with an interface key
|
2013-09-02 12:41:57 +04:00
|
|
|
nsDataHashtable<nsISupportsHashKey,uint32_t> EntToUniClass2(ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
|
|
|
nsCOMArray<IFoo> fooArray;
|
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
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));
|
2014-08-06 17:31:21 +04:00
|
|
|
|
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);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t myChar2;
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_TRUE(EntToUniClass2.Get(fooArray[i], &myChar2));
|
2016-11-04 09:00:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_FALSE(EntToUniClass2.Get((nsISupports*) 0x55443316, &myChar2));
|
2016-11-04 09:00:47 +03:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
uint32_t count = 0;
|
2015-11-23 01:39:01 +03:00
|
|
|
for (auto iter = EntToUniClass2.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoCString s;
|
|
|
|
nsCOMPtr<IFoo> foo = do_QueryInterface(iter.Key());
|
|
|
|
foo->GetString(s);
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, ENTITY_COUNT);
|
2015-11-23 01:39:01 +03:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
EntToUniClass2.Clear();
|
|
|
|
|
2015-11-25 06:42:28 +03:00
|
|
|
count = 0;
|
|
|
|
for (auto iter = EntToUniClass2.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoCString s;
|
|
|
|
nsCOMPtr<IFoo> foo = do_QueryInterface(iter.Key());
|
|
|
|
foo->GetString(s);
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(0));
|
2016-11-01 02:34:24 +03:00
|
|
|
}
|
2016-11-04 09:00:47 +03:00
|
|
|
|
2016-11-01 02:58:42 +03:00
|
|
|
TEST(Hashtables, InterfaceHashtable)
|
2016-11-01 02:34:24 +03:00
|
|
|
{
|
2016-11-01 02:58:42 +03:00
|
|
|
// check an interface-hashtable with an uint32_t key
|
2013-09-02 12:41:57 +04:00
|
|
|
nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2(ENTITY_COUNT);
|
2003-04-24 05:54:57 +04:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
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));
|
2014-08-06 17:31:21 +04:00
|
|
|
|
2012-05-18 21:30:49 +04:00
|
|
|
UniToEntClass2.Put(gEntities[i].mUnicode, foo);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
|
2003-04-24 05:54:57 +04:00
|
|
|
nsCOMPtr<IFoo> myEnt;
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_TRUE(UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt)));
|
2015-09-08 09:56:16 +03:00
|
|
|
|
|
|
|
nsAutoCString myEntStr;
|
|
|
|
myEnt->GetString(myEntStr);
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<IFoo> myEnt;
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_FALSE(UniToEntClass2.Get(9462, getter_AddRefs(myEnt)));
|
2016-11-04 09:00:47 +03:00
|
|
|
|
2016-11-01 02:34:24 +03:00
|
|
|
uint32_t count = 0;
|
2015-11-23 01:39:01 +03:00
|
|
|
for (auto iter = UniToEntClass2.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoCString s;
|
|
|
|
iter.UserData()->GetString(s);
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, ENTITY_COUNT);
|
2015-11-23 01:39:01 +03:00
|
|
|
|
2003-04-24 05:54:57 +04:00
|
|
|
UniToEntClass2.Clear();
|
|
|
|
|
2015-11-25 06:42:28 +03:00
|
|
|
count = 0;
|
|
|
|
for (auto iter = UniToEntClass2.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoCString s;
|
|
|
|
iter.Data()->GetString(s);
|
|
|
|
count++;
|
|
|
|
}
|
2016-11-01 02:58:42 +03:00
|
|
|
ASSERT_EQ(count, uint32_t(0));
|
2003-04-24 05:54:57 +04:00
|
|
|
}
|