本文整理汇总了C++中Completion::FromPlaintext方法的典型用法代码示例。如果您正苦于以下问题:C++ Completion::FromPlaintext方法的具体用法?C++ Completion::FromPlaintext怎么用?C++ Completion::FromPlaintext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Completion
的用法示例。
在下文中一共展示了Completion::FromPlaintext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memcpy
// This testcase check the returned result of |Has| API if fullhash matches
// a cache entry in negative cache but that entry is expired.
TEST(UrlClassifierCaching, InNegativeCacheExpired)
{
// Create a fullhash whose prefix is in the cache.
Completion prefix;
prefix.FromPlaintext(_Fragment("cache.expired.com/"));
Completion fullhash;
fullhash.FromPlaintext(_Fragment("firefox.com/"));
memcpy(fullhash.buf, prefix.buf, 10);
TestCache<LookupCacheV2>(fullhash, true, false, true);
TestCache<LookupCacheV4>(fullhash, true, false, true);
}
示例2: GeneratePrefix
void
TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete)
{
_PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32),
GeneratePrefix(_Fragment("browsing.com/"), 8),
GeneratePrefix(_Fragment("gound.com/"), 5),
GeneratePrefix(_Fragment("small.com/"), 4)
};
RunTestInNewThread([&] () -> void {
UniquePtr<LookupCache> cache = SetupLookupCache<LookupCacheV4>(array);
Completion lookupHash;
lookupHash.FromPlaintext(aFragment);
bool has, confirmed;
uint32_t matchLength;
// Freshness is not used in V4 so we just put dummy values here.
TableFreshnessMap dummy;
nsresult rv =
cache->Has(lookupHash, &has, &matchLength, &confirmed);
EXPECT_EQ(rv, NS_OK);
EXPECT_EQ(has, aExpectedHas);
EXPECT_EQ(matchLength == COMPLETE_SIZE, aExpectedComplete);
EXPECT_EQ(confirmed, false);
cache->ClearAll();
});
}
示例3: GeneratePrefix
void
TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete)
{
_PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32),
GeneratePrefix(_Fragment("browsing.com/"), 8),
GeneratePrefix(_Fragment("gound.com/"), 5),
GeneratePrefix(_Fragment("small.com/"), 4)
};
RunTestInNewThread([&] () -> void {
UniquePtr<LookupCache> cache = SetupLookupCacheV4(array);
Completion lookupHash;
nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID);
lookupHash.FromPlaintext(aFragment, cryptoHash);
bool has, complete;
nsresult rv = cache->Has(lookupHash, &has, &complete);
EXPECT_EQ(rv, NS_OK);
EXPECT_EQ(has, aExpectedHas);
EXPECT_EQ(complete, aExpectedComplete);
cache->ClearAll();
});
}
示例4:
// Generate a hash prefix from string
static const nsCString
GeneratePrefix(const _Fragment& aFragment, uint8_t aLength)
{
Completion complete;
nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID);
complete.FromPlaintext(aFragment, cryptoHash);
nsCString hash;
hash.Assign((const char *)complete.buf, aLength);
return hash;
}
示例5:
void
TestCache(const _Fragment& aFragment,
bool aExpectedHas,
bool aExpectedConfirmed,
bool aExpectedInCache,
T* aCache = nullptr)
{
Completion lookupHash;
lookupHash.FromPlaintext(aFragment);
TestCache<T>(lookupHash, aExpectedHas, aExpectedConfirmed, aExpectedInCache, aCache);
}
示例6: ActiveTables
nsresult
Classifier::Check(const nsACString& aSpec, LookupResultArray& aResults)
{
Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_CL_CHECK_TIME> timer;
// Get the set of fragments to look up.
nsTArray<nsCString> fragments;
nsresult rv = LookupCache::GetLookupFragments(aSpec, &fragments);
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<nsCString> activeTables;
ActiveTables(activeTables);
nsTArray<LookupCache*> cacheArray;
for (PRUint32 i = 0; i < activeTables.Length(); i++) {
LookupCache *cache = GetLookupCache(activeTables[i]);
if (cache) {
cacheArray.AppendElement(cache);
} else {
return NS_ERROR_FAILURE;
}
}
// Now check each lookup fragment against the entries in the DB.
for (PRUint32 i = 0; i < fragments.Length(); i++) {
Completion lookupHash;
lookupHash.FromPlaintext(fragments[i], mCryptoHash);
// Get list of host keys to look up
Completion hostKey;
rv = LookupCache::GetKey(fragments[i], &hostKey, mCryptoHash);
if (NS_FAILED(rv)) {
// Local host on the network
continue;
}
#if DEBUG && defined(PR_LOGGING)
if (LOG_ENABLED()) {
nsCAutoString checking;
lookupHash.ToString(checking);
LOG(("Checking %s (%X)", checking.get(), lookupHash.ToUint32()));
}
#endif
for (PRUint32 i = 0; i < cacheArray.Length(); i++) {
LookupCache *cache = cacheArray[i];
bool has, complete;
Prefix codedPrefix;
rv = cache->Has(lookupHash, hostKey, mHashKey,
&has, &complete, &codedPrefix);
NS_ENSURE_SUCCESS(rv, rv);
if (has) {
LookupResult *result = aResults.AppendElement();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
PRInt64 age;
bool found = mTableFreshness.Get(cache->TableName(), &age);
if (!found) {
age = 24 * 60 * 60; // just a large number
} else {
PRInt64 now = (PR_Now() / PR_USEC_PER_SEC);
age = now - age;
}
LOG(("Found a result in %s: %s (Age: %Lds)",
cache->TableName().get(),
complete ? "complete." : "Not complete.",
age));
result->hash.complete = lookupHash;
result->mCodedPrefix = codedPrefix;
result->mComplete = complete;
result->mFresh = (age < mFreshTime);
result->mTableName.Assign(cache->TableName());
}
}
}
return NS_OK;
}