18a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin//
28a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin// Copyright 2011 The Android Open Source Project
38a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin//
48a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
58a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#ifndef MOCKFILEFINDER_H
68a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#define MOCKFILEFINDER_H
78a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
88a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#include <utils/Vector.h>
98a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#include <utils/KeyedVector.h>
108a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#include <utils/String8.h>
118a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
128a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#include "DirectoryWalker.h"
138a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
148a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskinusing namespace android;
158a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
168a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskinclass MockFileFinder : public FileFinder {
178a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskinpublic:
188a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    MockFileFinder (KeyedVector<String8, KeyedVector<String8,time_t> >& files)
198a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        : mFiles(files)
208a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    {
218a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        // Nothing left to do
228a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    };
238a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
248a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    /**
258a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     * findFiles implementation for the abstraction.
268a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     * PRECONDITIONS:
278a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     *  No checking is done, so there MUST be an entry in mFiles with
288a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     *  path matching basePath.
298a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     *
308a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     * POSTCONDITIONS:
318a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     *  fileStore is filled with a copy of the data in mFiles corresponding
328a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     *  to the basePath.
338a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin     */
348a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
358a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    virtual bool findFiles(String8 basePath, Vector<String8>& extensions,
368a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin                           KeyedVector<String8,time_t>& fileStore,
378a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin                           DirectoryWalker* dw)
388a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    {
398a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        const KeyedVector<String8,time_t>* payload(&mFiles.valueFor(basePath));
408a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        // Since KeyedVector doesn't implement swap
418a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        // (who doesn't use swap??) we loop and add one at a time.
428a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        for (size_t i = 0; i < payload->size(); ++i) {
438a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin            fileStore.add(payload->keyAt(i),payload->valueAt(i));
448a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        }
458a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin        return true;
468a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    }
478a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
488a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskinprivate:
498a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    // Virtual mapping between "directories" and the "files" contained
508a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    // in them
518a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin    KeyedVector<String8, KeyedVector<String8,time_t> > mFiles;
528a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin};
538a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
548a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin
558a39da80b33691b0c82458c3b7727e13ff71277eJosiah Gaskin#endif // MOCKFILEFINDER_H