fake_io_delegate.h revision ea6e382143e4a8df894d47db3a6cb79a38ad4530
1/* 2 * Copyright (C) 2015, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef AIDL_TESTS_FAKE_IO_DELEGATE_H_ 18#define AIDL_TESTS_FAKE_IO_DELEGATE_H_ 19 20#include <base/macros.h> 21 22#include <map> 23#include <memory> 24#include <string> 25#include <vector> 26 27#include "io_delegate.h" 28 29namespace android { 30namespace aidl { 31namespace test { 32 33class FakeIoDelegate : public IoDelegate { 34 public: 35 FakeIoDelegate() = default; 36 virtual ~FakeIoDelegate() = default; 37 38 // Returns a unique_ptr to the contents of |filename|. 39 std::unique_ptr<std::string> GetFileContents( 40 const std::string& filename, 41 const std::string& append_content_suffix = "") const override; 42 43 bool FileIsReadable(const std::string& path) const override; 44 45 void SetFileContents(const std::string& filename, 46 const std::string& contents); 47 void AddStubParcelable(const std::string& canonical_name); 48 void AddStubInterface(const std::string& canonical_name); 49 void AddCompoundParcelable(const std::string& canonical_name, 50 const std::vector<std::string>& subclasses); 51 52 private: 53 void AddStub(const std::string& canonical_name, const char* format_str); 54 // Remove leading "./" from |path|. 55 std::string CleanPath(const std::string& path) const; 56 57 std::map<std::string, std::string> file_contents_; 58 59 DISALLOW_COPY_AND_ASSIGN(FakeIoDelegate); 60}; // class FakeIoDelegate 61 62} // namespace test 63} // namespace android 64} // namespace aidl 65 66#endif // AIDL_TESTS_FAKE_IO_DELEGATE_H_ 67