Ninja
Classes | Public Types | Public Member Functions | Public Attributes
VirtualFileSystem Struct Reference

An implementation of DiskInterface that uses an in-memory representation of disk state. More...

#include <test.h>

Inheritance diagram for VirtualFileSystem:
Inheritance graph
[legend]

List of all members.

Classes

struct  Entry
 An entry for a single in-memory file. More...

Public Types

typedef map< string, EntryFileMap

Public Member Functions

void Create (const string &path, const string &contents)
 "Create" a file with contents.
virtual bool MakeDir (const string &path)
 Create a directory, returning false on failure.
bool MakeDirs (const string &path)
 Create all the parent directories for path; like mkdir -p `basename path`.
virtual string ReadFile (const string &path, string *err)
 Read a file to a string. Fill in |err| on error.
virtual int RemoveFile (const string &path)
 Remove the file named path.
virtual TimeStamp Stat (const string &path)
 stat() a file, returning the mtime, or 0 if missing and -1 on other errors.
int Tick ()
 Tick "time" forwards; subsequent file operations will be newer than previous ones.
 VirtualFileSystem ()
virtual bool WriteFile (const string &path, const string &contents)
 Create a file, with the specified name and contents Returns true on success, false on failure.

Public Attributes

vector< string > directories_made_
FileMap files_
set< string > files_created_
vector< string > files_read_
set< string > files_removed_
int now_
 A simple fake timestamp for file operations.

Detailed Description

An implementation of DiskInterface that uses an in-memory representation of disk state.

It also logs file accesses and directory creations so it can be used by tests to verify disk access patterns.

Definition at line 49 of file test.h.


Member Typedef Documentation

typedef map<string, Entry> VirtualFileSystem::FileMap

Definition at line 76 of file test.h.


Constructor & Destructor Documentation

Definition at line 50 of file test.h.


Member Function Documentation

void VirtualFileSystem::Create ( const string &  path,
const string &  contents 
)

"Create" a file with contents.

Definition at line 101 of file test.cc.

References files_, files_created_, and now_.

Referenced by BuildTest::SetUp(), FakeCommandRunner::StartCommand(), and WriteFile().

bool VirtualFileSystem::MakeDir ( const string &  path) [virtual]

Create a directory, returning false on failure.

Implements DiskInterface.

Definition at line 120 of file test.cc.

References directories_made_.

bool DiskInterface::MakeDirs ( const string &  path) [inherited]

Create all the parent directories for path; like mkdir -p `basename path`.

Definition at line 59 of file disk_interface.cc.

References DiskInterface::MakeDir(), and DiskInterface::Stat().

Referenced by Builder::StartEdge().

string VirtualFileSystem::ReadFile ( const string &  path,
string *  err 
) [virtual]

Read a file to a string. Fill in |err| on error.

Implements DiskInterface.

Definition at line 125 of file test.cc.

References files_, and files_read_.

int VirtualFileSystem::RemoveFile ( const string &  path) [virtual]

Remove the file named path.

It behaves like 'rm -f path' so no errors are reported if it does not exists.

Returns:
0 if the file has been removed, 1 if the file does not exist, and -1 if an error occurs.

Implements DiskInterface.

Definition at line 133 of file test.cc.

References directories_made_, files_, and files_removed_.

TimeStamp VirtualFileSystem::Stat ( const string &  path) [virtual]

stat() a file, returning the mtime, or 0 if missing and -1 on other errors.

Implements DiskInterface.

Definition at line 108 of file test.cc.

References files_.

int VirtualFileSystem::Tick ( ) [inline]

Tick "time" forwards; subsequent file operations will be newer than previous ones.

Definition at line 57 of file test.h.

References now_.

bool VirtualFileSystem::WriteFile ( const string &  path,
const string &  contents 
) [virtual]

Create a file, with the specified name and contents Returns true on success, false on failure.

Implements DiskInterface.

Definition at line 115 of file test.cc.

References Create().


Member Data Documentation

Definition at line 74 of file test.h.

Referenced by MakeDir(), and RemoveFile().

Definition at line 77 of file test.h.

Referenced by Create(), ReadFile(), RemoveFile(), and Stat().

Definition at line 79 of file test.h.

Referenced by Create().

Definition at line 75 of file test.h.

Referenced by ReadFile().

Definition at line 78 of file test.h.

Referenced by RemoveFile().

A simple fake timestamp for file operations.

Definition at line 82 of file test.h.

Referenced by Create(), and Tick().


The documentation for this struct was generated from the following files: