| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef MOCKDIRECTORYWALKER_H |
| 5 |
#define MOCKDIRECTORYWALKER_H |
| 6 |
|
| 7 |
#include <utils/Vector.h> |
| 8 |
#include <utils/String8.h> |
| 9 |
#include <utility> |
| 10 |
#include "DirectoryWalker.h" |
| 11 |
|
| 12 |
using namespace android; |
| 13 |
using std::pair; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
class StringDirectoryWalker : public DirectoryWalker { |
| 23 |
public: |
| 24 |
StringDirectoryWalker(String8& path, Vector< pair<String8,time_t> >& data) |
| 25 |
: mPos(0), mBasePath(path), mData(data) { |
| 26 |
|
| 27 |
|
| 28 |
}; |
| 29 |
|
| 30 |
|
| 31 |
virtual bool openDir(String8 path) { |
| 32 |
|
| 33 |
|
| 34 |
return path == mBasePath; |
| 35 |
}; |
| 36 |
virtual bool openDir(const char* path) { |
| 37 |
String8 p(path); |
| 38 |
openDir(p); |
| 39 |
return true; |
| 40 |
}; |
| 41 |
|
| 42 |
virtual struct dirent* nextEntry() { |
| 43 |
|
| 44 |
if (mPos >= mData.size()) |
| 45 |
return NULL; |
| 46 |
|
| 47 |
|
| 48 |
mEntry.d_type = DT_REG; |
| 49 |
mEntry.d_ino = mPos; |
| 50 |
|
| 51 |
size_t i = 0; |
| 52 |
for (i; i < mData[mPos].first.size(); ++i) |
| 53 |
mEntry.d_name[i] = mData[mPos].first[i]; |
| 54 |
mEntry.d_name[i] = '\0'; |
| 55 |
|
| 56 |
|
| 57 |
mStats.st_ino = mPos; |
| 58 |
mStats.st_mtime = mData[mPos].second; |
| 59 |
|
| 60 |
|
| 61 |
mPos++; |
| 62 |
|
| 63 |
return &mEntry; |
| 64 |
}; |
| 65 |
|
| 66 |
virtual struct stat* entryStats() { |
| 67 |
return &mStats; |
| 68 |
}; |
| 69 |
|
| 70 |
virtual void closeDir() { |
| 71 |
|
| 72 |
}; |
| 73 |
virtual DirectoryWalker* clone() { |
| 74 |
return new StringDirectoryWalker(*this); |
| 75 |
}; |
| 76 |
private: |
| 77 |
|
| 78 |
size_t mPos; |
| 79 |
|
| 80 |
String8 mBasePath; |
| 81 |
|
| 82 |
Vector< pair<String8,time_t> > mData; |
| 83 |
}; |
| 84 |
|
| 85 |
#endif |