void *FlowGetStorageById(Flow *f, int id) { return StorageGetById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id); }
static int StorageTest02(void) { struct StorageTest02Data *test = NULL; StorageInit(); int id1 = StorageRegister(STORAGE_HOST, "test", 4, StorageTest02Init, StorageTestFree); if (id1 < 0) { printf("StorageRegister failed (2): "); goto error; } int id2 = StorageRegister(STORAGE_HOST, "test2", 4, StorageTest02Init, StorageTestFree); if (id2 < 0) { printf("StorageRegister failed (2): "); goto error; } if (StorageFinalize() < 0) { printf("StorageFinalize failed: "); goto error; } Storage *storage = NULL; void *data = StorageAllocById(&storage, STORAGE_HOST, id1); if (data == NULL) { printf("StorageAllocById failed, data == NULL, storage %p: ", storage); goto error; } test = (struct StorageTest02Data *)data; if (test->abc != 1234) { printf("setup failed, test->abc != 1234, but %d (1):", test->abc); goto error; } test->abc = 4321; data = StorageAllocById(&storage, STORAGE_HOST, id2); if (data == NULL) { printf("StorageAllocById failed, data == NULL, storage %p: ", storage); goto error; } test = (struct StorageTest02Data *)data; if (test->abc != 1234) { printf("setup failed, test->abc != 1234, but %d (2):", test->abc); goto error; } data = StorageGetById(storage, STORAGE_HOST, id1); if (data == NULL) { printf("StorageAllocById failed, data == NULL, storage %p: ", storage); goto error; } test = (struct StorageTest02Data *)data; if (test->abc != 4321) { printf("setup failed, test->abc != 4321, but %d (3):", test->abc); goto error; } //StorageFreeById(storage, STORAGE_HOST, id1); //StorageFreeById(storage, STORAGE_HOST, id2); StorageFree(&storage, STORAGE_HOST); StorageCleanup(); return 1; error: StorageCleanup(); return 0; }