gecko-dev/xpcom/tests/gtest/TestHashtables.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

545 строки
14 KiB
C++
Исходник Обычный вид История

/* -*- 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/. */
#include "nsTHashtable.h"
#include "nsBaseHashtable.h"
#include "nsDataHashtable.h"
#include "nsInterfaceHashtable.h"
#include "nsClassHashtable.h"
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsCOMArray.h"
#include "mozilla/Attributes.h"
#include "gtest/gtest.h"
namespace TestHashtables {
class TestUniChar // for nsClassHashtable
{
public:
explicit TestUniChar(uint32_t aWord) { mWord = aWord; }
~TestUniChar() = default;
uint32_t GetChar() const { return mWord; }
private:
uint32_t mWord;
};
struct EntityNode {
const char* mStr; // never owns buffer
uint32_t mUnicode;
};
Bug 1534878 - xpcom: Make some global functions static. r=erahm clang's -Wmissing-prototypes option identifies global functions that can be made static (because they're only called from one compilation unit) or removed (if they're never called). xpcom/base/Logging.cpp:85:13 [-Wmissing-prototypes] no previous prototype for function 'ToLogStr' xpcom/base/Logging.cpp:132:13 [-Wmissing-prototypes] no previous prototype for function 'ExpandPIDMarker' xpcom/base/LogModulePrefWatcher.cpp:37:6 [-Wmissing-prototypes] no previous prototype for function 'ResetExistingPrefs' xpcom/base/LogModulePrefWatcher.cpp:109:6 [-Wmissing-prototypes] no previous prototype for function 'LoadExistingPrefs' xpcom/base/nsCycleCollector.cpp:212:6 [-Wmissing-prototypes] no previous prototype for function 'SuspectUsingNurseryPurpleBuffer' xpcom/components/nsComponentManager.cpp:421:31 [-Wmissing-prototypes] no previous prototype for function 'begin' xpcom/components/nsComponentManager.cpp:427:31 [-Wmissing-prototypes] no previous prototype for function 'end' xpcom/ds/Dafsa.cpp:23:6 [-Wmissing-prototypes] no previous prototype for function 'GetNextOffset' xpcom/ds/Dafsa.cpp:55:6 [-Wmissing-prototypes] no previous prototype for function 'IsEOL' xpcom/ds/Dafsa.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'IsMatch' xpcom/ds/Dafsa.cpp:70:6 [-Wmissing-prototypes] no previous prototype for function 'IsEndCharMatch' xpcom/ds/Dafsa.cpp:78:6 [-Wmissing-prototypes] no previous prototype for function 'GetReturnValue' xpcom/ds/Dafsa.cpp:91:5 [-Wmissing-prototypes] no previous prototype for function 'LookupString' xpcom/io/CocoaFileUtils.mm:195:13 [-Wmissing-prototypes] no previous prototype for function 'GetQuarantinePropKey' xpcom/io/CocoaFileUtils.mm:203:24 [-Wmissing-prototypes] no previous prototype for function 'CreateQuarantineDictionary' xpcom/rust/gtest/bench-collections/Bench.cpp:65:11 [-Wmissing-prototypes] no previous prototype for function 'MyRand' xpcom/rust/gtest/bench-collections/Bench.cpp:85:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_unordered_set' xpcom/rust/gtest/bench-collections/Bench.cpp:125:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_PLDHashTable' xpcom/rust/gtest/bench-collections/Bench.cpp:166:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_MozHashSet' xpcom/tests/gtest/TestAtoms.cpp:114:6 [-Wmissing-prototypes] no previous prototype for function 'isStaticAtom' xpcom/tests/gtest/TestCallTemplates.cpp:72:6 [-Wmissing-prototypes] no previous prototype for function 'JustTestingCompilation' xpcom/tests/gtest/TestCOMPtr.cpp:87:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestCOMPtr.cpp:98:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:105:16 [-Wmissing-prototypes] no previous prototype for function 'return_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:164:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIBar' xpcom/tests/gtest/TestCOMPtr.cpp:175:6 [-Wmissing-prototypes] no previous prototype for function 'AnIFooPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:177:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:179:6 [-Wmissing-prototypes] no previous prototype for function 'AnISupportsPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:263:6 [-Wmissing-prototypes] no previous prototype for function 'Comparison' xpcom/tests/gtest/TestCOMPtr.cpp:298:6 [-Wmissing-prototypes] no previous prototype for function 'DontAddRef' xpcom/tests/gtest/TestCRT.cpp:17:5 [-Wmissing-prototypes] no previous prototype for function 'sign' xpcom/tests/gtest/TestDeadlockDetector.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'DisableCrashReporter' xpcom/tests/gtest/TestDeadlockDetector.cpp:74:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:95:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity2_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:159:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity4_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:182:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity5_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:303:5 [-Wmissing-prototypes] no previous prototype for function 'ContentionNoDeadlock_Child' xpcom/tests/gtest/TestHashtables.cpp:88:6 [-Wmissing-prototypes] no previous prototype for function 'testTHashtable' xpcom/tests/gtest/TestHashtables.cpp:205:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestMoveString.cpp:25:6 [-Wmissing-prototypes] no previous prototype for function 'SetAsOwned' xpcom/tests/gtest/TestMoveString.cpp:34:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectTruncated' xpcom/tests/gtest/TestMoveString.cpp:40:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectNew' xpcom/tests/gtest/TestMruCache.cpp:52:11 [-Wmissing-prototypes] no previous prototype for function 'MakeStringKey' xpcom/tests/gtest/TestMultiplexInputStream.cpp:106:34 [-Wmissing-prototypes] no previous prototype for function 'CreateStreamHelper' xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp:62:10 [-Wmissing-prototypes] no previous prototype for function 'ReadSegmentsFunction' xpcom/tests/gtest/TestNsDeque.cpp:240:6 [-Wmissing-prototypes] no previous prototype for function 'CheckIfQueueEmpty' xpcom/tests/gtest/TestNsRefPtr.cpp:105:10 [-Wmissing-prototypes] no previous prototype for function 'CreateFoo' xpcom/tests/gtest/TestNsRefPtr.cpp:116:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:123:13 [-Wmissing-prototypes] no previous prototype for function 'return_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:391:6 [-Wmissing-prototypes] no previous prototype for function 'AnFooPtrPtrContext' xpcom/tests/gtest/TestNsRefPtr.cpp:392:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestPLDHash.cpp:33:6 [-Wmissing-prototypes] no previous prototype for function 'TestCrashyOperation' xpcom/tests/gtest/TestPipes.cpp:98:10 [-Wmissing-prototypes] no previous prototype for function 'TestPipe' xpcom/tests/gtest/TestPipes.cpp:212:10 [-Wmissing-prototypes] no previous prototype for function 'TestShortWrites' xpcom/tests/gtest/TestPipes.cpp:354:6 [-Wmissing-prototypes] no previous prototype for function 'RunTests' xpcom/tests/gtest/TestPLDHash.cpp:90:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialLengthTooBig' xpcom/tests/gtest/TestPLDHash.cpp:95:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialEntryStoreTooBig' xpcom/tests/gtest/TestPLDHash.cpp:102:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_EntrySizeTooBig' xpcom/tests/gtest/TestSlicedInputStream.cpp:111:20 [-Wmissing-prototypes] no previous prototype for function 'CreateSeekableStreams' xpcom/tests/gtest/TestSlicedInputStream.cpp:125:20 [-Wmissing-prototypes] no previous prototype for function 'CreateNonSeekableStreams' xpcom/tests/gtest/TestStrings.cpp:471:6 [-Wmissing-prototypes] no previous prototype for function 'test_assign_helper' xpcom/tests/gtest/TestTArray.cpp:60:22 [-Wmissing-prototypes] no previous prototype for function 'DummyArray' xpcom/tests/gtest/TestTArray.cpp:72:22 [-Wmissing-prototypes] no previous prototype for function 'FakeHugeArray' xpcom/tests/gtest/TestThrottledEventQueue.cpp:96:6 [-Wmissing-prototypes] no previous prototype for function 'Enqueue' xpcom/threads/BlockingResourceBase.cpp:86:6 [-Wmissing-prototypes] no previous prototype for function 'PrintCycle' xpcom/threads/CPUUsageWatcher.cpp:41:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:46:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:51:40 [-Wmissing-prototypes] no previous prototype for function 'GetProcessCPUStats' xpcom/threads/CPUUsageWatcher.cpp:80:40 [-Wmissing-prototypes] no previous prototype for function 'GetGlobalCPUStats' xpcom/threads/nsTimerImpl.cpp:196:21 [-Wmissing-prototypes] no previous prototype for function 'GetTimerFiringsLog' Differential Revision: https://phabricator.services.mozilla.com/D23264 --HG-- extra : rebase_source : e03df033209e0a08fc263603e78bc16a09467f15 extra : source : 3beec9fbfdedf346fff85309029e7805717958ac
2019-02-25 04:35:59 +03:00
static const 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 (unsigned(sizeof(gEntities) / sizeof(EntityNode)))
class EntityToUnicodeEntry : public PLDHashEntryHdr {
public:
typedef const char* KeyType;
typedef const char* KeyTypePointer;
explicit EntityToUnicodeEntry(const char* aKey) { mNode = nullptr; }
EntityToUnicodeEntry(const EntityToUnicodeEntry& aEntry) {
mNode = aEntry.mNode;
}
~EntityToUnicodeEntry() = default;
bool KeyEquals(const char* aEntity) const {
return !strcmp(mNode->mStr, aEntity);
}
static const char* KeyToPointer(const char* aEntity) { return aEntity; }
static PLDHashNumber HashKey(const char* aEntity) {
return mozilla::HashString(aEntity);
}
enum { ALLOW_MEMMOVE = true };
const EntityNode* mNode;
};
static uint32_t nsTIterPrint(nsTHashtable<EntityToUnicodeEntry>& hash) {
uint32_t n = 0;
for (auto iter = hash.Iter(); !iter.Done(); iter.Next()) {
n++;
}
return n;
}
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;
}
Bug 1534878 - xpcom: Make some global functions static. r=erahm clang's -Wmissing-prototypes option identifies global functions that can be made static (because they're only called from one compilation unit) or removed (if they're never called). xpcom/base/Logging.cpp:85:13 [-Wmissing-prototypes] no previous prototype for function 'ToLogStr' xpcom/base/Logging.cpp:132:13 [-Wmissing-prototypes] no previous prototype for function 'ExpandPIDMarker' xpcom/base/LogModulePrefWatcher.cpp:37:6 [-Wmissing-prototypes] no previous prototype for function 'ResetExistingPrefs' xpcom/base/LogModulePrefWatcher.cpp:109:6 [-Wmissing-prototypes] no previous prototype for function 'LoadExistingPrefs' xpcom/base/nsCycleCollector.cpp:212:6 [-Wmissing-prototypes] no previous prototype for function 'SuspectUsingNurseryPurpleBuffer' xpcom/components/nsComponentManager.cpp:421:31 [-Wmissing-prototypes] no previous prototype for function 'begin' xpcom/components/nsComponentManager.cpp:427:31 [-Wmissing-prototypes] no previous prototype for function 'end' xpcom/ds/Dafsa.cpp:23:6 [-Wmissing-prototypes] no previous prototype for function 'GetNextOffset' xpcom/ds/Dafsa.cpp:55:6 [-Wmissing-prototypes] no previous prototype for function 'IsEOL' xpcom/ds/Dafsa.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'IsMatch' xpcom/ds/Dafsa.cpp:70:6 [-Wmissing-prototypes] no previous prototype for function 'IsEndCharMatch' xpcom/ds/Dafsa.cpp:78:6 [-Wmissing-prototypes] no previous prototype for function 'GetReturnValue' xpcom/ds/Dafsa.cpp:91:5 [-Wmissing-prototypes] no previous prototype for function 'LookupString' xpcom/io/CocoaFileUtils.mm:195:13 [-Wmissing-prototypes] no previous prototype for function 'GetQuarantinePropKey' xpcom/io/CocoaFileUtils.mm:203:24 [-Wmissing-prototypes] no previous prototype for function 'CreateQuarantineDictionary' xpcom/rust/gtest/bench-collections/Bench.cpp:65:11 [-Wmissing-prototypes] no previous prototype for function 'MyRand' xpcom/rust/gtest/bench-collections/Bench.cpp:85:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_unordered_set' xpcom/rust/gtest/bench-collections/Bench.cpp:125:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_PLDHashTable' xpcom/rust/gtest/bench-collections/Bench.cpp:166:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_MozHashSet' xpcom/tests/gtest/TestAtoms.cpp:114:6 [-Wmissing-prototypes] no previous prototype for function 'isStaticAtom' xpcom/tests/gtest/TestCallTemplates.cpp:72:6 [-Wmissing-prototypes] no previous prototype for function 'JustTestingCompilation' xpcom/tests/gtest/TestCOMPtr.cpp:87:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestCOMPtr.cpp:98:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:105:16 [-Wmissing-prototypes] no previous prototype for function 'return_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:164:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIBar' xpcom/tests/gtest/TestCOMPtr.cpp:175:6 [-Wmissing-prototypes] no previous prototype for function 'AnIFooPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:177:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:179:6 [-Wmissing-prototypes] no previous prototype for function 'AnISupportsPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:263:6 [-Wmissing-prototypes] no previous prototype for function 'Comparison' xpcom/tests/gtest/TestCOMPtr.cpp:298:6 [-Wmissing-prototypes] no previous prototype for function 'DontAddRef' xpcom/tests/gtest/TestCRT.cpp:17:5 [-Wmissing-prototypes] no previous prototype for function 'sign' xpcom/tests/gtest/TestDeadlockDetector.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'DisableCrashReporter' xpcom/tests/gtest/TestDeadlockDetector.cpp:74:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:95:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity2_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:159:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity4_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:182:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity5_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:303:5 [-Wmissing-prototypes] no previous prototype for function 'ContentionNoDeadlock_Child' xpcom/tests/gtest/TestHashtables.cpp:88:6 [-Wmissing-prototypes] no previous prototype for function 'testTHashtable' xpcom/tests/gtest/TestHashtables.cpp:205:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestMoveString.cpp:25:6 [-Wmissing-prototypes] no previous prototype for function 'SetAsOwned' xpcom/tests/gtest/TestMoveString.cpp:34:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectTruncated' xpcom/tests/gtest/TestMoveString.cpp:40:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectNew' xpcom/tests/gtest/TestMruCache.cpp:52:11 [-Wmissing-prototypes] no previous prototype for function 'MakeStringKey' xpcom/tests/gtest/TestMultiplexInputStream.cpp:106:34 [-Wmissing-prototypes] no previous prototype for function 'CreateStreamHelper' xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp:62:10 [-Wmissing-prototypes] no previous prototype for function 'ReadSegmentsFunction' xpcom/tests/gtest/TestNsDeque.cpp:240:6 [-Wmissing-prototypes] no previous prototype for function 'CheckIfQueueEmpty' xpcom/tests/gtest/TestNsRefPtr.cpp:105:10 [-Wmissing-prototypes] no previous prototype for function 'CreateFoo' xpcom/tests/gtest/TestNsRefPtr.cpp:116:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:123:13 [-Wmissing-prototypes] no previous prototype for function 'return_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:391:6 [-Wmissing-prototypes] no previous prototype for function 'AnFooPtrPtrContext' xpcom/tests/gtest/TestNsRefPtr.cpp:392:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestPLDHash.cpp:33:6 [-Wmissing-prototypes] no previous prototype for function 'TestCrashyOperation' xpcom/tests/gtest/TestPipes.cpp:98:10 [-Wmissing-prototypes] no previous prototype for function 'TestPipe' xpcom/tests/gtest/TestPipes.cpp:212:10 [-Wmissing-prototypes] no previous prototype for function 'TestShortWrites' xpcom/tests/gtest/TestPipes.cpp:354:6 [-Wmissing-prototypes] no previous prototype for function 'RunTests' xpcom/tests/gtest/TestPLDHash.cpp:90:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialLengthTooBig' xpcom/tests/gtest/TestPLDHash.cpp:95:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialEntryStoreTooBig' xpcom/tests/gtest/TestPLDHash.cpp:102:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_EntrySizeTooBig' xpcom/tests/gtest/TestSlicedInputStream.cpp:111:20 [-Wmissing-prototypes] no previous prototype for function 'CreateSeekableStreams' xpcom/tests/gtest/TestSlicedInputStream.cpp:125:20 [-Wmissing-prototypes] no previous prototype for function 'CreateNonSeekableStreams' xpcom/tests/gtest/TestStrings.cpp:471:6 [-Wmissing-prototypes] no previous prototype for function 'test_assign_helper' xpcom/tests/gtest/TestTArray.cpp:60:22 [-Wmissing-prototypes] no previous prototype for function 'DummyArray' xpcom/tests/gtest/TestTArray.cpp:72:22 [-Wmissing-prototypes] no previous prototype for function 'FakeHugeArray' xpcom/tests/gtest/TestThrottledEventQueue.cpp:96:6 [-Wmissing-prototypes] no previous prototype for function 'Enqueue' xpcom/threads/BlockingResourceBase.cpp:86:6 [-Wmissing-prototypes] no previous prototype for function 'PrintCycle' xpcom/threads/CPUUsageWatcher.cpp:41:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:46:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:51:40 [-Wmissing-prototypes] no previous prototype for function 'GetProcessCPUStats' xpcom/threads/CPUUsageWatcher.cpp:80:40 [-Wmissing-prototypes] no previous prototype for function 'GetGlobalCPUStats' xpcom/threads/nsTimerImpl.cpp:196:21 [-Wmissing-prototypes] no previous prototype for function 'GetTimerFiringsLog' Differential Revision: https://phabricator.services.mozilla.com/D23264 --HG-- extra : rebase_source : e03df033209e0a08fc263603e78bc16a09467f15 extra : source : 3beec9fbfdedf346fff85309029e7805717958ac
2019-02-25 04:35:59 +03:00
static void testTHashtable(nsTHashtable<EntityToUnicodeEntry>& hash,
uint32_t numEntries) {
uint32_t i;
for (i = 0; i < numEntries; ++i) {
EntityToUnicodeEntry* entry = hash.PutEntry(gEntities[i].mStr);
EXPECT_TRUE(entry);
EXPECT_FALSE(entry->mNode);
entry->mNode = &gEntities[i];
}
for (i = 0; i < numEntries; ++i) {
EntityToUnicodeEntry* entry = hash.GetEntry(gEntities[i].mStr);
EXPECT_TRUE(entry);
}
EntityToUnicodeEntry* entry = hash.GetEntry("xxxy");
EXPECT_FALSE(entry);
uint32_t count = nsTIterPrint(hash);
EXPECT_EQ(count, numEntries);
}
//
// 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 final : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
IFoo();
NS_IMETHOD_(MozExternalRefCountType) AddRef() override;
NS_IMETHOD_(MozExternalRefCountType) Release() override;
NS_IMETHOD QueryInterface(const nsIID&, void**) override;
NS_IMETHOD SetString(const nsACString& /*in*/ aString);
NS_IMETHOD GetString(nsACString& /*out*/ aString);
static void print_totals();
private:
~IFoo();
unsigned int refcount_;
static unsigned int total_constructions_;
static unsigned int total_destructions_;
nsCString mString;
};
NS_DEFINE_STATIC_IID_ACCESSOR(IFoo, NS_IFOO_IID)
unsigned int IFoo::total_constructions_;
unsigned int IFoo::total_destructions_;
void IFoo::print_totals() {}
IFoo::IFoo() : refcount_(0) { ++total_constructions_; }
IFoo::~IFoo() { ++total_destructions_; }
MozExternalRefCountType IFoo::AddRef() {
++refcount_;
return refcount_;
}
MozExternalRefCountType IFoo::Release() {
int newcount = --refcount_;
if (newcount == 0) {
delete this;
}
return newcount;
}
nsresult IFoo::QueryInterface(const nsIID& aIID, void** aResult) {
nsISupports* rawPtr = 0;
nsresult status = NS_OK;
if (aIID.Equals(NS_GET_IID(IFoo)))
rawPtr = this;
else {
nsID iid_of_ISupports = NS_ISUPPORTS_IID;
if (aIID.Equals(iid_of_ISupports))
rawPtr = static_cast<nsISupports*>(this);
else
status = NS_ERROR_NO_INTERFACE;
}
NS_IF_ADDREF(rawPtr);
*aResult = rawPtr;
return status;
}
nsresult IFoo::SetString(const nsACString& aString) {
mString = aString;
return NS_OK;
}
nsresult IFoo::GetString(nsACString& aString) {
aString = mString;
return NS_OK;
}
Bug 1534878 - xpcom: Make some global functions static. r=erahm clang's -Wmissing-prototypes option identifies global functions that can be made static (because they're only called from one compilation unit) or removed (if they're never called). xpcom/base/Logging.cpp:85:13 [-Wmissing-prototypes] no previous prototype for function 'ToLogStr' xpcom/base/Logging.cpp:132:13 [-Wmissing-prototypes] no previous prototype for function 'ExpandPIDMarker' xpcom/base/LogModulePrefWatcher.cpp:37:6 [-Wmissing-prototypes] no previous prototype for function 'ResetExistingPrefs' xpcom/base/LogModulePrefWatcher.cpp:109:6 [-Wmissing-prototypes] no previous prototype for function 'LoadExistingPrefs' xpcom/base/nsCycleCollector.cpp:212:6 [-Wmissing-prototypes] no previous prototype for function 'SuspectUsingNurseryPurpleBuffer' xpcom/components/nsComponentManager.cpp:421:31 [-Wmissing-prototypes] no previous prototype for function 'begin' xpcom/components/nsComponentManager.cpp:427:31 [-Wmissing-prototypes] no previous prototype for function 'end' xpcom/ds/Dafsa.cpp:23:6 [-Wmissing-prototypes] no previous prototype for function 'GetNextOffset' xpcom/ds/Dafsa.cpp:55:6 [-Wmissing-prototypes] no previous prototype for function 'IsEOL' xpcom/ds/Dafsa.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'IsMatch' xpcom/ds/Dafsa.cpp:70:6 [-Wmissing-prototypes] no previous prototype for function 'IsEndCharMatch' xpcom/ds/Dafsa.cpp:78:6 [-Wmissing-prototypes] no previous prototype for function 'GetReturnValue' xpcom/ds/Dafsa.cpp:91:5 [-Wmissing-prototypes] no previous prototype for function 'LookupString' xpcom/io/CocoaFileUtils.mm:195:13 [-Wmissing-prototypes] no previous prototype for function 'GetQuarantinePropKey' xpcom/io/CocoaFileUtils.mm:203:24 [-Wmissing-prototypes] no previous prototype for function 'CreateQuarantineDictionary' xpcom/rust/gtest/bench-collections/Bench.cpp:65:11 [-Wmissing-prototypes] no previous prototype for function 'MyRand' xpcom/rust/gtest/bench-collections/Bench.cpp:85:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_unordered_set' xpcom/rust/gtest/bench-collections/Bench.cpp:125:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_PLDHashTable' xpcom/rust/gtest/bench-collections/Bench.cpp:166:6 [-Wmissing-prototypes] no previous prototype for function 'Bench_Cpp_MozHashSet' xpcom/tests/gtest/TestAtoms.cpp:114:6 [-Wmissing-prototypes] no previous prototype for function 'isStaticAtom' xpcom/tests/gtest/TestCallTemplates.cpp:72:6 [-Wmissing-prototypes] no previous prototype for function 'JustTestingCompilation' xpcom/tests/gtest/TestCOMPtr.cpp:87:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestCOMPtr.cpp:98:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:105:16 [-Wmissing-prototypes] no previous prototype for function 'return_a_IFoo' xpcom/tests/gtest/TestCOMPtr.cpp:164:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIBar' xpcom/tests/gtest/TestCOMPtr.cpp:175:6 [-Wmissing-prototypes] no previous prototype for function 'AnIFooPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:177:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:179:6 [-Wmissing-prototypes] no previous prototype for function 'AnISupportsPtrPtrContext' xpcom/tests/gtest/TestCOMPtr.cpp:263:6 [-Wmissing-prototypes] no previous prototype for function 'Comparison' xpcom/tests/gtest/TestCOMPtr.cpp:298:6 [-Wmissing-prototypes] no previous prototype for function 'DontAddRef' xpcom/tests/gtest/TestCRT.cpp:17:5 [-Wmissing-prototypes] no previous prototype for function 'sign' xpcom/tests/gtest/TestDeadlockDetector.cpp:62:6 [-Wmissing-prototypes] no previous prototype for function 'DisableCrashReporter' xpcom/tests/gtest/TestDeadlockDetector.cpp:74:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:95:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity2_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:159:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity4_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:182:5 [-Wmissing-prototypes] no previous prototype for function 'Sanity5_Child' xpcom/tests/gtest/TestDeadlockDetector.cpp:303:5 [-Wmissing-prototypes] no previous prototype for function 'ContentionNoDeadlock_Child' xpcom/tests/gtest/TestHashtables.cpp:88:6 [-Wmissing-prototypes] no previous prototype for function 'testTHashtable' xpcom/tests/gtest/TestHashtables.cpp:205:10 [-Wmissing-prototypes] no previous prototype for function 'CreateIFoo' xpcom/tests/gtest/TestMoveString.cpp:25:6 [-Wmissing-prototypes] no previous prototype for function 'SetAsOwned' xpcom/tests/gtest/TestMoveString.cpp:34:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectTruncated' xpcom/tests/gtest/TestMoveString.cpp:40:6 [-Wmissing-prototypes] no previous prototype for function 'ExpectNew' xpcom/tests/gtest/TestMruCache.cpp:52:11 [-Wmissing-prototypes] no previous prototype for function 'MakeStringKey' xpcom/tests/gtest/TestMultiplexInputStream.cpp:106:34 [-Wmissing-prototypes] no previous prototype for function 'CreateStreamHelper' xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp:62:10 [-Wmissing-prototypes] no previous prototype for function 'ReadSegmentsFunction' xpcom/tests/gtest/TestNsDeque.cpp:240:6 [-Wmissing-prototypes] no previous prototype for function 'CheckIfQueueEmpty' xpcom/tests/gtest/TestNsRefPtr.cpp:105:10 [-Wmissing-prototypes] no previous prototype for function 'CreateFoo' xpcom/tests/gtest/TestNsRefPtr.cpp:116:6 [-Wmissing-prototypes] no previous prototype for function 'set_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:123:13 [-Wmissing-prototypes] no previous prototype for function 'return_a_Foo' xpcom/tests/gtest/TestNsRefPtr.cpp:391:6 [-Wmissing-prototypes] no previous prototype for function 'AnFooPtrPtrContext' xpcom/tests/gtest/TestNsRefPtr.cpp:392:6 [-Wmissing-prototypes] no previous prototype for function 'AVoidPtrPtrContext' xpcom/tests/gtest/TestPLDHash.cpp:33:6 [-Wmissing-prototypes] no previous prototype for function 'TestCrashyOperation' xpcom/tests/gtest/TestPipes.cpp:98:10 [-Wmissing-prototypes] no previous prototype for function 'TestPipe' xpcom/tests/gtest/TestPipes.cpp:212:10 [-Wmissing-prototypes] no previous prototype for function 'TestShortWrites' xpcom/tests/gtest/TestPipes.cpp:354:6 [-Wmissing-prototypes] no previous prototype for function 'RunTests' xpcom/tests/gtest/TestPLDHash.cpp:90:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialLengthTooBig' xpcom/tests/gtest/TestPLDHash.cpp:95:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_InitialEntryStoreTooBig' xpcom/tests/gtest/TestPLDHash.cpp:102:6 [-Wmissing-prototypes] no previous prototype for function 'InitCapacityOk_EntrySizeTooBig' xpcom/tests/gtest/TestSlicedInputStream.cpp:111:20 [-Wmissing-prototypes] no previous prototype for function 'CreateSeekableStreams' xpcom/tests/gtest/TestSlicedInputStream.cpp:125:20 [-Wmissing-prototypes] no previous prototype for function 'CreateNonSeekableStreams' xpcom/tests/gtest/TestStrings.cpp:471:6 [-Wmissing-prototypes] no previous prototype for function 'test_assign_helper' xpcom/tests/gtest/TestTArray.cpp:60:22 [-Wmissing-prototypes] no previous prototype for function 'DummyArray' xpcom/tests/gtest/TestTArray.cpp:72:22 [-Wmissing-prototypes] no previous prototype for function 'FakeHugeArray' xpcom/tests/gtest/TestThrottledEventQueue.cpp:96:6 [-Wmissing-prototypes] no previous prototype for function 'Enqueue' xpcom/threads/BlockingResourceBase.cpp:86:6 [-Wmissing-prototypes] no previous prototype for function 'PrintCycle' xpcom/threads/CPUUsageWatcher.cpp:41:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:46:10 [-Wmissing-prototypes] no previous prototype for function 'GetMicroseconds' xpcom/threads/CPUUsageWatcher.cpp:51:40 [-Wmissing-prototypes] no previous prototype for function 'GetProcessCPUStats' xpcom/threads/CPUUsageWatcher.cpp:80:40 [-Wmissing-prototypes] no previous prototype for function 'GetGlobalCPUStats' xpcom/threads/nsTimerImpl.cpp:196:21 [-Wmissing-prototypes] no previous prototype for function 'GetTimerFiringsLog' Differential Revision: https://phabricator.services.mozilla.com/D23264 --HG-- extra : rebase_source : e03df033209e0a08fc263603e78bc16a09467f15 extra : source : 3beec9fbfdedf346fff85309029e7805717958ac
2019-02-25 04:35:59 +03:00
static nsresult CreateIFoo(IFoo** result)
// a typical factory function (that calls AddRef)
{
auto* foop = new IFoo();
foop->AddRef();
*result = foop;
return NS_OK;
}
} // namespace TestHashtables
using namespace TestHashtables;
TEST(Hashtable, THashtable)
{
// check an nsTHashtable
nsTHashtable<EntityToUnicodeEntry> EntityToUnicode(ENTITY_COUNT);
testTHashtable(EntityToUnicode, 5);
uint32_t count = nsTIterPrintRemove(EntityToUnicode);
ASSERT_EQ(count, uint32_t(5));
count = nsTIterPrint(EntityToUnicode);
ASSERT_EQ(count, uint32_t(0));
testTHashtable(EntityToUnicode, ENTITY_COUNT);
EntityToUnicode.Clear();
count = nsTIterPrint(EntityToUnicode);
ASSERT_EQ(count, uint32_t(0));
}
TEST(Hashtable, Move)
{
const void* kPtr = reinterpret_cast<void*>(static_cast<uintptr_t>(0xbadc0de));
nsTHashtable<nsPtrHashKey<const void>> table;
table.PutEntry(kPtr);
nsTHashtable<nsPtrHashKey<const void>> moved = std::move(table);
ASSERT_EQ(table.Count(), 0u);
ASSERT_EQ(moved.Count(), 1u);
EXPECT_TRUE(moved.Contains(kPtr));
EXPECT_FALSE(table.Contains(kPtr));
}
TEST(Hashtables, DataHashtable)
{
// check a data-hashtable
nsDataHashtable<nsUint32HashKey, const char*> UniToEntity(ENTITY_COUNT);
for (auto& entity : gEntities) {
UniToEntity.Put(entity.mUnicode, entity.mStr);
}
const char* str;
for (auto& entity : gEntities) {
ASSERT_TRUE(UniToEntity.Get(entity.mUnicode, &str));
}
ASSERT_FALSE(UniToEntity.Get(99446, &str));
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
uint32_t count = 0;
for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
count++;
}
ASSERT_EQ(count, ENTITY_COUNT);
UniToEntity.Clear();
count = 0;
for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
printf(" enumerated %u = \"%s\"\n", iter.Key(), iter.Data());
count++;
}
ASSERT_EQ(count, uint32_t(0));
}
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
TEST(Hashtables, ClassHashtable)
{
// check a class-hashtable
nsClassHashtable<nsCStringHashKey, TestUniChar> EntToUniClass(ENTITY_COUNT);
for (auto& entity : gEntities) {
auto* temp = new TestUniChar(entity.mUnicode);
EntToUniClass.Put(nsDependentCString(entity.mStr), temp);
}
TestUniChar* myChar;
for (auto& entity : gEntities) {
ASSERT_TRUE(EntToUniClass.Get(nsDependentCString(entity.mStr), &myChar));
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
}
ASSERT_FALSE(EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar));
uint32_t count = 0;
for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
count++;
}
ASSERT_EQ(count, ENTITY_COUNT);
EntToUniClass.Clear();
count = 0;
for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
count++;
}
ASSERT_EQ(count, uint32_t(0));
}
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
TEST(Hashtables, DataHashtableWithInterfaceKey)
{
// check a data-hashtable with an interface key
nsDataHashtable<nsISupportsHashKey, uint32_t> EntToUniClass2(ENTITY_COUNT);
nsCOMArray<IFoo> fooArray;
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
nsCOMPtr<IFoo> foo;
CreateIFoo(getter_AddRefs(foo));
foo->SetString(nsDependentCString(gEntities[i].mStr));
fooArray.InsertObjectAt(foo, i);
EntToUniClass2.Put(foo, gEntities[i].mUnicode);
}
uint32_t myChar2;
for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
ASSERT_TRUE(EntToUniClass2.Get(fooArray[i], &myChar2));
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
}
ASSERT_FALSE(EntToUniClass2.Get((nsISupports*)0x55443316, &myChar2));
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
uint32_t count = 0;
for (auto iter = EntToUniClass2.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString s;
nsCOMPtr<IFoo> foo = do_QueryInterface(iter.Key());
foo->GetString(s);
count++;
}
ASSERT_EQ(count, ENTITY_COUNT);
EntToUniClass2.Clear();
count = 0;
for (auto iter = EntToUniClass2.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString s;
nsCOMPtr<IFoo> foo = do_QueryInterface(iter.Key());
foo->GetString(s);
count++;
}
ASSERT_EQ(count, uint32_t(0));
}
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
TEST(Hashtables, InterfaceHashtable)
{
// check an interface-hashtable with an uint32_t key
nsInterfaceHashtable<nsUint32HashKey, IFoo> UniToEntClass2(ENTITY_COUNT);
for (auto& entity : gEntities) {
nsCOMPtr<IFoo> foo;
CreateIFoo(getter_AddRefs(foo));
foo->SetString(nsDependentCString(entity.mStr));
UniToEntClass2.Put(entity.mUnicode, foo);
}
for (auto& entity : gEntities) {
nsCOMPtr<IFoo> myEnt;
ASSERT_TRUE(UniToEntClass2.Get(entity.mUnicode, getter_AddRefs(myEnt)));
nsAutoCString myEntStr;
myEnt->GetString(myEntStr);
}
nsCOMPtr<IFoo> myEnt;
ASSERT_FALSE(UniToEntClass2.Get(9462, getter_AddRefs(myEnt)));
Backed out 18 changesets (bug 1313469, bug 1313468, bug 1313474, bug 1313472, bug 1313473, bug 1313470, bug 1313471, bug 1313467, bug 1313466) for OS X gtest crashes CLOSED TREE Backed out changeset 5b5686e1bcd1 (bug 1313474) Backed out changeset e8d20bdd13d4 (bug 1313473) Backed out changeset 643bdd25166e (bug 1313473) Backed out changeset 9a33c84ab30a (bug 1313472) Backed out changeset 4d84926813e9 (bug 1313472) Backed out changeset c85e7a7a5a99 (bug 1313471) Backed out changeset 5d82bc9436ab (bug 1313471) Backed out changeset 00f7b342bb29 (bug 1313470) Backed out changeset f012923cfd8b (bug 1313470) Backed out changeset e7d5b8135ae6 (bug 1313470) Backed out changeset 82bf00ff6505 (bug 1313469) Backed out changeset 5364fc8db9b0 (bug 1313469) Backed out changeset 02959aa60196 (bug 1313468) Backed out changeset 3c25a6ed5914 (bug 1313467) Backed out changeset 0acc0a131101 (bug 1313467) Backed out changeset 6fae1bbd3819 (bug 1313467) Backed out changeset 107eb264a40d (bug 1313467) Backed out changeset 9b60e295a885 (bug 1313466) MozReview-Commit-ID: IKsAZxBYMfv --HG-- rename : xpcom/tests/gtest/TestAutoPtr.cpp => xpcom/tests/TestAutoPtr.cpp rename : xpcom/tests/gtest/TestAutoRef.cpp => xpcom/tests/TestAutoRef.cpp rename : xpcom/tests/gtest/TestCOMArray.cpp => xpcom/tests/TestCOMArray.cpp rename : xpcom/tests/gtest/TestCOMPtr.cpp => xpcom/tests/TestCOMPtr.cpp rename : xpcom/tests/gtest/TestCOMPtrEq.cpp => xpcom/tests/TestCOMPtrEq.cpp rename : xpcom/tests/gtest/TestFile.cpp => xpcom/tests/TestFile.cpp rename : xpcom/tests/gtest/TestHashtables.cpp => xpcom/tests/TestHashtables.cpp rename : xpcom/tests/gtest/TestID.cpp => xpcom/tests/TestID.cpp
2016-11-04 09:00:47 +03:00
uint32_t count = 0;
for (auto iter = UniToEntClass2.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString s;
iter.UserData()->GetString(s);
count++;
}
ASSERT_EQ(count, ENTITY_COUNT);
UniToEntClass2.Clear();
count = 0;
for (auto iter = UniToEntClass2.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString s;
iter.Data()->GetString(s);
count++;
}
ASSERT_EQ(count, uint32_t(0));
}
TEST(Hashtables, DataHashtable_LookupForAdd)
{
// check LookupForAdd/OrInsert
nsDataHashtable<nsUint32HashKey, const char*> UniToEntity(ENTITY_COUNT);
for (auto& entity : gEntities) {
auto entry = UniToEntity.LookupForAdd(entity.mUnicode);
const char* val = entry.OrInsert([&entity]() { return entity.mStr; });
ASSERT_FALSE(entry);
ASSERT_TRUE(val == entity.mStr);
ASSERT_TRUE(entry.Data() == entity.mStr);
}
for (auto& entity : gEntities) {
ASSERT_TRUE(UniToEntity.LookupForAdd(entity.mUnicode));
}
// 0 should not be found
size_t count = UniToEntity.Count();
UniToEntity.Lookup(0U).Remove();
ASSERT_TRUE(count == UniToEntity.Count());
// Lookup should find all entries
count = 0;
for (auto& entity : gEntities) {
if (UniToEntity.Lookup(entity.mUnicode)) {
count++;
}
}
ASSERT_TRUE(count == UniToEntity.Count());
for (auto& entity : gEntities) {
ASSERT_TRUE(UniToEntity.LookupForAdd(entity.mUnicode));
}
// Lookup().Remove() should remove all entries.
for (auto& entity : gEntities) {
if (auto entry = UniToEntity.Lookup(entity.mUnicode)) {
entry.Remove();
}
}
ASSERT_TRUE(0 == UniToEntity.Count());
// Remove newly added entries via OrRemove.
for (auto& entity : gEntities) {
auto entry = UniToEntity.LookupForAdd(entity.mUnicode);
ASSERT_FALSE(entry);
entry.OrRemove();
}
ASSERT_TRUE(0 == UniToEntity.Count());
// Remove existing entries via OrRemove.
for (auto& entity : gEntities) {
auto entry = UniToEntity.LookupForAdd(entity.mUnicode);
const char* val = entry.OrInsert([&entity]() { return entity.mStr; });
ASSERT_FALSE(entry);
ASSERT_TRUE(val == entity.mStr);
ASSERT_TRUE(entry.Data() == entity.mStr);
auto entry2 = UniToEntity.LookupForAdd(entity.mUnicode);
ASSERT_TRUE(entry2);
entry2.OrRemove();
}
ASSERT_TRUE(0 == UniToEntity.Count());
}
TEST(Hashtables, ClassHashtable_LookupForAdd)
{
// check a class-hashtable LookupForAdd with null values
nsClassHashtable<nsCStringHashKey, TestUniChar> EntToUniClass(ENTITY_COUNT);
for (auto& entity : gEntities) {
auto entry = EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr));
const TestUniChar* val = entry.OrInsert([]() { return nullptr; });
ASSERT_FALSE(entry);
ASSERT_TRUE(val == nullptr);
ASSERT_TRUE(entry.Data() == nullptr);
}
for (auto& entity : gEntities) {
ASSERT_TRUE(EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr)));
ASSERT_TRUE(
EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr)).Data() ==
nullptr);
}
// "" should not be found
size_t count = EntToUniClass.Count();
EntToUniClass.Lookup(nsDependentCString("")).Remove();
ASSERT_TRUE(count == EntToUniClass.Count());
// Lookup should find all entries.
count = 0;
for (auto& entity : gEntities) {
if (EntToUniClass.Lookup(nsDependentCString(entity.mStr))) {
count++;
}
}
ASSERT_TRUE(count == EntToUniClass.Count());
for (auto& entity : gEntities) {
ASSERT_TRUE(EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr)));
}
// Lookup().Remove() should remove all entries.
for (auto& entity : gEntities) {
if (auto entry = EntToUniClass.Lookup(nsDependentCString(entity.mStr))) {
entry.Remove();
}
}
ASSERT_TRUE(0 == EntToUniClass.Count());
// Remove newly added entries via OrRemove.
for (auto& entity : gEntities) {
auto entry = EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr));
ASSERT_FALSE(entry);
entry.OrRemove();
}
ASSERT_TRUE(0 == EntToUniClass.Count());
// Remove existing entries via OrRemove.
for (auto& entity : gEntities) {
auto entry = EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr));
const TestUniChar* val = entry.OrInsert([]() { return nullptr; });
ASSERT_FALSE(entry);
ASSERT_TRUE(val == nullptr);
ASSERT_TRUE(entry.Data() == nullptr);
auto entry2 = EntToUniClass.LookupForAdd(nsDependentCString(entity.mStr));
ASSERT_TRUE(entry2);
entry2.OrRemove();
}
ASSERT_TRUE(0 == EntToUniClass.Count());
}