Changeset View
Changeset View
Standalone View
Standalone View
serialization/tests/test_itemrepository.cpp
Context not available. | |||||
260 | // Choose sizes that ensure that the items fit in the desired buckets | 260 | // Choose sizes that ensure that the items fit in the desired buckets | ||
---|---|---|---|---|---|
261 | const uint bigItemSize = KDevelop::ItemRepositoryBucketSize * 0.55 - 1; | 261 | const uint bigItemSize = KDevelop::ItemRepositoryBucketSize * 0.55 - 1; | ||
262 | const uint smallItemSize = KDevelop::ItemRepositoryBucketSize * 0.25 - 1; | 262 | const uint smallItemSize = KDevelop::ItemRepositoryBucketSize * 0.25 - 1; | ||
263 | const uint monsterItemSize = KDevelop::ItemRepositoryBucketSize * 1.1; | ||||
263 | 264 | | |||
264 | // Will get placed in bucket 1 (bucket zero is invalid), so the root bucket table at position 'clashValue' will be '1' | 265 | // Will get placed in bucket 1 (bucket zero is invalid), so the root bucket table at position 'clashValue' will be '1' | ||
265 | const QScopedPointer<TestItem> firstChainFirstLink(createItem(clashValue, bigItemSize)); | 266 | const QScopedPointer<TestItem> firstChainFirstLink(createItem(clashValue, bigItemSize)); | ||
Context not available. | |||||
350 | * So TODO: Don't preserve links to items accessible from root buckets. This cannot | 351 | * So TODO: Don't preserve links to items accessible from root buckets. This cannot | ||
351 | * be done correctly using only Bucket::hasClashingItem as of now. | 352 | * be done correctly using only Bucket::hasClashingItem as of now. | ||
352 | */ | 353 | */ | ||
354 | | ||||
355 | // Re-using the first chain above, we link a monster to the end | ||||
356 | const QScopedPointer<TestItem> firstChainSecondLinkMonster(createItem(bucketHashSize + clashValue, monsterItemSize)); | ||||
357 | const uint firstChainSecondLinkMonsterIndex = repository.index(*firstChainSecondLinkMonster); | ||||
358 | QCOMPARE(bucketForIndex(firstChainSecondLinkMonsterIndex), 3u); | ||||
359 | | ||||
360 | // And link another monster to that one | ||||
361 | const QScopedPointer<TestItem> firstChainThirdLink(createItem(bucketHashSize * 2 + clashValue, monsterItemSize)); | ||||
362 | const uint firstChainThirdLinkIndex = repository.index(*firstChainThirdLink); | ||||
363 | QCOMPARE(bucketForIndex(firstChainThirdLinkIndex), 5u); | ||||
364 | | ||||
365 | /* | ||||
366 | * Now we cut the second monster out of the chain. | ||||
367 | * | ||||
368 | * What this test really cares about is that the stale link has been removed before the monster is destroyed. | ||||
369 | * | ||||
370 | * Monsters that are destroyed assert that they have no further links. That wouldn't make sense, as monsters | ||||
371 | * can only contain a single item, so removing it means it should be completely cut from the chain. | ||||
372 | * | ||||
373 | * If stale links are correctly detected and destroyed when items are removed, this will succeed. | ||||
374 | * | ||||
375 | * See also deleteClashingMonsterBucket() above, which tests this condition for root buckets | ||||
376 | */ | ||||
377 | repository.deleteItem(firstChainSecondLinkMonsterIndex); | ||||
378 | QCOMPARE(repository.findIndex(*firstChainThirdLink), firstChainThirdLinkIndex); | ||||
353 | } | 379 | } | ||
354 | }; | 380 | }; | ||
355 | 381 | | |||
Context not available. |