69 lines
2.4 KiB
C++
69 lines
2.4 KiB
C++
#include <iostream>
|
|
#include <filesystem>
|
|
#include "../binary_table.h"
|
|
|
|
int main() {
|
|
using namespace bt;
|
|
|
|
const std::string filename = "debug_multi.bin";
|
|
if (std::filesystem::exists(filename)) {
|
|
std::filesystem::remove(filename);
|
|
}
|
|
|
|
BinaryTable table(filename);
|
|
table.initialize();
|
|
|
|
std::cout << "=== Testing Multi-Key Storage ===" << std::endl;
|
|
|
|
// Store first key
|
|
std::cout << "1. Storing first key..." << std::endl;
|
|
table.set<int32_t>("key1", 100);
|
|
|
|
// Try to read it back
|
|
try {
|
|
int32_t val1 = table.get<int32_t>("key1");
|
|
std::cout << " ✅ First key retrieved: " << val1 << std::endl;
|
|
} catch (const std::exception& e) {
|
|
std::cout << " ❌ First key failed: " << e.what() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// Store second key - this is where it likely breaks
|
|
std::cout << "2. Storing second key..." << std::endl;
|
|
table.set<int32_t>("key2", 200);
|
|
|
|
// Try to read second key
|
|
try {
|
|
int32_t val2 = table.get<int32_t>("key2");
|
|
std::cout << " ✅ Second key retrieved: " << val2 << std::endl;
|
|
} catch (const std::exception& e) {
|
|
std::cout << " ❌ Second key failed: " << e.what() << std::endl;
|
|
}
|
|
|
|
// Try to read first key again - this will likely fail
|
|
std::cout << "3. Re-reading first key..." << std::endl;
|
|
try {
|
|
int32_t val1_again = table.get<int32_t>("key1");
|
|
std::cout << " ✅ First key still accessible: " << val1_again << std::endl;
|
|
} catch (const std::exception& e) {
|
|
std::cout << " ❌ First key now broken: " << e.what() << std::endl;
|
|
std::cout << " 💥 CONFIRMED: Table breaks after storing 2+ keys!" << std::endl;
|
|
}
|
|
|
|
// Store third key to see if pattern continues
|
|
std::cout << "4. Storing third key..." << std::endl;
|
|
try {
|
|
table.set<int32_t>("key3", 300);
|
|
int32_t val3 = table.get<int32_t>("key3");
|
|
std::cout << " ✅ Third key works: " << val3 << std::endl;
|
|
} catch (const std::exception& e) {
|
|
std::cout << " ❌ Third key failed: " << e.what() << std::endl;
|
|
}
|
|
|
|
std::cout << "\n=== Conclusion ===" << std::endl;
|
|
std::cout << "The issue is definitely in the address table management" << std::endl;
|
|
std::cout << "when storing multiple keys. Single key = perfect," << std::endl;
|
|
std::cout << "multiple keys = corruption." << std::endl;
|
|
|
|
return 0;
|
|
} |