Fixed and tested all VFS tests

pull/21/head
Nicolay Korslund 15 years ago
parent c5316804b5
commit 9e332c4067

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

@ -26,7 +26,8 @@ class MangleArchive : public Ogre::Archive
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 unload() {}
@ -34,7 +35,7 @@ class MangleArchive : public Ogre::Archive
{ return vfs->isFile(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;

@ -2,6 +2,7 @@
#include "../../stream/servers/ogre_datastream.h"
using namespace Mangle::VFS;
using namespace Mangle::Stream;
OgreVFS::OgreVFS(const std::string &_group)
: group(_group)
@ -18,10 +19,10 @@ OgreVFS::OgreVFS(const std::string &_group)
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);
return Strea::StreamPtr(new Stream::OgreStream(data));
return StreamPtr(new OgreStream(data));
}
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 dirs) const
{
@ -49,7 +50,7 @@ FileInfoList OgreVFS::list(const std::string& dir,
return res;
}
FileInfoList OgreVFS::find(const std::string& pattern,
FileInfoListPtr OgreVFS::find(const std::string& pattern,
bool recursive,
bool dirs) const
{

@ -27,7 +27,7 @@ class PhysVFS : public VFS
/// Open a new data stream. Deleting the object should be enough to
/// close it.
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
virtual bool isFile(const std::string &name) const

@ -6,7 +6,7 @@ I_OGRE=$(shell pkg-config --cflags OGRE)
L_OGRE=$(shell pkg-config --libs OGRE)
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)
ogre_resource_test: ogre_resource_test.cpp

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

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

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

@ -6,7 +6,7 @@
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
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.
*/

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

Loading…
Cancel
Save