| 1 |
/* |
| 2 |
* Copyright (C) 2017 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 TNT_MOCKCONFIG_H |
| 18 |
#define TNT_MOCKCONFIG_H |
| 19 |
|
| 20 |
|
| 21 |
#include <matc/Config.h> |
| 22 |
|
| 23 |
class NullOutput : public matc::Config::Output { |
| 24 |
|
| 25 |
public: |
| 26 |
NullOutput() : mNullStream(&mNull){ |
| 27 |
|
| 28 |
} |
| 29 |
bool open() noexcept override; |
| 30 |
bool write(const uint8_t* data, size_t size) noexcept override; |
| 31 |
std::ostream& getOutputStream() noexcept override; |
| 32 |
bool close() noexcept override; |
| 33 |
|
| 34 |
private: |
| 35 |
class NullBuffer : public std::streambuf |
| 36 |
{ |
| 37 |
public: |
| 38 |
int overflow(int c) { return c; } |
| 39 |
}; |
| 40 |
NullBuffer mNull; |
| 41 |
std::ostream mNullStream; |
| 42 |
}; |
| 43 |
|
| 44 |
class MockInput : public matc::Config::Input { |
| 45 |
public: |
| 46 |
MockInput(uint8_t* data, size_t size); |
| 47 |
~MockInput(); |
| 48 |
ssize_t open() noexcept override; |
| 49 |
std::unique_ptr<const char[]> read() noexcept override; |
| 50 |
bool close() noexcept override; |
| 51 |
const char* getName() const noexcept override { return "mock"; }; |
| 52 |
private: |
| 53 |
uint8_t* mData; |
| 54 |
size_t mSize; |
| 55 |
}; |
| 56 |
|
| 57 |
class MockConfig : public matc::Config { |
| 58 |
public: |
| 59 |
Output* getOutput() const noexcept override; |
| 60 |
Input* getInput() const noexcept override; |
| 61 |
std::string toString() const noexcept override; |
| 62 |
private: |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
#endif //TNT_MOCKCONFIG_H |