@todo Add a test where the complete content is deleted again, and make sure the result has a nice structure @todo More consistency and lost-space tests, especially about monster-buckets. Make sure their space is re-claimed
| 129 | ///@todo Add a test where the complete content is deleted again, and make sure the result has a nice structure |
| 130 | ///@todo More consistency and lost-space tests, especially about monster-buckets. Make sure their space is re-claimed |
| 131 | class TestItemRepository |
| 132 | : public ItemRepositoryTestBase |
| 133 | { |
| 134 | Q_OBJECT |
| 135 | |
| 136 | private Q_SLOTS: |
| 137 | void testItemRepository() |
| 138 | { |
| 139 | QMutex mutex; |
| 140 | ItemRepository<TestItem, TestItemRequest> repository(QStringLiteral("TestItemRepository"), &mutex); |
| 141 | |
| 142 | // calling statistics here does some extended tests and shouldn't crash or assert |
| 143 | repository.statistics(); |
| 144 | |
| 145 | uint itemId = 0; |
| 146 | QHash<uint, TestItem*> realItemsByIndex; |
| 147 | QHash<uint, TestItem*> realItemsById; |
| 148 | uint totalInsertions = 0, totalDeletions = 0; |
| 149 | uint maxSize = 0; |
| 150 | uint totalSize = 0; |
| 151 | srand(12345); |
| 152 | uint highestSeenIndex = 0; |
| 153 | |
| 154 | for (uint a = 0; a < cycles; ++a) { |
| 155 | { |
| 156 | //Insert an item |
| 157 | uint itemDecision = rand() % (smallItemsFraction + largeItemsFraction); |
| 158 | uint itemSize; |
| 159 | if (itemDecision < largeItemsFraction) { |
| 160 | //Create a large item: Up to 200kb |
| 161 | itemSize = (rand() % 200000) + sizeof(TestItem); |
| 162 | } else |
| 163 | itemSize = (rand() % 1000) + sizeof(TestItem); |
| 164 | TestItem* item = createItem(++itemId, itemSize); |
| 165 | Q_ASSERT(item->hash() == itemId); |
| 166 | QVERIFY(item->equals(item)); |
| 167 | uint index = repository.index(TestItemRequest(*item)); |
| 168 | if (index > highestSeenIndex) |
| 169 | highestSeenIndex = index; |
| 170 | Q_ASSERT(index); |
| 171 | realItemsByIndex.insert(index, item); |
| 172 | realItemsById.insert(itemId, item); |
| 173 | ++totalInsertions; |
| 174 | totalSize += itemSize; |
| 175 | if (itemSize > maxSize) |
| 176 | maxSize = itemSize; |
| 177 | } |
| 178 | |
| 179 | for (uint a = 0; a < checksPerCycle; ++a) { |
| 180 | //Check an item |
| 181 | uint pick = rand() % itemId; |
| 182 | if (realItemsById.contains(pick)) { |
| 183 | uint index = repository.findIndex(*realItemsById[pick]); |
| 184 | QVERIFY(index); |
| 185 | QVERIFY(realItemsByIndex.contains(index)); |
| 186 | QVERIFY(realItemsByIndex[index]->equals(repository.itemFromIndex(index))); |
| 187 | |
| 188 | if (( uint ) (rand() % 100) < deletionProbability) { |
nothing calls this directly
no test coverage detected