| /* |
| * Copyright 2014, The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #ifndef ANDROID_CAZE_TEST_UTILITIES_H |
| #define ANDROID_CAZE_TEST_UTILITIES_H |
| |
| #include "BaseType.h" |
| #include "Interpreter.h" |
| #include "ResourceProvider.h" |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| namespace android { |
| namespace caze { |
| |
| class GazerConnection; |
| class MockConnection; |
| |
| namespace test { |
| |
| // Matcher for matching the data pointed by a void pointer (arg) against the reference data provided |
| // in the data variable. Data should be an iterable collection of uint8_t types and arg should be a |
| // void pointer. |
| MATCHER_P(VoidPointee, data, "") { |
| uint32_t i = 0; |
| bool result = true; |
| const uint8_t* typedArg = static_cast<const uint8_t*>(arg); |
| for (uint8_t it : data) { |
| if (it != typedArg[i]) { |
| result = false; |
| } |
| ++i; |
| } |
| return result; |
| } |
| |
| // Action for setting the values pointed by a void pointer (arg0). Data should be an iterable |
| // collection of uint8_t types and arg should be a void pointer. |
| ACTION_P(SetVoidPointee, data) { |
| uint32_t i = 0; |
| uint8_t* typedArg = static_cast<uint8_t*>(arg0); |
| for (uint8_t it : data) { |
| typedArg[i] = it; |
| ++i; |
| } |
| } |
| |
| // Create an instruction code from the given details that can be interpreted by the interpreter |
| uint32_t instruction(Interpreter::InstructionCode code); |
| uint32_t instruction(Interpreter::InstructionCode code, uint32_t data); |
| uint32_t instruction(Interpreter::InstructionCode code, BaseType type, uint32_t data); |
| |
| template <typename T> |
| std::vector<uint8_t> toByteVector(const T& x); |
| |
| std::vector<uint8_t> createReplayData(uint32_t stackSize, uint32_t volatileMemorySize, |
| const std::vector<uint8_t>& constantMemory, |
| const ResourceProvider::ResourceList& resources, |
| const std::vector<uint32_t>& instructions); |
| |
| std::unique_ptr<GazerConnection> createGazerConnection(MockConnection* connection, |
| const std::string& replayId, |
| uint32_t replayLength); |
| |
| std::unique_ptr<GazerConnection> createGazerConnection(const std::string& replayId, |
| uint32_t replayLength); |
| |
| } // end of namespace test |
| } // end of namespace caze |
| } // end of namespace android |
| |
| #endif // ANDROID_CAZE_MOCK_UTILITIES_H |