#include #include #include #include #include #include #include int main(void) { const auto temp_dir_str = (std::filesystem::temp_directory_path() / "test_obj_store_tests").u8string(); assert(!std::filesystem::exists(temp_dir_str)); // test1, create store with 2 objects { ObjectStore2 os; Backends::FilesystemStorageAtomic fsa{os, temp_dir_str}; // empty, does nothing fsa.scanAsync(); assert(!std::filesystem::exists(temp_dir_str)); { // o1 // id1 std::vector id{0x00, 0x13, 0x37, 0x01}; auto o = fsa.newObject(ByteSpan{id}); std::vector data{0x01, 0x01, 0x11, 0xf1, 0xae, 0x0b, 0x33}; static_cast(fsa).write(o, ByteSpan{data}); } { // o2 // id2 std::vector id{0x00, 0x13, 0x37, 0x02}; auto o = fsa.newObject(ByteSpan{id}); std::vector data{0x11, 0x11, 0x11, 0xff, 0xff, 0xee, 0xee}; static_cast(fsa).write(o, ByteSpan{data}); } } assert(std::filesystem::exists(temp_dir_str)); // test2, load store created in test1 { ObjectStore2 os; Backends::FilesystemStorageAtomic fsa{os, temp_dir_str}; fsa.scanAsync(); assert(os.registry().storage().size() == 2); { // o1 std::vector id{0x00, 0x13, 0x37, 0x01}; auto o = os.getOneObjectByID(ByteSpan{id}); assert(static_cast(o)); std::vector orig_data{0x01, 0x01, 0x11, 0xf1, 0xae, 0x0b, 0x33}; // TODO: read and test content //static_cast(fsa).write(o, ByteSpan{data}); } { // o2 std::vector id{0x00, 0x13, 0x37, 0x02}; auto o = os.getOneObjectByID(ByteSpan{id}); assert(static_cast(o)); } } std::filesystem::remove_all(temp_dir_str); return 0; }