fix test requiring a data directory (sigsegv)

This commit is contained in:
Enno Rehling 2015-09-06 20:07:15 +02:00
parent e2b78cd8d8
commit 34580ab9fa
3 changed files with 5 additions and 1 deletions

1
.gitignore vendored
View File

@ -41,3 +41,4 @@ Thumbs.db
*.cfg *.cfg
*.cmd *.cmd
tmp/ tmp/
tests/config.lua

View File

@ -12,7 +12,7 @@ function test_store_unit()
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local fid = f.id local fid = f.id
u:add_item("money", u.number * 100) u:add_item("money", u.number * 100)
local filename = config.basepath .. "/data/test.dat" local filename = "test.dat"
store = storage.create(filename, "wb") store = storage.create(filename, "wb")
assert_not_equal(store, nil) assert_not_equal(store, nil)
store:write_unit(u) store:write_unit(u)

View File

@ -40,6 +40,9 @@ static int tolua_storage_create(lua_State * L)
data->store = store; data->store = store;
F = fopen(filename, type); F = fopen(filename, type);
if (!F) {
return 0;
}
if (strchr(type, 'r')) { if (strchr(type, 'r')) {
fread(&data->version, sizeof(int), 1, F); fread(&data->version, sizeof(int), 1, F);
fseek(F, sizeof(int), SEEK_CUR); fseek(F, sizeof(int), SEEK_CUR);