1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Fixed and tested all VFS tests

This commit is contained in:
Nicolay Korslund 2010-01-01 17:06:41 +01:00
parent c5316804b5
commit 9e332c4067
10 changed files with 46 additions and 40 deletions

View File

@ -7,8 +7,8 @@ using namespace Mangle::Stream;
Ogre::DataStreamPtr MangleArchive::open(const Ogre::String& filename) const Ogre::DataStreamPtr MangleArchive::open(const Ogre::String& filename) const
{ {
return Ogre::DataStreamPtr(new MangleDataStream return Ogre::DataStreamPtr(new Mangle2OgreStream
(filename, vfs->open(filename), true)); (filename, vfs->open(filename)));
} }
static void fill(Ogre::FileInfoList &out, FileInfoList &in) static void fill(Ogre::FileInfoList &out, FileInfoList &in)

View File

@ -26,7 +26,8 @@ class MangleArchive : public Ogre::Archive
bool isCaseSensitive() const { return vfs->isCaseSensitive; } bool isCaseSensitive() const { return vfs->isCaseSensitive; }
// These do nothing. You have to load / unload the archive manually. // These do nothing. You have to load / unload the archive in the
// constructor/destructor.
void load() {} void load() {}
void unload() {} void unload() {}
@ -34,7 +35,7 @@ class MangleArchive : public Ogre::Archive
{ return vfs->isFile(filename); } { return vfs->isFile(filename); }
time_t getModifiedTime(const Ogre::String& filename) time_t getModifiedTime(const Ogre::String& filename)
{ return vfs->stat(filename).time; } { return vfs->stat(filename)->time; }
Ogre::DataStreamPtr open(const Ogre::String& filename) const; Ogre::DataStreamPtr open(const Ogre::String& filename) const;

View File

@ -2,6 +2,7 @@
#include "../../stream/servers/ogre_datastream.h" #include "../../stream/servers/ogre_datastream.h"
using namespace Mangle::VFS; using namespace Mangle::VFS;
using namespace Mangle::Stream;
OgreVFS::OgreVFS(const std::string &_group) OgreVFS::OgreVFS(const std::string &_group)
: group(_group) : group(_group)
@ -18,10 +19,10 @@ OgreVFS::OgreVFS(const std::string &_group)
group = gm->getWorldResourceGroupName(); group = gm->getWorldResourceGroupName();
} }
Mangle::Stream::StreamPtr OgreVFS::open(const std::string &name) StreamPtr OgreVFS::open(const std::string &name)
{ {
Ogre::DataStreamPtr data = gm->openResource(name, group); Ogre::DataStreamPtr data = gm->openResource(name, group);
return Strea::StreamPtr(new Stream::OgreStream(data)); return StreamPtr(new OgreStream(data));
} }
static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs) static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs)
@ -39,7 +40,7 @@ static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs)
} }
} }
FileInfoList OgreVFS::list(const std::string& dir, FileInfoListPtr OgreVFS::list(const std::string& dir,
bool recurse, bool recurse,
bool dirs) const bool dirs) const
{ {
@ -49,7 +50,7 @@ FileInfoList OgreVFS::list(const std::string& dir,
return res; return res;
} }
FileInfoList OgreVFS::find(const std::string& pattern, FileInfoListPtr OgreVFS::find(const std::string& pattern,
bool recursive, bool recursive,
bool dirs) const bool dirs) const
{ {

View File

@ -27,7 +27,7 @@ class PhysVFS : public VFS
/// Open a new data stream. Deleting the object should be enough to /// Open a new data stream. Deleting the object should be enough to
/// close it. /// close it.
virtual Stream::StreamPtr open(const std::string &name) virtual Stream::StreamPtr open(const std::string &name)
{ return new Stream::StreamPtr(Stream::PhysFile(PHYSFS_openRead(name.c_str()))); } { return Stream::StreamPtr(new Stream::PhysFile(PHYSFS_openRead(name.c_str()))); }
/// Check for the existence of a file /// Check for the existence of a file
virtual bool isFile(const std::string &name) const virtual bool isFile(const std::string &name) const

View File

@ -6,7 +6,7 @@ I_OGRE=$(shell pkg-config --cflags OGRE)
L_OGRE=$(shell pkg-config --libs OGRE) L_OGRE=$(shell pkg-config --libs OGRE)
L_PHYSFS=-lphysfs L_PHYSFS=-lphysfs
ogre_client_test: ogre_client_test.cpp dummy_vfs.cpp ../vfs.h ../clients/wrapper.h ../clients/ogre_archive.h ../clients/ogre_archive.cpp ogre_client_test: ogre_client_test.cpp dummy_vfs.cpp ../vfs.h ../clients/ogre_archive.h ../clients/ogre_archive.cpp
$(GCC) $< ../clients/ogre_archive.cpp -o $@ $(I_OGRE) $(L_OGRE) $(GCC) $< ../clients/ogre_archive.cpp -o $@ $(I_OGRE) $(L_OGRE)
ogre_resource_test: ogre_resource_test.cpp ogre_resource_test: ogre_resource_test.cpp

View File

@ -5,7 +5,7 @@
using namespace std; using namespace std;
void print(FileInfo inf) void print(FileInfo &inf)
{ {
cout << "name: " << inf.name << endl; cout << "name: " << inf.name << endl;
cout << "basename: " << inf.basename << endl; cout << "basename: " << inf.basename << endl;
@ -13,12 +13,14 @@ void print(FileInfo inf)
cout << "size: " << inf.size << endl; cout << "size: " << inf.size << endl;
cout << "time: " << inf.time << endl; cout << "time: " << inf.time << endl;
} }
void print(FileInfoPtr inf) { print(*inf); }
void print(FileInfoList lst) void print(FileInfoList &lst)
{ {
for(int i=0; i<lst.size(); i++) for(int i=0; i<lst.size(); i++)
print(lst[i]); print(lst[i]);
} }
void print(FileInfoListPtr lst) { print(*lst); }
int main() int main()
{ {
@ -33,7 +35,7 @@ int main()
cout << endl; cout << endl;
print(vfs.stat("dir")); print(vfs.stat("dir"));
Stream *inp = vfs.open("file1"); StreamPtr inp = vfs.open("file1");
cout << "filesize: " << inp->size() << endl; cout << "filesize: " << inp->size() << endl;
return 0; return 0;

View File

@ -3,9 +3,10 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "../../stream/tests/dummy_input.cpp" #include "../../stream/servers/memory_stream.h"
using namespace Mangle::VFS; using namespace Mangle::VFS;
using namespace Mangle::Stream;
class DummyVFS : public VFS class DummyVFS : public VFS
{ {
@ -13,14 +14,15 @@ public:
DummyVFS() DummyVFS()
{ {
hasFind = false; hasFind = false;
hasList = true;
isCaseSensitive = true; isCaseSensitive = true;
} }
// We only support opening 'file1' at the moment. // We only support opening 'file1' at the moment.
Mangle::Stream::Stream *open(const std::string &name) StreamPtr open(const std::string &name)
{ {
assert(name == "file1"); assert(name == "file1");
return new DummyInput(); return StreamPtr(new MemoryStream("hello world", 11));
} }
bool isFile(const std::string &name) const bool isFile(const std::string &name) const
@ -35,31 +37,31 @@ public:
} }
/// Get info about a single file /// Get info about a single file
FileInfo stat(const std::string &name) const FileInfoPtr stat(const std::string &name) const
{ {
FileInfo fi; FileInfoPtr fi(new FileInfo);
fi.name = name; fi->name = name;
fi.time = 0; fi->time = 0;
if(isFile(name)) if(isFile(name))
{ {
if(name == "dir/file2") if(name == "dir/file2")
{ {
fi.basename = "file2"; fi->basename = "file2";
fi.size = 2; fi->size = 2;
} }
else else
{ {
fi.basename = "file1"; fi->basename = "file1";
fi.size = 1; fi->size = 1;
} }
fi.isDir = false; fi->isDir = false;
} }
else if(isDir(name)) else if(isDir(name))
{ {
fi.basename = "dir"; fi->basename = "dir";
fi.isDir = true; fi->isDir = true;
fi.size = 0; fi->size = 0;
} }
else assert(0); else assert(0);
@ -69,13 +71,13 @@ public:
/// List all entries in a given directory. A blank dir should be /// List all entries in a given directory. A blank dir should be
/// interpreted as a the root/current directory of the archive. If /// interpreted as a the root/current directory of the archive. If
/// dirs is true, list directories instead of files. /// dirs is true, list directories instead of files.
virtual FileInfoList list(const std::string& dir = "", virtual FileInfoListPtr list(const std::string& dir = "",
bool recurse=true, bool recurse=true,
bool dirs=false) const bool dirs=false) const
{ {
assert(dir == ""); assert(dir == "");
FileInfoList fl; FileInfoListPtr fl(new FileInfoList);
FileInfo fi; FileInfo fi;
@ -86,14 +88,14 @@ public:
fi.isDir = false; fi.isDir = false;
fi.size = 1; fi.size = 1;
fi.time = 0; fi.time = 0;
fl.push_back(fi); fl->push_back(fi);
if(recurse) if(recurse)
{ {
fi.name = "dir/file2"; fi.name = "dir/file2";
fi.basename = "file2"; fi.basename = "file2";
fi.size = 2; fi.size = 2;
fl.push_back(fi); fl->push_back(fi);
} }
} }
else else
@ -103,13 +105,13 @@ public:
fi.isDir = true; fi.isDir = true;
fi.size = 0; fi.size = 0;
fi.time = 0; fi.time = 0;
fl.push_back(fi); fl->push_back(fi);
} }
return fl; return fl;
} }
FileInfoList find(const std::string& pattern, FileInfoListPtr find(const std::string& pattern,
bool recursive=true, bool recursive=true,
bool dirs=false) const bool dirs=false) const
{ assert(0); return FileInfoList(); } { assert(0); }
}; };

View File

@ -17,7 +17,7 @@ void print(StringVectorPtr lst)
int main() int main()
{ {
VFS *vfs = new DummyVFS(); VFSPtr vfs(new DummyVFS());
MangleArchive arc(vfs, "dummy"); MangleArchive arc(vfs, "dummy");
cout << "Case: " << arc.isCaseSensitive() << endl; cout << "Case: " << arc.isCaseSensitive() << endl;

View File

@ -6,7 +6,7 @@
This isn't really a test of our implementation, but a test of using This isn't really a test of our implementation, but a test of using
the Ogre resource system to find files. If the Ogre interface the Ogre resource system to find files. If the Ogre interface
changes and you have to change this test, you will have to change changes and you have to change this test, you will have to change
the ogre_vfs.cpp implementation equivalently. the servers/ogre_vfs.cpp implementation equivalently.
*/ */

View File

@ -14,7 +14,7 @@ void find(VFS &vfs, const std::string &file)
return; return;
} }
Stream *data = vfs.open(file); StreamPtr data = vfs.open(file);
cout << "Size: " << data->size() << endl; cout << "Size: " << data->size() << endl;