mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 21:09:42 +00:00
Merge branch 'testthevfs' into 'master'
Fix vfs bindings and add tests Closes #8157 See merge request OpenMW/openmw!4371
This commit is contained in:
commit
96ec3a8125
3 changed files with 51 additions and 5 deletions
|
@ -144,7 +144,11 @@ namespace MWLua
|
|||
values.push_back(sol::make_object<std::string>(lua, msg));
|
||||
}
|
||||
else
|
||||
values.push_back(sol::make_object<std::streampos>(lua, self.mFilePtr->tellg()));
|
||||
{
|
||||
// tellg returns std::streampos which is not required to be a numeric type. It is required to be
|
||||
// convertible to std::streamoff which is a number
|
||||
values.push_back(sol::make_object<std::streamoff>(lua, self.mFilePtr->tellg()));
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
@ -205,7 +209,7 @@ namespace MWLua
|
|||
});
|
||||
};
|
||||
|
||||
handle["close"] = [](lua_State* L, FileHandle& self) {
|
||||
handle["close"] = [](sol::this_state lua, FileHandle& self) {
|
||||
sol::variadic_results values;
|
||||
try
|
||||
{
|
||||
|
@ -214,16 +218,16 @@ namespace MWLua
|
|||
{
|
||||
auto msg = "Can not close file '" + self.mFileName + "': file handle is still opened.";
|
||||
values.push_back(sol::nil);
|
||||
values.push_back(sol::make_object<std::string>(L, msg));
|
||||
values.push_back(sol::make_object<std::string>(lua, msg));
|
||||
}
|
||||
else
|
||||
values.push_back(sol::make_object<bool>(L, true));
|
||||
values.push_back(sol::make_object<bool>(lua, true));
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
auto msg = "Can not close file '" + self.mFileName + "': " + std::string(e.what());
|
||||
values.push_back(sol::nil);
|
||||
values.push_back(sol::make_object<std::string>(L, msg));
|
||||
values.push_back(sol::make_object<std::string>(lua, msg));
|
||||
}
|
||||
|
||||
return values;
|
||||
|
|
|
@ -3,6 +3,7 @@ local core = require('openmw.core')
|
|||
local async = require('openmw.async')
|
||||
local util = require('openmw.util')
|
||||
local types = require('openmw.types')
|
||||
local vfs = require('openmw.vfs')
|
||||
local world = require('openmw.world')
|
||||
|
||||
local function testTimers()
|
||||
|
@ -224,6 +225,42 @@ local function initPlayer()
|
|||
coroutine.yield()
|
||||
end
|
||||
|
||||
local function testVFS()
|
||||
local file = 'test_vfs_dir/lines.txt'
|
||||
testing.expectEqual(vfs.fileExists(file), true, 'lines.txt should exist')
|
||||
testing.expectEqual(vfs.fileExists('test_vfs_dir/nosuchfile'), false, 'nosuchfile should not exist')
|
||||
|
||||
local getLine = vfs.lines(file)
|
||||
for _,v in pairs({ '1', '2', '', '4' }) do
|
||||
testing.expectEqual(getLine(), v)
|
||||
end
|
||||
testing.expectEqual(getLine(), nil, 'All lines should have been read')
|
||||
local ok = pcall(function()
|
||||
vfs.lines('test_vfs_dir/nosuchfile')
|
||||
end)
|
||||
testing.expectEqual(ok, false, 'Should not be able to read lines from nonexistent file')
|
||||
|
||||
local getPath = vfs.pathsWithPrefix('test_vfs_dir/')
|
||||
testing.expectEqual(getPath(), file)
|
||||
testing.expectEqual(getPath(), nil, 'All paths should have been read')
|
||||
|
||||
local handle = vfs.open(file)
|
||||
testing.expectEqual(vfs.type(handle), 'file', 'File should be open')
|
||||
testing.expectEqual(handle.fileName, file)
|
||||
|
||||
local n1, n2, _, l3, l4 = handle:read("*n", "*number", "*l", "*line", "*l")
|
||||
testing.expectEqual(n1, 1)
|
||||
testing.expectEqual(n2, 2)
|
||||
testing.expectEqual(l3, '')
|
||||
testing.expectEqual(l4, '4')
|
||||
|
||||
testing.expectEqual(handle:seek('set', 0), 0, 'Reading should happen from the start of the file')
|
||||
testing.expectEqual(handle:read("*a"), '1\n2\n\n4')
|
||||
|
||||
testing.expectEqual(handle:close(), true, 'File should be closeable')
|
||||
testing.expectEqual(vfs.type(handle), 'closed file', 'File should be closed')
|
||||
end
|
||||
|
||||
tests = {
|
||||
{'timers', testTimers},
|
||||
{'rotating player with controls.yawChange should change rotation', function()
|
||||
|
@ -283,6 +320,7 @@ tests = {
|
|||
world.createObject('basic_dagger1h', 1):moveInto(player)
|
||||
testing.runLocalTest(player, 'playerWeaponAttack')
|
||||
end},
|
||||
{'vfs', testVFS},
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
1
|
||||
2
|
||||
|
||||
4
|
Loading…
Reference in a new issue